2

In java we can use the isNan() method for float and double values.
E.g.:

 if (!Double.isNaN(0.01)) {
     // condition happens    
 } 


 if (!Float.isNaN(0.01F)) {
     // condition happens    
 } 


I wonder why we can't use it for Integers.

Mureinik
  • 297,002
  • 52
  • 306
  • 350
Dil.
  • 1,996
  • 7
  • 41
  • 68
  • 6
    Because integers and strings aren't allowed to take up holy orders? (Sorry, mocking the `isNun` typo). – IMSoP Dec 16 '14 at 00:37
  • You can check out http://stackoverflow.com/questions/17615634/why-doesnt-integer-represent-nan-in-java for more information from a similar question – nunofmendes Dec 16 '14 at 00:40
  • 1
    @IMSoP The Java, the Sun (Microsystems), and the malformed POST? – mkobit Dec 16 '14 at 00:41
  • My mistake to ask this question.. :D thank you anyway for clearing the idea.. – Dil. Dec 16 '14 at 00:46

3 Answers3

5

NaN is Not a Number, i.e., an undefined or unrepresentible number, such as the square root of -1. Integers are always well defined, and Strings just aren't numbers at all, so they are irrelevant for checking against being NaN.

Mureinik
  • 297,002
  • 52
  • 306
  • 350
2

Because String and Integer can't be NaN.

Marv
  • 3,517
  • 2
  • 22
  • 47
2

NaN is a special value of floating point numbers, along with others like Infinity; integers and strings don't have such special values, so the functions to check for them would make no sense.

The reason they exist is to represent the results of certain calculations, so that floating point numbers can be used in arbitrary mathematical situations.

IMSoP
  • 89,526
  • 13
  • 117
  • 169