Re:WTFJS?
by waldrews on Friday February 12, 2010 @06:36PM
(#1122147)
In what language is 0.1 + 0.2 == 0.3? (I guess C# with decimal literals, but you'd have to specify that with a suffix)
[ Parent
| on HN ]
Re:WTFJS?
by twopoint718 on Friday February 12, 2010 @09:13PM
(#1122395)
I was curious and fired up sbcl:
* (= (+ 0.1 0.2) 0.3)
T
* (type-of 0.1)
SINGLE-FLOAT
* (= 0.3d0 (+ 0.1d0 0.2d0))
NIL
* (type-of 0.1d0)
DOUBLE-FLOAT Prelude> (0.1 + 0.2) == 0.3
False
Prelude Ratio> 1 % 10 + 2 % 10 == 3 % 10
TrueOr:
ghci> 0.1 + 0.2 == (0.3 :: Ratio Int)
True
Same type, less syntax.
Re:WTFJS?
by regularfry on Saturday February 13, 2010 @06:59AM
(#1122933)
That's cheating. Haskell isn't a language, it's The Word of Simon.
The question of which Simon is left as an exercise to the reader.
Re:WTFJS?
by techiferous on Friday February 12, 2010 @10:25PM
(#1122467)
In Ruby:
0.1 + 0.2 == 0.3 => false
According to "The Ruby Programming Language", all languages that use IEEE-754 floating-point numbers have this problem.
In Ruby you can get around this by using BigDecimal.
>> require 'bigdecimal'
=> true
>> require 'bigdecimal/util'
=> true
>> 0.1.to_d + 0.2.to_d == 0.3.to_d
=> true