aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Double Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Double" Watch "Double" New topic
Author

Double

Arathi Rajashekar
Ranch Hand

Joined: Nov 20, 2001
Posts: 112
Hi,
I have doubt in the following code

Why it gives as answer as positive infinity.
Won't the -0 be promoted to -0.0. What is the reason


Arathi<br />Sun Certified Java Programmer
Manfred Leonhardt
Ranch Hand

Joined: Jan 09, 2001
Posts: 1492
Hi Arathi,
The answer is because you are using -0 instead of -0.. There is no such value -0 as an integer it is just 0 therefore the compiler performs the following:
-10. / -0
replaced with
-10. / 0
converted to
-10. / 0.
therefore the answer is Positive!

Only IEEE 754 recognizes a difference bewteen positive and negative zero!

If you had used the double negative zero you would get the result you expected without any replacement or conversion by the compiler.
Regards,
Manfred.
Darryl Failla
Ranch Hand

Joined: Oct 16, 2001
Posts: 129
In order for the operation to take place, -0 must be cast to a double. To do that, the int value -0 must first be evaluated. Since there is no such int as -0, the value is evaluated as 0. This is cast to 0.0, and the operation is performed; leaving a result of POSITIVE_INFINITY.


Darryl Failla
Sun Certified Java 2 Programmer
Arathi Rajashekar
Ranch Hand

Joined: Nov 20, 2001
Posts: 112
Originally posted by Manfred Leonhardt:
Hi Arathi,
The answer is because you are using -0 instead of -0.. There is no such value -0 as an integer it is just 0 therefore the compiler performs the following:
-10. / -0
replaced with
-10. / 0
converted to
-10. / 0.
therefore the answer is Positive!

Only IEEE 754 recognizes a difference bewteen positive and negative zero!

If you had used the double negative zero you would get the result you expected without any replacement or conversion by the compiler.
Regards,
Manfred.

Thanks for your answer. I feel that when conversion by the compiler is made then 10.0/-0
is converted to
10.0/0. because -0 is converted as 0.0(with Casting). Am I correct. This what you meant to say. If its right, then i think you have to change the above code.
[ January 11, 2002: Message edited by: Arathi Rajashekar ]
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Double