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

Very weird addition bug (.69+.69+.13 = 1.509999...)

So, I discovered this bizare bug. To reproduce, roll this: .69+.69+.13 The result is 1.5099999999999998. .69+.69+.69, .13+.13+.13, .13+.13+.69, etc. all add fine, but .69+.69+.13 does not add correctly. There's not much else to say. This is a very bizarre bug.
1414162545
Lithl
Pro
Sheet Author
API Scripter
This is a result of performing math on floating-point numbers. Wikipedia has a lot of technical information on the problem, if you're actually interested: <a href="http://en.wikipedia.org/wiki/Floating_point#IEEE_7" rel="nofollow">http://en.wikipedia.org/wiki/Floating_point#IEEE_7</a>... The long and short of it is that it's not Roll20's fault, but rather the fault of the way computers store and manipulate information (specifically, fractional numbers) .
I have seen this weird floating point error come up before, and I have to wonder, isn't there some sort of easy work around the devs could implement? I admit to not reading the entire link, and even if I did, I admit I probably wouldn't understand it. If I bring up the calculator in windows it does it right. So does the one on my android phone. There definitely are solutions out there somewhere.....is it that difficult to code, or that computationally expensive to do?
Most programs that require accuracy like calculators or accounting programs use a composite data type like BigDecimal in Java instead of a primitive data type like Double/Float. It's a bit more expensive to use, so I guess the dev team didn't feel it was worth it.
1414321171
Lithl
Pro
Sheet Author
API Scripter
Zamp said: Most programs that require accuracy like calculators or accounting programs use a composite data type like BigDecimal in Java instead of a primitive data type like Double/Float. It's a bit more expensive to use, so I guess the dev team didn't feel it was worth it. Roll20 is primarily written with JavaScript. All numbers in JavaScript are 64-bit floating point numbers, and there is no standard BigNumber implementation in JavaScript (although I'm sure there exist a few third-party implementations with varying degrees of quality). There is also no fixed point number data type, to go the other direction.