The special floating-point number NaN is defined to be different from all other floating-point numbers, including itself, when compared using the equality operators, == and !=.

To check whether a variable x is NaN use the method isNaN that is defined on both java.lang.Float and java.lang.Double.

The expression x == Double.NaN is always false. This expression should be replaced by Double.isNaN(x), which accurately identifies whether x is equal to Double.NaN.

  • Java Language Specification: Numerical Equality Operators == and !=.