#28542 [NEW]: Floating point error while adding values to a float var

From: Date: Thu, 27 May 2004 13:01:30 +0000
Subject: #28542 [NEW]: Floating point error while adding values to a float var
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-60070@lists.php.net to get a copy of this message
From: tny at eyefi dot nl Operating system: Linix / BSDs PHP version: 4.3.6 PHP Bug Type: Variables related Bug description: Floating point error while adding values to a float var Description: ------------ When adding a float value to a variable (starting with a negative value) in a loop the result that should be zero (0) is nearly zero, but not exact zero. Reproduce code: --------------- <?php for ($i = -1.0; $i <= 1.0; $i += 0.1) { echo $i . "\n"; } ?> Expected result: ---------------- -1 -0.9 -0.8 -0.7 -0.6 -0.5 -0.4 -0.3 -0.2 -0.1 0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1 Actual result: -------------- -1 -0.9 -0.8 -0.7 -0.6 -0.5 -0.4 -0.3 -0.2 -0.1 -1.38777878078E-16 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1 -- Edit bug report at http://bugs.php.net/?id=28542&edit=1 -- Try a CVS snapshot (php4): http://bugs.php.net/fix.php?id=28542&r=trysnapshot4 Try a CVS snapshot (php5): http://bugs.php.net/fix.php?id=28542&r=trysnapshot5 Fixed in CVS: http://bugs.php.net/fix.php?id=28542&r=fixedcvs Fixed in release: http://bugs.php.net/fix.php?id=28542&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=28542&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=28542&r=needscript Try newer version: http://bugs.php.net/fix.php?id=28542&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=28542&r=support Expected behavior: http://bugs.php.net/fix.php?id=28542&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=28542&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=28542&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=28542&r=globals PHP 3 support discontinued: http://bugs.php.net/fix.php?id=28542&r=php3 Daylight Savings: http://bugs.php.net/fix.php?id=28542&r=dst IIS Stability: http://bugs.php.net/fix.php?id=28542&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=28542&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=28542&r=float

« previous php.bugs (#60070) next »