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
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
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

Add a Patch

Pull Requests

Add a Pull Request

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-2024 The PHP Group
All rights reserved.
Last updated: Thu May 16 09:01:32 2024 UTC