From: spartacus4+php at gmail dot com
Operating system: Mac OSX
PHP version: 5.2.5
PHP Bug Type: Math related
Bug description: Adding decimals to math calc where it should not
Description:
------------
It appears PHP is adding incorrect decimal points.
The included test script shows this happening at value: 31243.41.
When I add the two values: 31243.41 + 49.83 it produces the correct sum.
But if I use it in an array that += the amount, it adds an incorrect
decimal value after several hundred add ons. It appears to be a possible
memory flaw when summing array values.
FYI: I'm actually using PHP version 5.2.3 - it was not an option in the
drop down.
Reproduce code:
---------------
$amount = '49.83';
$out=array();
$type='test';;
for($i=0; $i<1000; $i++){
if(!isset($out[$test][$result])) $out[$test][$result]=0;
$out[$test][$result] += $amount;
echo $out[$test][$result].' + '.$amount.'<br>';
}
echo '<pre>';
print_r($out);
echo '</pre>';
Expected result:
----------------
Either an explanation of why the decimal points are added only when using
an array value OR potentially a bug fix within new version fixing this
flaw.
Actual result:
--------------
Actual results are output within included code.
--
Edit bug report at http://bugs.php.net/?id=44659&edit=1
--
Try a CVS snapshot (PHP 5.2):
http://bugs.php.net/fix.php?id=44659&r=trysnapshot52
Try a CVS snapshot (PHP 5.3):
http://bugs.php.net/fix.php?id=44659&r=trysnapshot53
Try a CVS snapshot (PHP 6.0):
http://bugs.php.net/fix.php?id=44659&r=trysnapshot60
Fixed in CVS: http://bugs.php.net/fix.php?id=44659&r=fixedcvs
Fixed in release:
http://bugs.php.net/fix.php?id=44659&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=44659&r=needtrace
Need Reproduce Script: http://bugs.php.net/fix.php?id=44659&r=needscript
Try newer version: http://bugs.php.net/fix.php?id=44659&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=44659&r=support
Expected behavior: http://bugs.php.net/fix.php?id=44659&r=notwrong
Not enough info:
http://bugs.php.net/fix.php?id=44659&r=notenoughinfo
Submitted twice:
http://bugs.php.net/fix.php?id=44659&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=44659&r=globals
PHP 4 support discontinued: http://bugs.php.net/fix.php?id=44659&r=php4
Daylight Savings: http://bugs.php.net/fix.php?id=44659&r=dst
IIS Stability: http://bugs.php.net/fix.php?id=44659&r=isapi
Install GNU Sed: http://bugs.php.net/fix.php?id=44659&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=44659&r=float
No Zend Extensions: http://bugs.php.net/fix.php?id=44659&r=nozend
MySQL Configuration Error: http://bugs.php.net/fix.php?id=44659&r=mysqlcfg