ID: 49418 Updated by: [email protected] Reported By: ilies dot radu at gmail dot com -Status: Open +Status: Bogus Bug Type: Variables related Operating System: MacOSX, NetBSD, Linux PHP Version: 5.2.10 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. If you would like to know more about "floats" and what IEEE 754 is, read this: http://docs.sun.com/source/806-3568/ncg_goldberg.html Thank you for your interest in PHP. Previous Comments: ------------------------------------------------------------------------ [2009-08-30 17:29:54] ilies dot radu at gmail dot com Description: ------------ ---- Example #1 / FAIL (This should NOT FAIL, but it does) !!!!!!!!!!! $a=1.3333; $b=1.6666; $c=2.9999; $d=($a+$b); if($d != $c) { echo 'php have a serious bug ...'; } else { echo 'OK ...'; } //end if else // notice that currently I use number_format($d, 4, '.', '') to fix this, but is abnormal ! ---- ---- Example #2 / OK $a=4.3333; $b=4.6666; $c=8.9999; $d=($a+$b); if($d != $c) { echo 'php have a serious bug ...'; } else { echo 'OK ...'; } //end if // this seems that not raise that bug, ... hmmm ... very strange ---- I tested it on: PHP 4.4.9 PHP 5.2.9 PHP 5.2.10 PHP 4.4.4 (bundled with Zend Studio) It appears that all fail at Example #1 and should not ... !!! If you release a patch, please also patch the 4.4.9 version. Reproduce code: --------------- $a=1.3333; $b=1.6666; $c=2.9999; $d=($a+$b); if($d != $c) { echo 'php have a serious bug ...'; } else { echo 'OK ...'; } //end if else Expected result: ---------------- the output should be 'OK ...' but is not ! Actual result: -------------- 'php have a serious bug ...' ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=49418&edit=1
