C++ portable NaN for win32/Unix C++ portable NaN for win32/Unix unix unix

C++ portable NaN for win32/Unix


C++ guarantees that 0.0/0.0 is NaN, so this is the easiest way to express it.

Remember that NaN != NaN, so (0.0/0.0) == (0.0/0.0) is actually false. To test for NaN-ness, if you don't have a library is_nan somewhere, just check for x != x for some candidate double x.


When writing portable C++ code, try using the NaN defined in the standard library <limits>. For example for the type double you might want to use std::numeric_limits<double>::quiet_NaN().