According to the JLS, §4.2.3, "Floating-Point Types, Formats, and Values" [JLS 2005]:
NaN
(not-a-number) is unordered, so the numerical comparison operators<
,<=
,>
, and>=
returnfalse
if either or both operands areNaN
. The equality operator==
returnsfalse
if either operand isNaN
, and the inequality operator!=
returnstrue
if either operand isNaN
.
...
Automated detection of comparison with NaN is straightforward. Sound determination of whether the possibility of an unordered result has been correctly handled is not feasible in the general case. Heuristic checks could be useful.
Bibliography
FE: Doomed test for equality to NaN | |
[JLS 2005] |
...
NUM06-J. Use the strictfp modifier for floating-point calculation consistency across platforms Rule 03: Numeric Types and Operations (NUM)