aspose file tools*
The moose likes Beginning Java and the fly likes Division by ZERO 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 » Java » Beginning Java
Bookmark "Division by ZERO" Watch "Division by ZERO" New topic
Author

Division by ZERO

Thomas Markl
Ranch Hand

Joined: Mar 08, 2001
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)
Exception in thread "main"


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

Joined: Nov 06, 2000
Posts: 1510
Check the API. float or double division by zero does not throw NFE.


Bosun (SCJP, SCWCD)
So much trouble in the world -- Bob Marley
Dave Vick
Ranch Hand

Joined: May 10, 2001
Posts: 3244
Thomas
From the JLS section 4.2.4
Floating-point operators produce no exceptions .


Dave
Ilja Preuss
author
Sheriff

Joined: Jul 11, 2001
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


The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
Dirk Schreckmann
Sheriff

Joined: Dec 10, 2001
Posts: 7023
Take a look at the Incomperable NaN item of Roedy Green's list of Java Gotchas.


[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Division by ZERO