Red Hat Bugzilla – Bug 62644
math addition and subtraction errors
Last modified: 2008-08-01 12:22:52 EDT
From Bugzilla Helper:
User-Agent: Mozilla/5.0 (X11; U; Linux i586; en-US; rv:0.9.7) Gecko/20011226
Description of problem:
Using perl, php or even the gnome calculator, adding 39.9+19.95=59.85
subtracting 59.85 should = 0 but does not. (very small number -7.10543e-15)
Version-Release number of selected component (if applicable):
Steps to Reproduce:
1.in X windows (I used gnome calculator) add 39.9 to 19.95 and subtract
the sum (59.85) which should equal 0
2. write a perl script to add and subtract these numbers
3. write a php script to add and subtract these numbers
Actual Results: You get output of -7.10543e-15 instead of 0
Expected Results: You should get 0
We've countered this problem in scripting by using an if < than 0 statement.
Linux rocks, but it should add and subtract right. (Micorsoft products do (yuk)
Floating point math isn't exact - you can't represent an infinite range (R - all
real numbers) in a finite space of 2^(precision) combinations. Thus, don't count
on having a specific number when you have done a series of numerical
calculations. This is especially a problem with 0, as if it was 1+1e-20, the
last part would be truncated when displayed.
In perl/php this is entirely normal and expected, that's how floating point
calculations work, they have limited precision.
The calculator app should work around it though, bug filed upstream here:
Closing on Red Hat level.