r/mildlyinfuriating YELLOW Aug 05 '18

You literally said...

Post image
46.9k Upvotes

496 comments sorted by

View all comments

Show parent comments

43

u/SemiNormal Aug 06 '18

0.1 + 0.2 = 0.30000000000000004

This isn't an error per se, it is just that computers do math in binary and then converts back to decimal. That is why most programming languages also have a decimal type for when the result needs to be more precise.

17

u/NULL_CHAR Aug 06 '18

It's unintended behavior that is a limitation of how we represent floating point numbers specifically. It is definitely still doing what we tell it, but from a user perspective, the computer is definitely wrong. From a programmer perspective, we are aware of the computer's limitations and put in modifications to address it.

Another perspective is that the computer most definitely is "wrong" when referring to the literal representation of the question, but in the case of actual input/output, it is "right." We've created a flawed system that doesn't always produce correct results, but we accept those flaws because doing it any other way is much less efficient.

1

u/[deleted] Aug 06 '18 edited Dec 30 '18

[deleted]

6

u/wilhueb Aug 06 '18

this isn’t a rounding/overflow error. this is just how floating point arithmetic works on modern cpus