Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

-0.0 and +0.0

 
Jello Yao
Greenhorn
Posts: 13
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Does it true or false? Thanks!
Math.min(-0.0,+0.0) == Math.max(0.0,+0.0);
 
Jello Yao
Greenhorn
Posts: 13
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I compiled it. The printout is true. Why Java consider -0.0 equals +0.0?
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Because it actually *is*?
Why would you expect it to be different?
 
John Lee
Ranch Hand
Posts: 2545
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes there are. See the JLS for more info.
 
Dirk Schreckmann
Sheriff
Posts: 7023
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic