• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

Division by ZERO

 
Ranch Hand
Posts: 192
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 1514
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Check the API. float or double division by zero does not throw NFE.
 
Ranch Hand
Posts: 3244
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thomas
From the JLS section 4.2.4
Floating-point operators produce no exceptions .
 
author
Posts: 14112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
 
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Take a look at the Incomperable NaN item of Roedy Green's list of Java Gotchas.
reply
    Bookmark Topic Watch Topic
  • New Topic