3 ms·
NaN++ is sometimes a TypeError in environments that define NaN as read only, that one’s sometimes wrong. The float examples aren’t weird in JS, they’re the sam
by dahart 5y ago
NaN++ is sometimes a TypeError in environments that define NaN as read only, that one’s sometimes wrong.
The float examples aren’t weird in JS, they’re the same in all languages that use IEEE 754 floats, which specifies that NaN != x, where x is anything.
“This is due to a decision made by the IEEE-754 committee for a few reasons, such as space efficiency and the fact that the function isNaN didn't exist at the time.”
This explanation feels like it’s trying hard to downplay the reasons and make it sound arbitrary and almost whimsical. It doesn’t make sense to allow NaN - NaN = 0 (Note that Infinity - Infinity == NaN), and it’s important that NaNs used as input to computation produce NaNs as output (other than when using boolean tests).