#22738 [Opn->Bgs]: Imcrementing by decimals leads to partial failure

From: Date: Sun, 16 Mar 2003 22:29:54 +0000
Subject: #22738 [Opn->Bgs]: Imcrementing by decimals leads to partial failure
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-35716@lists.php.net to get a copy of this message
ID: 22738 Updated by: sniper@php.net Reported By: sunofman at sympatico dot ca -Status: Open +Status: Bogus Bug Type: Variables related Operating System: Windows XP PHP Version: 4.3.1 New Comment: <?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 Previous Comments: ------------------------------------------------------------------------ [2003-03-16 16:00:59] 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) ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=22738&edit=1

« previous php.bugs (#35716) next »