• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • salvin francis
  • fred rosenberger

NaN==NaN and NaN===NaN ?

 
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
why NaN==NaN and NaN===NaN return false?
 
Marshal
Posts: 69494
277
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Look up IEEE754; you will find that it defines that the behaviour of equality symbols show NaN as always unequal to itself.
 
Master Rancher
Posts: 3539
39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, that doesn't really say anything about why it's this way.  In this case, it's helpful to look at what sort of operations return NaN.  Offhand, I know of 0.0/0.0, the square root of a negative number, the logarithm of a negative number, and various inverse trigonometric functions such as arcsin(2).  If those operations are all NaN, should they be equal to each other?  That wouldn't make much sense, I think.


[I belatedly saw that this was posted in C#, and I posted Java code.  But the basic point remains the same, I think.]
 
Campbell Ritchie
Marshal
Posts: 69494
277
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Mike Simmons wrote:. . . the basic point remains the same . . . .

Yes, I am sure it does.

By the way: what does the === operator do?
 
lowercase baba
Posts: 12856
52
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Campbell Ritchie wrote:By the way: what does the === operator do?


Oh Campbell....that seems like something a quick google search would tell you.  ;-)

If i recall, it's a strictly equals.  in some languages, an int of 10 would be equal to a string of "10", but not strictly equal, due to different types.
 
Campbell Ritchie
Marshal
Posts: 69494
277
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you. I am feeling too lazy to search anything.
 
If you live in a cold climate and on the grid, incandescent light can use less energy than LED. Tiny ad:
Devious Experiments for a Truly Passive Greenhouse!
https://www.kickstarter.com/projects/paulwheaton/greenhouse-1
    Bookmark Topic Watch Topic
  • New Topic