Hacker News new | ask | show | jobs
by roywiggins 3246 days ago
That's just normal floating point behavior. NaN isn't equal to anything, not even itself. It's in the standard.
1 comments

Floating point can be a bit mind bending. Still, something not being equal to itself almost pushes the barrier into philosophy.
As long as you can define what's going on rigorously, it's just mathematics :) The equality operator means just what I choose it to mean- neither more nor less, as Humpty Dumpty would say.

Also fun: (NaN < x) should be false for every x, and (NaN > x) should be false for every x. It's not a number, so it's not less than or greater than any number. But then by process of elimination, NaN == x for every x. Which is obviously nonsense. So equality and comparison is completely "broken" anyway when you start comparing NaN to things.

NaN is not a name for one thing. You could think of not a number as not any particular thing. There is no comparison with itself, because there is no it.
How is isNaN() implemented?

    function isNaN(x) { return x !== x }
It’s a native browser function so it may not actually be done that way, but that’s one way you could do it.
We really are deep in the realm of Philosophy.