Originally posted by bill bozeman:
For the first one, try to remember this:
if you compare to NaN values with == it will return false, if you compare them with equals it will return true.
if you compare -0.0 to 0.0 with == it will return true, if you compare them with equals it will return false.
The way I have remembered this, is 0.0 is a number and if you were to type in the numbers with == then it would work and return true. NaN is not a number, so I treat it like an object, so == will return false. Then I just remember that the opposite is true for the other scenerios involving equals() method. Tricky, but one of those things you just have to memorize.
Bill
The reply to question seems to be a good way to remember the answer.But to understand it why it really happens is to just understand what NAN is actually.It is pure mathematics(with a little difference).NAN in
JAVA is introduced to take care of things like 0.0/0.0,infinity*0.0.Now suppose that NAN==NAN
then
1.0/0.0*0.0==2.0/0.0*0.0
i:e POSITIVE_INFINITY*0.0(NAN)==POSITIVE_INFINITY*0.0(NAN)
BUT that means 1.0=2.0
which is ridiculos.
Now where the difference lies
1.0/0.0*0.0==1.0/0.0*0.0
where NAN doesnt work.JAVA takes result as not equal.
There is some logic behind everything and where logic can not be applied it is then yr wish
I hope that helps
sandeep
[This message has been edited by sandeep bagati (edited April 21, 2001).]