Bug 62644 - math addition and subtraction errors
Summary: math addition and subtraction errors
Keywords:
Status: CLOSED CURRENTRELEASE
Alias: None
Product: Red Hat Linux
Classification: Retired
Component: gnome-utils
Version: 7.2
Hardware: i386
OS: Linux
medium
medium
Target Milestone: ---
Assignee: Havoc Pennington
QA Contact: Brian Brock
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2002-04-03 18:14 UTC by Craig
Modified: 2008-08-01 16:22 UTC (History)
0 users

Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Clone Of:
Environment:
Last Closed: 2002-04-10 15:00:04 UTC
Embargoed:


Attachments (Terms of Use)

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.


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