3 ms·
0.1 + 0.2 == 0.3 returns false in all the interpreters I have installed locally (Ruby, Python, NodeJS and Haskell), and you can't with a straight face pretend t
by WJW 7y ago
0.1 + 0.2 == 0.3 returns false in all the interpreters I have installed locally (Ruby, Python, NodeJS and Haskell), and you can't with a straight face pretend that Haskells type system is not strict enough.
Because I was curious, I tested it out with C# on repl.it and behold, 0.1 + 0.2 == 0.3 returns false in C# as well: https://repl.it/repls/AdoredValidVirtualmachines https://repl.it/repls/AdoredValidVirtualmachines. Not very surprising of course, since that "error" is a result of the IEEE floating point spec and not of any language.
- Davertron 7y agoThank you, I'm so sick of this being used as an example of why JavaScript is bad...
- covidcovidcovid 7y agoIf you write in C# decimal a = 0.1m; decimal b = 0.2m; var result = a + b; then you will get exactly 0.3, because decimal is a special high-precision numeric type that doesn't have such issues.