Given the code:
Float f1 = new Float(Float.NaN);
Float f2 = new Float(Float.NaN);
System.out.println( ""+ (f1 == f2)+" "+f1.equals(f2)+ " "+(Float.NaN == Float.NaN) );
Ans : false,true,false
Although f1.equals(f2) should return false, it returns true. Javadoc gives two exceptional cases:
. If f1 and f2 both represent Float.NaN, then the equals method returns true, even though Float.NaN==Float.NaN has the value false.
. If f1 represents +0.0f while f2 represents -0.0f, or vice versa, the equal
test has the value false, even though 0.0f==-0.0f has the value true.
Doubt: IS it true for Double.NaN values also???