Bug #17984: comparison of float values does not always work.

From: Date: Tue, 25 Jun 2002 22:53:43 +0000
Subject: Bug #17984: comparison of float values does not always work.
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-12086@lists.php.net to get a copy of this message
From: szii@sziisoft.com Operating system: Linux Mandrake PHP version: 4.2.1 PHP Bug Type: Unknown/Other Function Bug description: comparison of float values does not always work. Comparison of float values does not always work. ./configure --with-mysql=/usr/local/mysql --with-xml --with-apache=../../apache/apache_1.3.26/ Test code follows: <?php $a = 332.06; $b = 45.11 + 134.38 + 85.35 + 67.22; echo "output\n"; var_dump($a); var_dump($b); print("Total = $a\n"); print("Production = $b\n"); if($a != $b) { print("Totals do not Match!\n"); } else { print("Totals are in Balance\n"); } if($a !== $b) { print("Totals do not Match!\n"); } else { print("Totals are in Balance\n"); } if($a <> $b) { print("Totals do not Match!\n"); } else { print("Totals are in Balance\n"); } if($a > $b) { print("a is greater!\n"); } else { print("b is greater!\n"); } settype($a,"string"); settype($b,"string"); if ($a != $b) echo "String compare failed!\n\n"; settype($a,"float"); settype($b,"float"); if ($a != $b) echo "recast to float compare failed!\n\n"; echo "end output\n"; ?> ----------------------------- output float(332.06) float(332.06) Total = 332.06 Production = 332.06 Totals do not Match! Totals do not Match! Totals do not Match! b is greater! end output ------------------------------ Summary: float compare fails (!=) float compare fails (<>) float compare fails (!==) "b" is somehow greater than "a" cast to string, compare okay. recast to float, compare okay. -Mike -- Edit bug report at http://bugs.php.net/?id=17984&edit=1 -- Fixed in CVS: http://bugs.php.net/fix.php?id=17984&r=fixedcvs Fixed in release: http://bugs.php.net/fix.php?id=17984&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=17984&r=needtrace Try newer version: http://bugs.php.net/fix.php?id=17984&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=17984&r=support Expected behavior: http://bugs.php.net/fix.php?id=17984&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=17984&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=17984&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=17984&r=globals

« previous php.bugs (#12086) next »