This week's giveaway is in the Spring forum. We're giving away four copies of REST with Spring (video course) and have Eugen Paraschiv on-line! See this thread for details.

I am going through Java 2 Sun Certification Study guide by Sierra/Bates.

On Page 163 (last paragraph) the authors discuss division by zero and state that "Floating-point numbers divided by zero return either positive or negative infinity, depending on whether or not the zero is positive or negative!"

When I tested this in code I get -infinity only when the dividend is negative regardless of whether 0(divisor) is positive or negative

i.e. -6.25/0 or -6.25/-0 is -infinity and 6.25/0 or 6.25/-0 is infinity

so the answer is dependant on the sign of the dividend and not on whether 0 is positive or negative.

Please help, is the book incorrect or am I interpreting this incorrectly.

in 6.25/-0 the -0 is an integer. When it gets pormoted to a float it becomes 0.0 not -0.0. That's why you are getting positive infinity for 6.25/-0 Sanyev

Vanitha Naidu
Greenhorn

Joined: Jun 20, 2004
Posts: 2

posted

0

Thank you for that explanation, I was not using a floating point zero for my divisor.