Question 181) what does the following expression return? (0.0 == -0.0)
true false the ans is true . why?
posted 14 years ago
Hi Wei, This is why. Section 4.2.3 of the JVM Spec:
Positive zero and negative zero compare equal; thus the result of the expression 0.0==-0.0 is true and the result of 0.0>-0.0 is false. But other operations can distinguish positive and negative zero; for example, 1.0/0.0 has the value positive infinity, while the value of 1.0/-0.0 is negative infinity.