From: netnessie at gmail dot com Operating system: Linux PHP version: 5.2.0 PHP Bug Type: *Programming Data Structures Bug description: Range function produces odd values in foreach loop
Description: ------------ When you use the range function, with a range between zero and 1, incrementing by 0.05 each step, the loop produces an incorrect result when you attempt to minus the current value in the loop from 1. As you can see below, the last element in the array is the integer 1. The script should echo the result of 1 minus 1. However, for some reason PHP treats 1-1 as -2.22044604925E-16 instead of zero. Reproduce code: --------------- foreach (range(0,1,0.05) as $t) { echo (1-$t).'<br />'; } Expected result: ---------------- 1 0.95 0.9 0.85 0.8 0.75 0.7 0.65 0.6 0.55 0.5 0.45 0.4 0.35 0.3 0.25 0.2 0.15 0.1 0.05 0 Actual result: -------------- 1 0.95 0.9 0.85 0.8 0.75 0.7 0.65 0.6 0.55 0.5 0.45 0.4 0.35 0.3 0.25 0.2 0.15 0.1 0.05 -2.22044604925E-16 -- Edit bug report at http://bugs.php.net/?id=39464&edit=1 -- Try a CVS snapshot (PHP 4.4): http://bugs.php.net/fix.php?id=39464&r=trysnapshot44 Try a CVS snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=39464&r=trysnapshot52 Try a CVS snapshot (PHP 6.0): http://bugs.php.net/fix.php?id=39464&r=trysnapshot60 Fixed in CVS: http://bugs.php.net/fix.php?id=39464&r=fixedcvs Fixed in release: http://bugs.php.net/fix.php?id=39464&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=39464&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=39464&r=needscript Try newer version: http://bugs.php.net/fix.php?id=39464&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=39464&r=support Expected behavior: http://bugs.php.net/fix.php?id=39464&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=39464&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=39464&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=39464&r=globals PHP 3 support discontinued: http://bugs.php.net/fix.php?id=39464&r=php3 Daylight Savings: http://bugs.php.net/fix.php?id=39464&r=dst IIS Stability: http://bugs.php.net/fix.php?id=39464&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=39464&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=39464&r=float No Zend Extensions: http://bugs.php.net/fix.php?id=39464&r=nozend MySQL Configuration Error: http://bugs.php.net/fix.php?id=39464&r=mysqlcfg