This week's book giveaway is in the Security forum.We're giving away four copies of Penetration Testing Basics and have Ric Messier on-line!See this thread for details.
Win a copy of Penetration Testing Basics this week in the Security forum!

# Division by ZERO

Thomas Markl
Ranch Hand
Posts: 192
When I divide 10 / 0 then Exception „Divided by zero“ should appear as in example 1.
Why doesn’t it apper in Example 2 with „double d“?
And why POSITIVE Infinity?

C:\Java\EigeneJavaProgramme>java Positive_infinity_test
java.lang.ArithmeticException: / by zero
at Positive_infinity_test.main(Positive_infinity_test.java:5)

C:\Java\EigeneJavaProgramme>java Positive_infinity_test
10.0 / -0) = Infinity
Positive infinityInfinity

C:\Java\EigeneJavaProgramme>java Positive_infinity_test
10.0 / -0) = Infinity
Positive infinityInfinity

Bosun Bello
Ranch Hand
Posts: 1511
Check the API. float or double division by zero does not throw NFE.

Dave Vick
Ranch Hand
Posts: 3244
Thomas
From the JLS section 4.2.4
Floating-point operators produce no exceptions .

Ilja Preuss
author
Sheriff
Posts: 14112
Originally posted by Thomas Markl:
When I divide 10 / 0 then Exception „Divided by zero“ should appear as in example 1.
Why doesn’t it apper in Example 2 with „double d“?
And why POSITIVE Infinity?

Because it is usefull for the following reason:
lim (x -> +0) (10/x) = positive infinity
That is, the nearer x gets to zero, the bigger gets 10/x

Dirk Schreckmann
Sheriff
Posts: 7023
Take a look at the Incomperable NaN item of Roedy Green's list of Java Gotchas.