• 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:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Floating point divide by zero

 
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can anybody explain whether the following statement is true or not.
If true, please explain.

Floating point modulo (%) by zero produces NaN , but floating point divide by zero does not.
 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi
Its true
Floating point divide by zero produces Infinity & Floating point modulo by zero produces NaN(not a number)
 
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
does anyone know the reason behind this ?

Why arithmetic exception happens for int and not for float ?
[ March 28, 2007: Message edited by: JB Ramesh ]
 
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by JB Ramesh:
does anyone know the reason behind this ?

Why arithmetic exception happens for int and not for float ?



The behavior of float is actually defined by the IEEE standard. Java follows the same standard used by most floating point processors in use today.

As for int, it throws an exception, because there is no representation for infinity or NaN.

Henry
 
Srinivas Kumar
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
My actual doubt is that floating point module zero also does divide by zero internally. So why Nan is getting printed instead of Infinity?
 
reply
    Bookmark Topic Watch Topic
  • New Topic