double i = Double.NaN;
The API for Double.equals() spells out the answer: “Double.NaN==Double.NaN has the value false”. This is elaborated in the Java Language Specification under “Floating-Point Types, Formats, and Values”:
NaN
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
. In
particular,x!=x
istrue
if and only
ifx
isNaN
, and(x<y) == !(x>=y)
will
befalse
ifx
ory
isNaN
.