• 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
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

Doubt in NaN

 
Ranch Hand
Posts: 361
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What exactly are .NaN values? I mean I know it stands for Not a Number but after that.
can only primitives use them?
why do all comparisons with .Nan(with non .NaN or .NaN) values result in a false? Can anyone give any simple example or usage.
 
Sheriff
Posts: 11343
Mac Safari Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In simple terms, you might think of NaN resulting from something that's undefined for real numbers -- for example, trying to obtain the square root of a negative number. See Wikipedia - NaN for more details.

As to why comparisons return false, consider that NaN is... Well, not a number. In other words, it's non-ordinal so it can't be considered "greater than," "less than," or even "equal to" some other quantity.

Note however that NaN != NaN returns true, so a float or double is NaN if it is not equal to itself (for example, x != x).
 
Ranch Hand
Posts: 809
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Also see it on Java Ranch faq

How can you compare NaN values?

Naseem
[ July 23, 2006: Message edited by: Naseem Khan ]
 
Creativity is allowing yourself to make mistakes; art is knowing which ones to keep. Keep this tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic