From:             boydell at orbsix dot com
Operating system: WinXP, Linux
PHP version:      5.2.3
PHP Bug Type:     Math related
Bug description:  double precision error

Description:
------------
The math on the following should be zero.

echo (65 + 50 - 50 + 15 - 15 + 100 - 100 + 50 + 16.50 - 36.50 + 88.21 -
38.21 - 145);

but we get: -2.84217094304E-14




Reproduce code:
---------------
$list = array(65, 50, -50, 15, -15, 100, -100, 50, 16.50, -36.50, 88.21,
-38.21, -145);
$current = 0;
foreach($list as $number) {
        echo $current . "+" . $number . "=";
        $current += $number;
        echo $current . "\n<br>";
}


Expected result:
----------------
0+65=65
65+50=115
115+-50=65
65+15=80
80+-15=65
65+100=165
165+-100=65
65+50=115
115+16.5=131.5
131.5+-36.5=95
95+88.21=183.21
183.21+-38.21=145
145+-145=0

Actual result:
--------------
0+65=65
65+50=115
115+-50=65
65+15=80
80+-15=65
65+100=165
165+-100=65
65+50=115
115+16.5=131.5
131.5+-36.5=95
95+88.21=183.21
183.21+-38.21=145
145+-145=-2.8421709430404E-14 

-- 
Edit bug report at http://bugs.php.net/?id=42333&edit=1
-- 
Try a CVS snapshot (PHP 4.4): 
http://bugs.php.net/fix.php?id=42333&r=trysnapshot44
Try a CVS snapshot (PHP 5.2): 
http://bugs.php.net/fix.php?id=42333&r=trysnapshot52
Try a CVS snapshot (PHP 6.0): 
http://bugs.php.net/fix.php?id=42333&r=trysnapshot60
Fixed in CVS:                 http://bugs.php.net/fix.php?id=42333&r=fixedcvs
Fixed in release:             
http://bugs.php.net/fix.php?id=42333&r=alreadyfixed
Need backtrace:               http://bugs.php.net/fix.php?id=42333&r=needtrace
Need Reproduce Script:        http://bugs.php.net/fix.php?id=42333&r=needscript
Try newer version:            http://bugs.php.net/fix.php?id=42333&r=oldversion
Not developer issue:          http://bugs.php.net/fix.php?id=42333&r=support
Expected behavior:            http://bugs.php.net/fix.php?id=42333&r=notwrong
Not enough info:              
http://bugs.php.net/fix.php?id=42333&r=notenoughinfo
Submitted twice:              
http://bugs.php.net/fix.php?id=42333&r=submittedtwice
register_globals:             http://bugs.php.net/fix.php?id=42333&r=globals
PHP 3 support discontinued:   http://bugs.php.net/fix.php?id=42333&r=php3
Daylight Savings:             http://bugs.php.net/fix.php?id=42333&r=dst
IIS Stability:                http://bugs.php.net/fix.php?id=42333&r=isapi
Install GNU Sed:              http://bugs.php.net/fix.php?id=42333&r=gnused
Floating point limitations:   http://bugs.php.net/fix.php?id=42333&r=float
No Zend Extensions:           http://bugs.php.net/fix.php?id=42333&r=nozend
MySQL Configuration Error:    http://bugs.php.net/fix.php?id=42333&r=mysqlcfg

Reply via email to