The == and != Operators are apparently not limited by the IEEE 754 behavior for NaN s, as indicated by @AlexD's answer.
However, the <math.h> comparison macros must follow the NaN rules equivalent to IEEE 754 . The following draft from C11 draft N1580 in section 7.12.14 Comparison macros state that the <math.h> comparison macros are necessary to ensure that if one or both of x, y are NaN , then:
isunordered(x, y) true
isgreater(x, y) , isgreaterequal(x, y) , isless(x, y) , islessequal(x, y) all false
Relationship and equality operators support the usual mathematical relationships between numerical values. For any ordered pair of numerical values, exactly one of the relationships - less , greater and equal - is true. Relationship operators may raise an "invalid" floating point exception if the value of the argument is NaN s. For NaN and a numerical value, or for two NaN s, only the disordered ratio is true .
The C++ simply discards in C one on the <math.h> question:
Classification / comparison functions behave in the same way as C macros with the corresponding names defined in 7.12.3, classification macros and 7.12.14, comparison macros in the C standard.
source share