What is meant by: Support for NaNs?
I suggest that we add to C9X draft standard in 7.7
Mathematics <math.h> after the paragraph that defines the
An implementation supports quiet NaNs if its NaNs have the
same behaviour as IEC-559 quiet NaNs for all floating types.
Add to the Rationale in section 7.7:
NaNs have the following propertities:
Every floating-point arithmetic operation that delivers a
floating-point result that has one or more NaN operands,
shall deliver a quiet NaN result, which should be one of
the input NaNs, and signal no exception. Note, format
conversions between floating-point types might be unable
to deliver the same NaN.
The comparison operators ( <, <=, >, and >= ) involving
one or two input NaNs, shall signal the invalid exception
and deliver 0 as the result.
The equality operators ( == and != ) involving one or two
input NaNs shall raise no exceptions; the result of ==
shall be 0 and of != shall be 1.
The comparison macros ( isgreater, isgreaterequal, isless,
islessequal, islessgreater, and isunordered ), new with
C9X, are meant for programs that care about NaNs. They
are similar to the existing comparison operators, but do
not raise invalid for NaN operands.
Every conversion from floating-point to integer that has a
NaN operand shall raise invalid and the resulting value is
Conversion of NaNs to decimal strings is specified by
printf(). Conversion of NaN decimal strings to floating
is specified by strtod().
For functions that deliver floating results from floating
arguments, unless specified otherwise:
One-parameter functions of a NaN argument return that same
NaN and raise no exception.
Two or more parameter functions with one NaN argument
return that same NaN and raise no exception.
Two or more parameter functions with two or more NaN
arguments return a NaN results (which should be one of the
arguments) and raise no exception.
---------- end of suggested changes.
The terms NaN and supported are used several places in the
C9X draft. Some of them are:
188.8.131.52.2 Characteristics of floating types <float.h> has:
A NaN is an encoding signifying Not-a-Number. A quiet
NaN propagates through almost every arithmetic operation
without raising an exception; a signaling NaN generally
raises an exception when ocurring as an arithmetic
Footnote 17: IEC 559 specifies quiet and signaling NaNs.
For implementations that do not support IEC 559, the terms
quiet NaN and signaling NaN are intended to apply to
encodings with similar behavior.
184.108.40.206 Real floating types has:
"When a float is promoted to double or long double,
or a double is promoted to long double, its value
7.7 Mathematics <math.h> has:
The macro NAN is defined if and only if the implementation
supports quiet NaNs for the float type.
Footnote 176. For the isnan macro, the type for
determination doesn't matter unless the implementation
supports NaNs in the evaluation type but not in the
220.127.116.11 The nan function currently has:
If the implementation does not support quiet NaNs for the
double type, a call to the nan function is unspecified.
Footnote 182. NaN arguments are treated as missing data:
if one argument is a NaN and the other numeric, then fmax
chooses the numeric value. See F.9.9.2.
Footnote 183. fmin is analogous to fmax in its treatment
7.7.14 Comparison macros
The relational and equality operators support the usual
mathematical relationships between numeric values. For
any ordered pair of numeric values exactly one of the
relationships - less, greater, and equal - is true.
Relational operators may raise the invalid exception when
argument values are NaNs. For a NaN and a numeric value,
or for two NaNs, just the unordered relationship is
true.184 The following subclauses provide macros that are
quiet (non exception raising) versions of the relational
operators, and other comparison macros that facilitate
writing efficient code that accounts for NaNs without
suffering the invalid exception. In the synopses in this
subclause, real-floating indicates that the argument must
be an expression of real floating type.
Footnote 184. IEC 559 requires that the built-in
relational operators raise the invalid exception if the
operands compare unordered, as an error indicator for
programs written without consideration of NaNs; the result
in these cases is false.
F.2.1 Infinities, signed zeros, and NaNs
This specification does not define the behavior of
signaling NaNs.274 It generally uses the term NaN to
denote quiet NaNs. The NAN and INFINITY macros and the
nan function in <math.h> provide designations for IEC 559
NaNs and infinities.