News for hackers. Stuff that matters.
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)
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
Re:WTFJS? by Locke1689 on Saturday February 13, 2010 @03:53AM (#1122766)

  Prelude> (0.1 + 0.2) == 0.3
  False
  Prelude Ratio> 1 % 10 + 2 % 10 == 3 % 10
  True
Re:WTFJS? by jrockway on Saturday February 13, 2010 @04:37AM (#1122827)
Or:

    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

Re:WTFJS? by martian on Friday February 12, 2010 @11:38PM (#1122553)
In Python

  >>> decimal.Decimal(".2") + decimal.Decimal(".1") == decimal.Decimal(".3")
  True
  >>> .2 + .1 == .3
  False