• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

NaN and '=='

 
Joseph Clark
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

The following is from Dan Chisholm's.
The output is: true false true.
Can anyone explain the practical advantage of the following behaviour regarding *.NaN and '=='?
 
Fes D Gaur
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
NAN is not equal to anything including itself. So

(NAN == NAN) will result in false.

Fes
 
Barry Gaunt
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For an explanation I can only suggest reading the IEEE 754 Standard and the Java Language Specification. There are also interesting documents on the Web if you search for them. Those programmers who are involved in scientific computing need to know this stuff, but for a large number of commercial applications it is not necessary to go into such detail. It is certainly not necessary for SCJP 5.0.

What I love most is Double.NaN != Double.NaN is true
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic