php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #22738 Imcrementing by decimals leads to partial failure
Submitted: 2003-03-16 16:00 UTC Modified: 2003-03-16 16:29 UTC
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: sunofman at sympatico dot ca Assigned:
Status: Not a bug Package: Variables related
PHP Version: 4.3.1 OS: Windows XP
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: sunofman at sympatico dot ca
New email:
PHP Version: OS:

 

 [2003-03-16 16:00 UTC] sunofman at sympatico dot ca
$x = 0.0;
$y = 0.7;

do {
   if ($x == $y) {
      PRINT "found<br>";
   } else {
      PRINT "not found<br>";
   }
   $x += 0.1;
} while($x <= 1.0);

When $y is 0.0 to 0.7 everything works fine and it will find the match...if you make $y = 0.8 or higher it will fail to find the match.

I'm using the basic install of 4.3.1 (it happens in older versions as well)

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2003-03-16 16:29 UTC] sniper@php.net
<?php
ini_set("precision",18);

$x = 0.0;
$y = 0.8;

do {
   if ($x == $y) {
      PRINT "found\n";
   } else {
      PRINT "not found\n";
   }
   $x += 0.1;
echo $x;
} while($x <= 1.0);

?>

Try this and you'll see why..
And then read this to know why that happens:

http://www.php.net/manual/en/language.types.float.php


 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Fri Jul 04 09:01:34 2025 UTC