If your compiler produces a NaN, it has a property that it is not equal to any value, including itself. *

If a is NaN, then a == a is false. If a is NaN, then a will neither be equal to, less than, nor greater than any value including itself.

Another Example: regardless of the value of b, a < b, a <= b, a > b, a >= b, and a == b will all return

Here’s how to check if a value is NaN:

    #include <cmath>

void funct(double x)
if (isnan(x)) { ← though see caveat below
// x is NaN
} else {
// x is a normal value

photo credit: Girl and XO, Mongolia via photopin (license)