Bug 62644 - math addition and subtraction errors
math addition and subtraction errors
Status: CLOSED CURRENTRELEASE
Product: Red Hat Linux
Classification: Retired
Component: gnome-utils (Show other bugs)
7.2
i386 Linux
medium Severity medium
: ---
: ---
Assigned To: Havoc Pennington
Brian Brock
:
Depends On:
Blocks:
  Show dependency treegraph
 
Reported: 2002-04-03 13:14 EST by Craig
Modified: 2008-08-01 12:22 EDT (History)
0 users

See Also:
Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Environment:
Last Closed: 2002-04-10 11:00:04 EDT
Type: ---
Regression: ---
Mount Type: ---
Documentation: ---
CRM:
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---


Attachments (Terms of Use)

  None (edit)
Description Craig 2002-04-03 13:14:20 EST
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):


How reproducible:
Always

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

 -or-
2. write a perl script to add and subtract these numbers
-or-
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

Additional info:

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)
Comment 1 Trond Eivind Glomsrxd 2002-04-10 10:59:57 EDT
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.
Comment 2 Havoc Pennington 2002-04-10 11:03:18 EDT
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:
http://bugzilla.gnome.org/show_bug.cgi?id=78292

Closing on Red Hat level.

Note You need to log in before you can comment on or make changes to this bug.