#43447 [Opn->Bgs]: comparison in a for-loop is not exact
| From: | derick@php.net | Date: | Thu, 29 Nov 2007 12:12:47 +0000 |
| Subject: | #43447 [Opn->Bgs]: comparison in a for-loop is not exact | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-120209@lists.php.net to get a copy of this message | ||
ID: 43447
Updated by: derick@php.net
Reported By: jumo at gmx dot de
-Status: Open
+Status: Bogus
Bug Type: *General Issues
Operating System: Ubuntu Linux
PHP Version: 5.2.5
New Comment:
Floating point values have a limited precision. Hence a value might
not have the same string representation after any processing. That also
includes writing a floating point value in your script and directly
printing it without any mathematical operations.
If you would like to know more about "floats" and what IEEE
754 is read this:
http://docs.sun.com/source/806-3568/ncg_goldberg.html
Thank you for your interest in PHP.
.
Previous Comments:
------------------------------------------------------------------------
[2007-11-29 12:08:02] jumo at gmx dot de
Description:
------------
the comparison in a special for-loop is not correct.
Reproduce code:
---------------
<?php
for($i = 400.84; $i < 400.88; $i = $i + 0.01) {
echo $i;
echo "<br>";
}
?>
Expected result:
----------------
400.84<br>
400.85<br>
400.86<br>
400.87<br>
Actual result:
--------------
400.84<br>
400.85<br>
400.86<br>
400.87<br>
400.88<br>
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=43447&edit=1