Live data from Hacker News

0.1 and 0.2 Returns 0.30000000000000004 (2018)

qntm.org

1–10 of 161 posts

Re: 0.1 and 0.2 Returns 0.30000000000000004 (2018)

#4
Not in Raku it doesn't!

    > 1.1 + 2.2
    3.3
    > 1.1 + 2.2 == 3.3
    True
EDIT: to be clear: this is not because Raku is magic, it's because Raku defaults to a rational number type for decimal literals, which is arguably a much better choice for a language like Raku.

Re: 0.1 and 0.2 Returns 0.30000000000000004 (2018)

#9
This is pretty much the same problem as what does 1/3 + 1/3 = in decimal. You are specifying fractions that don’t have an exact finite representation in that base (base 10 with 1/3) and (base 2 with 0.1 or 1/10).

With proper rounding and I/O these are not generally an issue.

Re: 0.1 and 0.2 Returns 0.30000000000000004 (2018)

#10
post #7
post #5

Earlier quoted context omitted.

Misunderstanding floating point is more harmful than floating point itself.

Hence why it's harmful.

Floating point arithmetic powers everything from computer graphics to weather simulations. Seems rather silly to dismiss it as an anti-pattern.
Post reply on HN