I just got a question that I can\'t answer.
Suppose you have this loop definition in Java:
while (i == i) ;
What is the type of
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":
NaNis unordered, so the numerical comparison operators<,<=,>, and>=returnfalseif either or both operands areNaN. The equality operator==returnsfalseif either operand isNaN, and the inequality operator!=returnstrueif either operand isNaN. In particular,x!=xistrueif and only ifxisNaN, and(xwill be=y) falseifxoryisNaN.