Bug #17726: Serious comparision operator bug using floating point vars
| From: | Snelders at Infocure dot nl | Date: | Wed, 12 Jun 2002 13:53:32 +0000 |
| Subject: | Bug #17726: Serious comparision operator bug using floating point vars | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-10242@lists.php.net to get a copy of this message | ||
From: Snelders@Infocure.nl
Operating system: Redhat kernel 2.2.19-7.0.12
PHP version: 4.2.1
PHP Bug Type: Unknown/Other Function
Bug description: Serious comparision operator bug using floating point vars
--- My code ---
<?
$HRDelta = 1;
function HRValue($Max = 100){
global $HRDelta;
$C = ($Max < 0 ? -1 : 1);
$Order = floor(log10($Max * $C));
$i = 1;
do{
$AxisMax = $i * $HRDelta * pow(10,$Order);
$i++;
}while($Max * $C >= $AxisMax);
echo "Expression: (\$Max * \$C >= \$AxisMax) ? \"true\" :
\"false\")<BR>\n";
echo "Evaluated: (" . $Max * $C . " >= $AxisMax) ? \"true\" :
\"false\")<BR>\n";
echo "Answer: " . (($Max * $C >= $AxisMax) ? "true" : "false") .
"<BR>";
return $C * $AxisMax;
}
echo HRValue(-0.7);
?>
--- My Output ---
Expression: ($Max * $C >= $AxisMax) ? "true" : "false")
Evaluated: (0.7 >= 0.7) ? "true" : "false")
Answer: false
-0.7
--- Description problem ---
The last comparison operator returns false for some unknown reason. I also
checked the variables using var_dump and they seem to be exactly the same
(float(0.7)) according to php.
--- My configure line --
'./configure' '--with-apxs=/usr/sbin/apxs' '--with-mysql=/usr/'
'--with-png-dir=/usr/local/libpng' '--with-gd=/usr/local/gd-1.8.4'
'--with-zlib' '--with-ttf' '--with-freetype-dir=/usr/local/freetype2'
'--with-xml' '--with-oracle=/users/home/oskarsson/OraHome1'
'--with-oci8=/users/home/oskarsson/OraHome1'
--
Edit bug report at http://bugs.php.net/?id=17726&edit=1
--
Fixed in CVS: http://bugs.php.net/fix.php?id=17726&r=fixedcvs
Fixed in release: http://bugs.php.net/fix.php?id=17726&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=17726&r=needtrace
Try newer version: http://bugs.php.net/fix.php?id=17726&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=17726&r=support
Expected behavior: http://bugs.php.net/fix.php?id=17726&r=notwrong
Not enough info: http://bugs.php.net/fix.php?id=17726&r=notenoughinfo
Submitted twice: http://bugs.php.net/fix.php?id=17726&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=17726&r=globals