3 ms·
That's just normal floating point behavior. NaN isn't equal to anything, not even itself. It's in the standard.
by roywiggins 9y ago
That's just normal floating point behavior. NaN isn't equal to anything, not even itself. It's in the standard.
- tambourine_man 9y agoFloating point can be a bit mind bending. Still, something not being equal to itself almost pushes the barrier into philosophy.
- fmihaila 9y agoNaN 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.
- goatlover 9y agoHow is isNaN() implemented?
- Gaelan 9y agofunction 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.
- tambourine_man 9y agoWe really are deep in the realm of Philosophy.
- roywiggins 9y agoAs 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.