• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

float 12.0/0 error

 
mridul makkar
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why float f=12.0/0 wont raise any exception.I want to know the inner reason......
 
Jay Pawar
Ranch Hand
Posts: 411
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Check out this link . Hope this helps you.
 
vas vas
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Unlike Integer class in java, Float has a field called NaN. A constant holding a Not-a-Number value of type float.

so when you do 12.0/0 , this is NaN.This is not the same with integers.You get an exception when you do 12/0 , but not whne 12.0/0.

Hope this helps.
Suman Tedla.
 
Joe Borderi
Ranch Hand
Posts: 151
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"so when you do 12.0/0 , this is NaN."

12.0/0 is POSITIVE_INFINITY. NaN results from performing Java operations that result in "Not a Number", such as taking the square root of a negative number.

 
Srinivasa Raghavan
Ranch Hand
Posts: 1228
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is this even same for double ?
I mean does double has a NAN const.
 
Jesse Torres
Ranch Hand
Posts: 985
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by srini vasan:
Is this even same for double ?
I mean does double has a NAN const.


Yes primitive double also has a NaN constant.
 
Srinivasa Raghavan
Ranch Hand
Posts: 1228
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks guys nice info.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic