This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes waht is -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 » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "waht is -0.0? " Watch "waht is -0.0? " New topic

waht is -0.0?

ego hu
Ranch Hand

Joined: Mar 20, 2001
Posts: 53
Mock Exam:
What is displayed when the following is executed:
double d1 = -0.5;
System.out.println("Ceil d1 = " + Math.ceil(d1));
System.out.println("floor d1 = " + Math.floor(d1));
Answer: -0.0, -1.0.
I compiled and run, it is true.
So what is the difference between -0.0 and 0.0?
Bala Arul

Joined: Feb 09, 2001
Posts: 29
In my opinion, 0.0 is equals to -0.0. Sign only indicates how the zero was achieved, whether from positive or negative value.
B Arul
Stevie Kaligis
Ranch Hand

Joined: Feb 04, 2001
Posts: 400
Hi Ego...
0.0 & -0.0 :
1. they both are Floating Point Literals.
2. they considered equal when you use (0.0 == -0.0)
3. but produce different result when used in some calculation.
for example :
(1.0/0.0) produces positive invinity, and
(1.0/-0.0) produces negative invinity.
hope this help
I agree. Here's the link:
subject: waht is -0.0?
Similar Threads
Negative Zero's
if(0.0 == -0.0) - Sample question