The reason 0.0f == -0.0f is because IEEE defines it as so. The reason the float class doesn't adhere to IEEE is because it wants 0.0f and -0.0f to be used as keys in a hashmap/set. (The JavaDoc clearly states this deviation from the IEEE specification)

NaN means "not a number". It is a valid value defined by the IEEE specification. And can be achieve with certain calculations. For example, the square root of a negative number is a NaN. Zero divided by zero results in NaN.

And Float.NaN is simply a static variable of the Float class that holds this value. This is so that you can compare results to see if it is NaN, without having to calculate it yourself.

Henry [ September 07, 2008: Message edited by: Henry Wong ]

Arjun Reddy
Ranch Hand

Joined: Nov 10, 2007
Posts: 629

posted Sep 07, 2008 22:03:00

0

So, -1.2f == 1.2f is only for floats and doubles right and also, say, Float.NaN == Float.NaN is false because we can not compare two values which are undefined or unknown maybe right?