3 ms·
> 0.2 + 0.1 === 0.3 This isn't just javascript though. It's harder to find a language for which this would be true than the other way around.
by azangru 3y ago
> 0.2 + 0.1 === 0.3
This isn't just javascript though. It's harder to find a language for which this would be true than the other way around.
- mohbk 3y agoand typeof NaN == "number" is also part of the standard, it is valid to pass NaN to functions that accept numbers, and it's expected to propagate or change back to normal numbers (e.g. NaN^0=1)
- marcosdumay 3y agoIf anything, JS has plenty of problems due to its too literal interpretation of NaN.
- bee_rider 3y agoI mean, it is a weird statement in that the language apparently needs a === operator. Of course, after looking up what === is, the behavior is obvious.
- threatofrain 3y agoThat wouldn't change anything here. This behavior is due to the IEEE 754 number spec, which is implemented in many languages.
- bee_rider 3y agoThe floating point behavior is the obvious part, the === operator is the head-scratcher.
- kerkeslager 3y agoYeah, this is a IEEE754 floating point issue. I'm not sure why it seems there hasn't been any progress made on making floating point types less error-prone in the last few decades.
- bazoom42 3y agoRounding errors are unavoidable when representing an infinite amout of numbers in a fixed number of bits. But in many cases a decimal type (like in C#) would have more intuitive behvior than binary floating point. A decimal type have been proposed for JavaScript but I dont know how far along it is.