Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
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
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "-0.0 and +0.0" Watch "-0.0 and +0.0" New topic

-0.0 and +0.0

Jello Yao

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

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

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

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

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

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]
I agree. Here's the link:
subject: -0.0 and +0.0
jQuery in Action, 3rd edition