Roll20 uses cookies to improve your experience on our site. Cookies enable you to enjoy certain features, social sharing functionality, and tailor message and display ads to your interests on our site and others. They also help us understand how our site is being used. By continuing to use our site, you consent to our use of cookies. Update your cookie preferences .
×
Create a free account

My life is a lie!

I had a math issue, and while its not important, I thought it was kind of funny. Somehow it didn't quite do that math correctly. I typed ./r 577.2-172.8, and got 404.40000000000000000003.
1396785447
Lithl
Pro
Sheet Author
API Scripter
0.2 = 2 * 1/10, 0.8 = 8 * 1/10. 1/10 is a repeating decimal in base-2, just like 1/3 is a repeating decimal in base-10. (In fact, any fraction whose denominator is not a power of 2 will have an infinite representation in base-2.) Computers are always working in base-2. If you round the binary representation of 0.1 to 24 bits, the result is the value 0.100000001490116119384765625. Floating-point arithmetic has problems, as well. For example (using 24-bit representations), 0.1 * 0.1 results in ~0.0100000003, whereas the representable number closest to 0.01 (the correct answer) is ~0.0099999998. For more fun, addition and multiplication remain commutative (a + b = b + a) in floating-point arithmetic, but they are not associative ((a + b) + c =/= a + (b + c)) or distributive ((a + b) * c =/= a * c + b * c). Floating-point precision errors have gotten people killed .
Thats actually really neat! (I mean not the dead people part) but the explanation. I did not know computers computed like that, it makes me wonder if financial institutions can benefit from little things like this when they are dealing with billions of dollars.
1396848031
Karl V.
Pro
Translator
Money in computer systems is typically represented by integers, not floating point numbers. Hence no precision error. The bank makes money on stuff like investing capital for interest while it is being transfered and taking exorbiant fees for services that costs them nothing, but not through calculation errors.