From: Operating system: Multiple PHP version: 5.2.13 Package: Math related Bug Type: Bug Bug description:should add to zero, but gets 1.1102230246252E-16 instead
Description: ------------ Math error for code that should be returning zero, but instead returns 1.1102230246252E-16 on multiple systems using multiple versions of PHP. The problem is that when the input value is -3 the output value should be zero: 0.9 + (-3 * 0.3) = 0.9 - 0.9 = 0. If the calculated value is non-zero the error does not occur. I first saw the error on a WinXP (Home SP3, 32bit) system running PHP 5.2.9-1, but it also shows up on a MAC (10.6.2) with PHP 5.3.0 installed. I'm in the process of upgrading PHP (to 5.2.13) on my Gentoo box to test it there but haven't had a chance to do so yet. Test script: --------------- my_function(-3); function my_function($input){ $output = 1; if($input <= 0) $output = 0.9 + ($input * 0.3); // the above should give 0.9 - 0.9 = 0 echo "Verifying values: 0.9 - ".($input * 0.3)." is supposed to be zero?\n"; echo "Input: $input\tOutput: $output\n"; return $output; } Expected result: ---------------- should have received zero (0). Actual result: -------------- actually received: 1.1102230246252E-16 -- Edit bug report at http://bugs.php.net/bug.php?id=51518&edit=1 -- Try a snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=51518&r=trysnapshot52 Try a snapshot (PHP 5.3): http://bugs.php.net/fix.php?id=51518&r=trysnapshot53 Try a snapshot (PHP 6.0): http://bugs.php.net/fix.php?id=51518&r=trysnapshot60 Fixed in SVN: http://bugs.php.net/fix.php?id=51518&r=fixed Fixed in SVN and need be documented: http://bugs.php.net/fix.php?id=51518&r=needdocs Fixed in release: http://bugs.php.net/fix.php?id=51518&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=51518&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=51518&r=needscript Try newer version: http://bugs.php.net/fix.php?id=51518&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=51518&r=support Expected behavior: http://bugs.php.net/fix.php?id=51518&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=51518&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=51518&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=51518&r=globals PHP 4 support discontinued: http://bugs.php.net/fix.php?id=51518&r=php4 Daylight Savings: http://bugs.php.net/fix.php?id=51518&r=dst IIS Stability: http://bugs.php.net/fix.php?id=51518&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=51518&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=51518&r=float No Zend Extensions: http://bugs.php.net/fix.php?id=51518&r=nozend MySQL Configuration Error: http://bugs.php.net/fix.php?id=51518&r=mysqlcfg