Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

About NAN

 
Xiao Song
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,everyone, Why the result is false??


Thanks advance!!
 
Joe Harry
Ranch Hand
Posts: 10124
3
Eclipse IDE Mac PPC Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
0.0/0.0 is NaN and NaN is different from 0. Hence false.
 
Xiao Song
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a lot.
In rt.jar NaN is defined as follows:


A constant holding the largest positive finite value of type
double,It is equal to the hexadecimal floating-point literal
0x1.fffffffffffffP+1023 and also equal to
Double.longBitsToDouble(0x7fefffffffffffffL)


What is this mean??
 
Burkhard Hassel
Ranch Hand
Posts: 1274
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi ranchers,
Xiao Song posted November 20, 2006 01:39 AM
Hello,everyone, Why the result is false??
when you perform arithmetic operation on NaN the result will also be not a number.
So NaN - NaN = NaN
and NaN is not zero.

Furthermor NaN is unuequal to everything, including itself (this may give you some headaches if you think about it).

eg

prints
NaN
false
true
 
Xiao Song
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Burkhard Hassel, His explonatio is very clear.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic