Java – Not A Number Gotcha

Examples

java

There are always subtle nuances to every computer language. Recently, I found the following NaN (not a number) nuance in Java:

Bad:

if (value == Double.NaN)
    // Do something...

Good:

if (Double.isNaN(value))

    // Do something....
1 Comment

1 Comment

  1. David Chandler  •  Jul 24, 2009 @14:27

    Thanks. The comparison seems like it should work, but oh well. All languages has oddities.

Leave a Reply

Allowed tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>