WORK IN PROGRESS
Floating Point Numbers, Infinities and NaNs
In preparation for resolving STDCXX-51 this page outlines the platform-specific details describing infinities and NaNs produced as the result of certain floating point calculations, usually triggered by invalid operands.
libc symbols
C99 specifies the following interface to infinities and NaNs:
7.12 Mathematics <math.h>
4 The macro INFINITY
expands to a constant expression of type float representing positive or unsigned infinity, if available; else to a positive constant of type float
that overflows at translation time.
5 The macro NAN
is defined if and only if the implementation supports quiet NaNs for the float
type. It expands to a constant expression of type float representing a quiet NaN.
7.12.11.2 The nan functions
1 Synopsis
#include <math.h> double nan(const char *tagp); float nanf(const char *tagp); long double nanl(const char *tagp);
Description
2 The call nan("
n-char-sequence")
is equivalent to strtod("NAN(
n-charsequence)", (char**) NULL)
; the call nan("")
is equivalent to strtod("NAN()", (char**) NULL)
. If tagp
does not point to an n-char sequence or an empty string, the call is equivalent to strtod("NAN", (char**) NULL)
. Calls to nanf
and nanl
are equivalent to the corresponding calls to strtof
and strtold
.
Returns
3 The nan functions return a quiet NaN, if available, with content indicated through tagp
. If the implementation does not support quiet NaNs, the functions return zero.
The table below lists the public symbols defined on each platform for Infinity, quiet NaN, and signaling NaN.
|
|
|
libc symbols |
|
|
|
|
|
AIX |
HP-UX |
IRIX |
Linux |
Solaris |
Tru64 UNIX |
Windows |
header |
|
|
N/A |
|
|
|
|
Infinity |
|
|
N/A |
|
|
|
N/A |
Quiet NaN |
|
|
N/A |
|
|
|
N/A |
Signaling NaN |
|
|
N/A |
N/A |
|
|
N/A |
1 Supports all signatures required by C99 and POSIX: float nanf(const char*)
, double nan(const char*)
, and long double nanl(const char*)
.
2 Recent versions also support the C99 interface.
printf() formatting
|
|
|
|
|
|
|
|
|
|
AIX |
HP-UX |
IRIX |
Linux |
Solaris |
Tru64 UNIX |
Windows/x86 |
Windows/x64 |
Infinity |
|
|
|
|
|
|
|
|
Quiet NaN |
|
|
|
|
|
|
|
|
Signaling NaN |
|
|
|
|
|
|
|
|
numeric_limits<double> values/formatting
|
|
|
|
|
|
|
|
|
|
AIX |
HP-UX |
IRIX |
Linux |
Solaris |
Tru64 UNIX |
Windows/x86 |
Windows/x64 |
|
XLC++ 9.0 |
aCC 3,6 |
MIPSpro |
gcc |
Sun C++ |
HP C++ |
MSVC |
MSVC |
|
|
|
|
|
|
0 |
|
|
|
|
|
|
|
|
0 |
|
|
|
|
|
|
|
|
0 |
|
|
Bit Patterns
The table below shows the bit patterns for Infinity, Quiet NaN, and Signaling NaN on each platform.
|
|
|
IEEE 754 double precision bit patterns |
|
|
|
|
Number |
|
Sign |
Exponent |
Fraction |
|||
AIX/Power |
Infinity |
|
|
|
|||
Quiet NaN |
|
|
|
||||
Signaling NaN |
|
|
|
||||
HP-UX |
Infinity |
|
|
|
|||
Quiet NaN |
|
|
|
||||
Signaling NaN |
|
|
|
||||
IRIX/MIPS |
Infinity |
|
|
|
|||
Quiet NaN |
|
|
|
||||
Signaling NaN |
|
|
|
||||
Linux/x86 |
Infinity |
|
|
|
|||
Quiet NaN1 |
|
|
|
||||
Signaling NaN1 |
|
|
|
||||
Solaris/SPARC |
Infinity |
|
|
|
|||
Quiet NaN |
|
|
|
||||
Signaling NaN |
|
|
|
||||
Solaris/x86 |
Infinity |
|
|
|
|||
Quiet NaN1 |
|
|
|
||||
Signaling NaN1 |
|
|
|
||||
Tru64 UNIX/Alpha |
Infinity |
|
|
|
|||
Quiet NaN |
|
|
|
||||
Signaling NaN |
|
|
|
||||
Windows/x86 |
Infinity |
|
|
|
|||
Quiet NaN |
|
|
|
||||
Signaling NaN |
|
|
|
1 Intel and AMD processors set the first fraction bit to 1 for Quiet NaNs and clear it for Signaling NaNs.