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
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem:
43 - 29 = ?
Subscribe to this entry?

 
 [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-2024 The PHP Group
All rights reserved.
Last updated: Thu Oct 31 23:01:28 2024 UTC