• 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
  • Tim Cooke
  • paul wheaton
  • Paul Clapham
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Roland Mueller
  • Piet Souris
Bartenders:

NaN

 
Ranch Hand
Posts: 213
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Why is Float.NaN == Float.NaN equal to false?
I don't understand the think behind not being able to check if NaN is not equal to NaN.
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The special value NaN gets special treatment in all float related operations to ensure that your code does not lose track of the fact that a bad numeric operation occurred.
Use the static Float.isNaN( float ) method to detect NaN values.
Note there is also a NaN for double.
Bill
 
Charlie Swanson
Ranch Hand
Posts: 213
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The reason I am confused about this is isn't
Float.NaN or Double.NaN simply a constant of some sort.
 
Ranch Hand
Posts: 216
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi William,
I agree with you, a careless programmer can make such a mistake
while coding / debugging hence such a provision is provided in
situations wherein one needs to find out whether a NaN value
is occured during a programme.


Use the static Float.isNaN( float ) method to detect NaN values.


Ravindra Mohan.
 
reply
    Bookmark Topic Watch Topic
  • New Topic