php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #18682 for loop with floats causes roundup problem
Submitted: 2002-07-31 16:36 UTC Modified: 2002-08-02 05:01 UTC
From: webmaster at hackquest dot com Assigned:
Status: Not a bug Package: Scripting Engine problem
PHP Version: 4.2.2, 4.3.0-dev OS: Linux, Tru64
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: webmaster at hackquest dot com
New email:
PHP Version: OS:

 

 [2002-07-31 16:36 UTC] webmaster at hackquest dot com
for ($i = 1.0; $i >= 0; $i -= 0.05)

Will produce the line:

..
..
0.1
0.05


The 0 is missing, obviously its rounded to below zero somehow, and then gets discarded.

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2002-07-31 17:51 UTC] kalowsky@php.net
Works for me on OSX just fine:

for ($i = 1.0; $i >= 0; $i -=  0.05)
{
        print "my i value is '$i'\n";
}
print "end of script\n";

please post a full sample script if this continues.
 [2002-08-01 14:13 UTC] nohn@php.net
Reopened this bug. My understanding of this that it counts to (inclusive) 0.:

Extendet the script like this:

<?php
for ($i = 1.0; $i >= 0; $i -=  0.05)
{
        print "my i value is '$i'\n";
}
print "end of script\n";

for ($i = 10; $i >= 0; $i -= 1)
{
        print "my i value is '$i'\n";
}
print "end of script\n";
?>

the result is:

bndiap56> php4-200207301200_install_alpha_tru64/bin/php php-bugs/18682.php
Unaligned access pid=146367 <php> va=0x14005e3ec pc=0x1201c6910 ra=0x1201c6904 inst=0xb4010000
my i value is '1'
my i value is '0.95'
my i value is '0.9'
my i value is '0.85'
my i value is '0.8'
my i value is '0.75'
my i value is '0.7'
my i value is '0.65'
my i value is '0.6'
my i value is '0.55'
my i value is '0.5'
my i value is '0.45'
my i value is '0.4'
my i value is '0.35'
my i value is '0.3'
my i value is '0.25'
my i value is '0.2'
my i value is '0.15'
my i value is '0.1'
my i value is '0.05'
end of script
my i value is '10'
my i value is '9'
my i value is '8'
my i value is '7'
my i value is '6'
my i value is '5'
my i value is '4'
my i value is '3'
my i value is '2'
my i value is '1'
my i value is '0'
end of script


 [2002-08-02 05:01 UTC] hholzgra@php.net
never compare floats for equality. period.
see http://php.net/float or your favourite
computer science book for why not to do so

 
PHP Copyright © 2001-2026 The PHP Group
All rights reserved.
Last updated: Wed Oct 07 13:00:02 2026 UTC