Doing some optimziation on a piece of code, the correctness of the code depending on how the compiler handle NaNs.
I read the IEEE-754 rules on NaN, which states:
C/C++ does not require specific floating-point representation and does not require that any comparison against NaN is false.
In C++ you can check if all floating-point types fulfill IEEE 754 using std::numeric_limits::is_iec559:
static constexpr bool is_iec559;56 True if and only if the type adheres to IEC 559 standard.217
57 Meaningful for all floating point types.
217) International Electrotechnical Commission standard 559 is the same as IEEE 754.
For other floating-point representations comparison against NaN
may or may not behave the same way.
In fact, even representing NaN itself is not required. See std::numeric_limits