Integer.MAX_VALUE is a number and has a defined value. Double.NaN is (as its name says) not a number and hence doesn't have a defined value. The logic is presumably that comparing something which doesn't have a defined value to anything else shouldn't return true.
It's defined by the IEEE floating point specification. NaN is defined to not equal to NaN.
As a side note, the Double.equals() method reports the NaN equals NaN, which is in direct violation of the specification. This was done because the "no duplicates" rule of the hashmap and hashset collections would be broken otherwise.
It's defined by the IEEE floating point specification. NaN is defined to not equal to NaN.
As a side note, the Double.equals() method reports the NaN equals NaN, which is in direct violation of the specification. This was done because the "no duplicates" rule of the hashmap and hashset collections would be broken otherwise.
Floating-point equality testing is performed in accordance with the rules of the IEEE 754 standard:
If either operand is NaN, then the result of == is false but the result of != is true. Indeed, the test x!=x is true if and only if the value of x is NaN. (The methods Float.isNaN and Double.isNaN may also be used to test whether a value is NaN.)
Positive zero and negative zero are considered equal. Therefore, -0.0==0.0 is true, for example.
Otherwise, two distinct floating-point values are considered unequal by the equality operators. In particular, there is one value representing positive infinity and one value representing negative infinity; each compares equal only to itself, and each compares unequal to all other values.