From: ruben_ruben at yahoo dot com
Operating system: win xp pro sp2
PHP version: 5.1.2
PHP Bug Type: Variables related
Bug description: Iterations with bad precision
Description:
------------
In loops like While and For with increases with point decimal fails the
precision.
Reproduce code:
---------------
$i=71;
$i2 = 82;
$increases = .1;
for($i; $i <= $i2; $i = $i + $increases)
{
echo "$i<br>";
}
//**** or ******
$i=1.5;
$i2 = 2;
$increases = .001;
while($i <= $i2)
{
echo "$i<br>";
$i = $i + $increases;
}
Expected result:
----------------
with
$i=71;
$i2 = 82;
$increases = .1;
it must be:
71
71.1
.
.
.
81.9
82
***************
with
$i=1.5;
$i2 = 2;
$increases = .001;
it must be:
1.5
1.501
1.502
.
.
.
1.999
2
Actual result:
--------------
both with
$i=71;
$i2 = 82;
generates:
71
71.1
.
.
79.8
79.899999999999
79.999999999999
.
.
81.899999999999
81.999999999999
***************
both with
$i=1.5;
$i2 = 2;
$increases = .001;
generates:
1.5
1.501
1.502
.
.
1.954
1.9549999999999
1.9559999999999
.
.
1.9989999999999
1.9999999999999
--
Edit bug report at http://bugs.php.net/?id=37202&edit=1
--
Try a CVS snapshot (PHP 4.4):
http://bugs.php.net/fix.php?id=37202&r=trysnapshot44
Try a CVS snapshot (PHP 5.1):
http://bugs.php.net/fix.php?id=37202&r=trysnapshot51
Try a CVS snapshot (PHP 6.0):
http://bugs.php.net/fix.php?id=37202&r=trysnapshot60
Fixed in CVS: http://bugs.php.net/fix.php?id=37202&r=fixedcvs
Fixed in release:
http://bugs.php.net/fix.php?id=37202&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=37202&r=needtrace
Need Reproduce Script: http://bugs.php.net/fix.php?id=37202&r=needscript
Try newer version: http://bugs.php.net/fix.php?id=37202&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=37202&r=support
Expected behavior: http://bugs.php.net/fix.php?id=37202&r=notwrong
Not enough info:
http://bugs.php.net/fix.php?id=37202&r=notenoughinfo
Submitted twice:
http://bugs.php.net/fix.php?id=37202&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=37202&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=37202&r=php3
Daylight Savings: http://bugs.php.net/fix.php?id=37202&r=dst
IIS Stability: http://bugs.php.net/fix.php?id=37202&r=isapi
Install GNU Sed: http://bugs.php.net/fix.php?id=37202&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=37202&r=float
No Zend Extensions: http://bugs.php.net/fix.php?id=37202&r=nozend
MySQL Configuration Error: http://bugs.php.net/fix.php?id=37202&r=mysqlcfg