#19398 [Opn]: mathmatical errors, especially after string conversions
| From: | hholzgra@php.net | Date: | Tue, 17 Sep 2002 09:43:40 +0000 |
| Subject: | #19398 [Opn]: mathmatical errors, especially after string conversions | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-19524@lists.php.net to get a copy of this message | ||
ID: 19398
Updated by: hholzgra@php.net
Reported By: jeffb@umci.com
Status: Open
Bug Type: Scripting Engine problem
Operating System: Redhat 7.3
PHP Version: 4.2.2
New Comment:
Never compare floats for equalness!
Thats like comparing two pieces of rope
for exactly equal length -> you won't
ever find an equal pair
see for example the note on http://www.php.net/language.types.float
Previous Comments:
------------------------------------------------------------------------
[2002-09-13 20:03:14] jeffb@umci.com
The script below produces a lot of output on two of
our systems. One a 6 cpu ppro, the other a single
cpu duron 950. Both boxes run redhat 7.3. One runs the
php that came with redhat 7.3, the 6 cpu box runs php
4.2.2 that we compiled ourselves to add more options.
For sample output of this script, with a phpinfo() call
appended to it, go to:
http://www.umci.com/testcode.phtml
<?
$start=0.01;
while ($start <= 10) {
// Removing the quotes from test's assignment will eliminate the
// errors unless you uncomment the ++/-- down a fiew lines.
$test="$start";
$test2=$start;
/////////////////////////////////////////////////////////////////
// Uncommenting these two lines accentuates the problem a bit...
/////////////////////////////////////////////////////////////////
//$test++;
//$test--;
if ($test!=$test2)
echo "Comparison Result: \"$test\" != \"$test2\" ----- Shouldn't this
be true?<br>";
$start = $start + 0.01;
}
?>
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=19398&edit=1