Re:NaN does not equal NaN
by masklinn on Tuesday September 27, 2011 @04:35PM
(#3045106)
You know what's a simple test for NaN? The isNaN built-in function...
[ Parent
| on HN ]
Re:NaN does not equal NaN
by simonsarris on Tuesday September 27, 2011 @04:45PM
(#3045159)
Yes, but this is bigger than that. JavaScript doesn't define NaN, IEEE-754 defines NaN and JavaScript takes its definition from that. So it's IEEE-754 thinks num == num being false is a good test for NaN.
For the record, isNaN in JavaScript is also not necessarily the fastest way of doing it: http://jsperf.com/nantest
> For the record, isNaN in JavaScript is also not necessarily the fastest way of doing it
Which will absolutely not matter in 100% of the cases after rounding. `isNaN` is simple (your original criteria) and clearly says what it's doing.