The correct answer is simple: " standard (and docs ). But I'm not going to be cynical, because it is obvious that not what you need.
In addition to the other answers here, I will try to connect infinities with saturating arithmetic.
Other answers have already stated that the reason comparisons on NaN are true , so I'm not going to beat a dead horse.
Say I have a saturating integer representing shades of gray. Why am I using saturating arithmetic? Because something brighter than white is still white, and darker than black, still black (except orange ). This means BLACK - x == BLACK and WHITE + x == WHITE . Has the meaning?
Now suppose we want to represent grayscale colors with a (signed) 1s complement of an 8-bit integer, where BLACK == -127 and WHITE == 127 . Why 1s complement? Because it gives us a signed zero , like IEEE 754 floating point , And since we use saturating arithmetic, -127 - x == -127 and 127 + x == 127 .
How is this related to floating point infinities? Replace the floating-point integer, BLACK with NEGATIVE_INFINITY and WHITE with POSITIVE_INFINITY and what do you get? NEGATIVE_INFINITY - x == NEGATIVE_INFINITY and POSITIVE_INFINITY + x == POSITIVE_INFINITY .
Since you used POSITIVE_INFINITY , I also use it. First we need a class to represent our saturating integer color; call it SaturatedColor and suppose it works like any other integer in Java. Now let's take your code and replace double with our own SaturatedColor and Double.POSITIVE_INFINITY with SaturatedColor.WHITE :
SaturatedColor a = SaturatedColor.WHITE; SaturatedColor b = SaturatedColor.WHITE;
As we set above, SaturatedColor.WHITE (only WHITE above) is 127 , so let's do it here:
SaturatedColor a = 127; SaturatedColor b = 127;
Now we use the System.out.println statements that you used, and replace a and b with your value (values?):
System.out.println(127 == 127); System.out.println(127 < 127); System.out.println(127 > 127);
It should be obvious that this will print.