0.1 and 0.2 Returns 0.30000000000000004 (2018)
1–10 of 161 posts
Re: 0.1 and 0.2 Returns 0.30000000000000004 (2018)
#2Floating point considered harmful
Edit: this is not a blanket statement. It was meant in the context.
Re: 0.1 and 0.2 Returns 0.30000000000000004 (2018)
#3It sure does: https://0.30000000000000004.com/
Re: 0.1 and 0.2 Returns 0.30000000000000004 (2018)
#4Not 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)
#5Floating point considered harmful Edit: this is not a blanket statement. It was meant in the context.
Misunderstanding floating point is more harmful than floating point itself.
Re: 0.1 and 0.2 Returns 0.30000000000000004 (2018)
#6[2018]
Re: 0.1 and 0.2 Returns 0.30000000000000004 (2018)
#7Re: 0.1 and 0.2 Returns 0.30000000000000004 (2018)
#8I've seen a lot of stuff on getting the shortest representation that is equal to the floating point value back but what about finding the minimum/maximum representation that is equal to a given value?
Re: 0.1 and 0.2 Returns 0.30000000000000004 (2018)
#9This 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.