Win a copy of Testing JavaScript Applications this week in the HTML Pages with CSS and JavaScript forum!
  • 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
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

NaN==NaN and NaN===NaN ?

 
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
why NaN==NaN and NaN===NaN return false?
 
Marshal
Posts: 69847
278
  • 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.
 
Rancher
Posts: 3571
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: 69847
278
  • 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: 12871
62
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: 69847
278
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you. I am feeling too lazy to search anything.
 
What's a year in metric? Do you know this metric stuff tiny ad?
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic