#28515 [Opn->Bgs]: A simple comparision operation FAILS!

From: Date: Tue, 25 May 2004 09:18:31 +0000
Subject: #28515 [Opn->Bgs]: A simple comparision operation FAILS!
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-59965@lists.php.net to get a copy of this message
ID: 28515 Updated by: helly@php.net Reported By: andrew dot panin at nvkz dot net -Status: Open +Status: Bogus Bug Type: Output Control Operating System: Windows 98 SE PHP Version: Irrelevant New Comment: 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: marcus@frodo 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. Previous Comments: ------------------------------------------------------------------------ [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

« previous php.bugs (#59965) next »