udhaya, this is what i'm guessing. you are doing a == on literals, but invoking the overriden method equals on the other. so, its likely that Float's overriden equals method is implemented to be not equal for 0.0 and -0.0
Joined: Nov 27, 2001
the Float equals method use the native method floatToIntBits to do its comparison. I take it the result of comparison between Float(-0.0) and Float(0.0) might be different according to the platform implementation of this method.
Positive zero and negative zero are considered equal. Therefore, -0.0==0.0 is true, for example.
However, as Mikael Bellec cleverly noted, Float.equals() uses Float.floatToIntBits() to do its comparison. In the Java doc for Float, it mentions the inconsistency:
...two float values are considered to be the same if and only if the method floatToIntBits(float) returns the identical int value when applied to each.
Note that in most cases, for two instances of class Float, f1 and f2, the value of f1.equals(f2) is true if and only if
f1.floatValue() == f2.floatValue()
also has the value true. However, there are two exceptions:
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. This definition allows hash tables to operate properly. --Float.equals() Java doc
At the low level, floatToIntBits() returns a bit sequence starting with 0 for a positive zero value, and floatToIntBits() returns a bit sequence starting with 1 for a negative zero value. The two bit sequences are unequal so the equals() test returns false. The reason the authors chose to do it this way is to ensure that for any pair of Float objects where equals() returns true, the hashCode() return values will be equal. The hashCode() method returns
the integer bit representation, exactly as produced by the method floatToIntBits(float), of the primitive float value represented by this Float object. --Float.hashCode() Java doc