It's not a secret anymore!*
The moose likes Beginning Java and the fly likes -0.0 and +0.0 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "-0.0 and +0.0" Watch "-0.0 and +0.0" New topic
Author

-0.0 and +0.0

Jello Yao
Greenhorn

Joined: Jan 05, 2003
Posts: 13
Does it true or false? Thanks!
Math.min(-0.0,+0.0) == Math.max(0.0,+0.0);
Jello Yao
Greenhorn

Joined: Jan 05, 2003
Posts: 13
I compiled it. The printout is true. Why Java consider -0.0 equals +0.0?
Ilja Preuss
author
Sheriff

Joined: Jul 11, 2001
Posts: 14112
Because it actually *is*?
Why would you expect it to be different?


The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
John Lee
Ranch Hand

Joined: Aug 05, 2001
Posts: 2545
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

Joined: Jan 30, 2000
Posts: 18671
Yes there are. See the JLS for more info.


"I'm not back." - Bill Harding, Twister
Dirk Schreckmann
Sheriff

Joined: Dec 10, 2001
Posts: 7023
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.


[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: -0.0 and +0.0
 
Similar Threads
Math.min and Math. max
Math class
what s the result
[about zero]...
what this code returns true