My Blog SCJP 5 SCWCD 5
SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
My Blog SCJP 5 SCWCD 5
Originally posted by Himanshu Gupta:
What I think is that this line public static final double NaN = 0.0d / 0.0; will give only one value; whatever it may be, so it has to be equal. Because there is only one copy of that and that too final.
SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
Originally posted by PUNEET MITTAL:
the thing is when you are doing this
so "Double.NaN" returns some constant value which is actually a long type of value but not a number. But the thing is in a it returns some value which is assigned to it, but in next it again returns the same value but it is considered as from different address or reference. when you are comparing it using "==" it gives false, but while comparing it using equals() it gives true as this method checks the contents, rather than the reference.
My Blog SCJP 5 SCWCD 5
public static final double NaN
A constant holding a Not-a-Number (NaN) value of type double. It is equivalent to the value returned by
Double.longBitsToDouble(0x7ff8000000000000L).
but since its not a number. so how can it return a value similar to the above��. That�s wat confusing me.
Originally posted by PUNEET MITTAL:
ok so you mean to say is that its a binary stream which is in long type and is converted to double type and that double type of bitstream is assigned to NaN, which is returned by Double.NaN.
ok i got it.
thanks henry.
Henry: The longBitsToDouble() method, assigns the bits represented by a long as a double. No coversion is done. The bit pattern of the long is simply used as the bit pattern of the double. And that bit pattern is the one that IEEE assigned to NAN.
My Blog SCJP 5 SCWCD 5
well no NaN values are ==. So NaN == Nan will always be false.
Originally posted by PUNEET MITTAL:
originally posted by ankit:
well ankit, i think you are somewhat misconcepted at this point as NaN is a static final, which means it is a contant term, so the value will always remains same. but the reason for this is different which i think henry has replied for it perfectly.
SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
Spot false dilemmas now, ask me how!
(If you're not on the edge, you're taking up too much room.)
Don't get me started about those stupid light bulbs. |