Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
programming forums Java Java JSRs Mobile Certification Databases Caching Books Engineering Languages Frameworks Products This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Sheriffs:
Saloon Keepers:
Bartenders:

# Double

Arathi Rajashekar
Ranch Hand
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

Manfred Leonhardt
Ranch Hand
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.

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
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.

Arathi Rajashekar
Ranch Hand
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.

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.