ID: 28515
Comment by: lars_stegelitz at col dot wunderman dot com
Reported By: andrew dot panin at nvkz dot net
Status: Bogus
Bug Type: Output Control
Operating System: Windows 98 SE
PHP Version: Irrelevant
New Comment:
This happens on 4.3.7dev too, but...
It seems to be a representation problem of 'print $d;'.
If you modify your if-clause the following way, it shows what I mean:
if ($d > 1) { print "E"; }
Now, the 'E' is printed ! It seems, that the value of $d is NOT exactly
one :
if (((int)$d) == 1) { print "E"; }
Whent $d is converted to integer, the 'E' is printed also.
Use number_format($d, 20); to see an internal value representation of
$d (it reads 1.00000000000000044409).
When working with floating point values, never ever test on equality!
Previous Comments:
------------------------------------------------------------------------
[2004-05-25 11:18:29] [EMAIL PROTECTED]
Floating point values have a limited precision. Hence a value might
not have the same string representation after any processing. That also
includes writing a floating point value in your script and directly
printing it without any mathematical operations.
Thank you for your interest in PHP.
Look at this:
[EMAIL PROTECTED] php-cvs $ php -r \'var_dump(3*(7/3 - 2) == 1);\'
bool(false)
(7/3-2) == 1/3 but a float can never be 1/3 exact.
E.g. floats cannot handle fractions.
------------------------------------------------------------------------
[2004-05-25 06:20:54] andrew dot panin at nvkz dot net
Description:
------------
Just look into the code!
Reproduce code:
---------------
<?php
$in="1234567";
$d = 0;
$d = 3*abs(strlen($in)/3 - floor(strlen($in)/3));
print $d;
//here $d=1, as it PHP print
if ($d == 1) { print "E"; }
//The "E" is NOT prints!
die();
?>
Expected result:
----------------
That the "E" will be shown.
Actual result:
--------------
NOTHING!!!
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=28515&edit=1