standards/130067: Wrong numeric limits in system headers?
Vaclav Haisman
v.haisman at sh.cvut.cz
Tue Dec 30 22:40:02 UTC 2008
>Number: 130067
>Category: standards
>Synopsis: Wrong numeric limits in system headers?
>Confidential: no
>Severity: serious
>Priority: medium
>Responsible: freebsd-standards
>State: open
>Quarter:
>Keywords:
>Date-Required:
>Class: sw-bug
>Submitter-Id: current-users
>Arrival-Date: Tue Dec 30 22:40:01 UTC 2008
>Closed-Date:
>Last-Modified:
>Originator: Vaclav Haisman
>Release: 6.3
>Organization:
SU SH
>Environment:
FreeBSD shell.sh.cvut.cz 6.3-PRERELEASE FreeBSD 6.3-PRERELEASE #0: Fri Jan 18 17:04:16 CET 2008 root at shell.sh.cvut.cz:/usr/obj/usr/src/sys/SHELL-SMP i386
>Description:
There seems to be a problem with definition of long double limits on FreeBSD i386/6.x.
shell::wilx:~/packed_vector> echo | g++ -dD -E - | sort | grep LDBL_MAX
#define __LDBL_MAX_10_EXP__ 4932
#define __LDBL_MAX_EXP__ 16384
#define __LDBL_MAX__ 1.1897314953572316e+4932L
shell::wilx:~/packed_vector> fgrep -rn LDBL_MAX /usr/include
[...]
/usr/include/machine/float.h:75:#define LDBL_MAX_EXP 16384
/usr/include/machine/float.h:76:#define LDBL_MAX 1.1897314953572317650E+4932L
/usr/include/machine/float.h:77:#define LDBL_MAX_10_EXP 4932
/usr/include/float.h:75:#define LDBL_MAX_EXP 16384
/usr/include/float.h:76:#define LDBL_MAX 1.1897314953572317650E+4932L
/usr/include/float.h:77:#define LDBL_MAX_10_EXP 4932
Notice the difference in definition of LDBL_MAX, the values in system
headers are tiny bit larger than that defined by GCC itself.
machine/float.h:76:#define LDBL_MAX 1.1897314953572317650E+4932L
float.h:76:#define LDBL_MAX 1.1897314953572317650E+4932L
GCC: __LDBL_MAX__ 1.1897314953572316e+4932L
A simple test shows the following:
shell::wilx:~/tmp> cat >longdouble.cxx
#include <iostream>
#include <limits>
#include <cfloat>
int
main ()
{
typedef std::numeric_limits<long double> limits;
std::cout << "max: " << limits::max () << "\n";
std::cout << "__LDBL_MAX__: " << __LDBL_MAX__ << "\n";
std::cout << "LDBL_MAX: " << LDBL_MAX << "\n";
}
shell::wilx:~/tmp> g++ -o longdouble longdouble.cxx
shell::wilx:~/tmp> ./longdouble
max: 1.18973e+4932
__LDBL_MAX__: 1.18973e+4932
LDBL_MAX: inf
This is on 6.3/i386. 7.1/AMD64 does not print inf for LDBL_MAX. I
think this is a bug in 6.x headers or in GCC 3.4.x that it
uses. LDBL_MAX should never result in "inf".
>How-To-Repeat:
#include <iostream>
#include <limits>
#include <cfloat>
int
main ()
{
typedef std::numeric_limits<long double> limits;
std::cout << "max: " << limits::max () << "\n";
std::cout << "__LDBL_MAX__: " << __LDBL_MAX__ << "\n";
std::cout << "LDBL_MAX: " << LDBL_MAX << "\n";
}
>Fix:
>Release-Note:
>Audit-Trail:
>Unformatted:
More information about the freebsd-standards
mailing list