aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes (0.0==-0.0) true or false Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "(0.0==-0.0) true or false" Watch "(0.0==-0.0) true or false" New topic
Author

(0.0==-0.0) true or false

wei liu
Ranch Hand

Joined: Dec 06, 2001
Posts: 56
Question 181)
what does the following expression return?
(0.0 == -0.0)

true
false
the ans is true . why?
Manfred Leonhardt
Ranch Hand

Joined: Jan 09, 2001
Posts: 1492
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.

Regards,
Manfred.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: (0.0==-0.0) true or false
 
Similar Threads
Math functions
-0.0 and +0.0
extremes of Math.ceil
what s the result
Majji #Q.28