ID:               37202
 Updated by:       [EMAIL PROTECTED]
 Reported By:      ruben_ruben at yahoo dot com
-Status:           Open
+Status:           Bogus
 Bug Type:         Variables related
 Operating System: win xp pro sp2
 PHP Version:      5.1.2
 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:
------------------------------------------------------------------------

[2006-04-25 20:42:21] ruben_ruben at yahoo dot com

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 this bug report at http://bugs.php.net/?id=37202&edit=1

Reply via email to