Bug 62644

Summary: math addition and subtraction errors
Product: [Retired] Red Hat Linux Reporter: Craig <craig>
Component: gnome-utilsAssignee: Havoc Pennington <hp>
Status: CLOSED CURRENTRELEASE QA Contact: Brian Brock <bbrock>
Severity: medium Docs Contact:
Priority: medium    
Version: 7.2   
Target Milestone: ---   
Target Release: ---   
Hardware: i386   
OS: Linux   
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2002-04-10 15:00:04 UTC Type: ---
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:

Description Craig 2002-04-03 18:14:20 UTC
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 14:59:57 UTC
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 15:03:18 UTC
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.