programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
• Campbell Ritchie
• Ron McLeod
• Paul Clapham
• Jeanne Boyarsky
• Liutauras Vilda
Sheriffs:
• Tim Cooke
• Bear Bibeault
• paul wheaton
Saloon Keepers:
• Carey Brown
• Stephan van Hulst
• Tim Holloway
• Mikalai Zaikin
• Piet Souris
Bartenders:

# -0.0 and +0.0

Greenhorn
Posts: 13
• Number of slices to send:
Optional 'thank-you' note:
Does it true or false? Thanks!
Math.min(-0.0,+0.0) == Math.max(0.0,+0.0);

Jello Yao
Greenhorn
Posts: 13
• Number of slices to send:
Optional 'thank-you' note:
I compiled it. The printout is true. Why Java consider -0.0 equals +0.0?

author
Posts: 14112
• Number of slices to send:
Optional 'thank-you' note:
Because it actually *is*?
Why would you expect it to be different?

Ranch Hand
Posts: 2545
• Number of slices to send:
Optional 'thank-you' note:
In Java, there are not special notations of -0.0 and +0.0. I think maybe in Fortran, there is such thing, but I am not sure.

Wanderer
Posts: 18671
• Number of slices to send:
Optional 'thank-you' note:

Sheriff
Posts: 7023
• Number of slices to send:
Optional 'thank-you' note:
For the lazy (like me):

The IEEE 754 standard includes... positive and negative zeros...
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.

 Barry's not gonna like this. Barry's not gonna like this one bit. What is Barry's deal with tiny ads? Low Tech Laboratory https://www.kickstarter.com/projects/paulwheaton/low-tech-0