Bug #67201 [NEW]: Simple comparison of two floats gives incorrect result

From: Date: Sun, 04 May 2014 07:42:33 +0000
Subject: Bug #67201 [NEW]: Simple comparison of two floats gives incorrect result
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-185616@lists.php.net to get a copy of this message
From: ashley at ashleydawson dot co dot uk Operating system: Ubuntu 13.10 PHP version: 5.5.12 Package: *General Issues Bug Type: Bug Bug description:Simple comparison of two floats gives incorrect result Description: ------------ The exact PHP version is PHP 5.5.3-1ubuntu2.3 (I was unable to find this in the version list). Here is an example of the issue: if (((float)8568.2 + (float)-614) == (float)7954.2) { echo 'Match'; } else { echo 'No Match'; } The result of this comparison is always false, resulting in "No Match". The expected result is true or "Match" as 8568.2 + -614 = 7954.2 Example run via PHP HTTP Server. PHP Modules: [PHP Modules] bcmath bz2 calendar Core ctype curl date dba dom ereg exif fileinfo filter ftp gettext hash iconv intl json libxml mbstring mhash mongo mysql mysqli openssl pcntl pcre PDO pdo_mysql Phar posix readline Reflection session shmop SimpleXML soap sockets SPL standard sysvmsg sysvsem sysvshm tokenizer wddx xml xmlreader xmlwriter Zend OPcache zip zlib [Zend Modules] Zend OPcache Test script: --------------- if (((float)8568.2 + (float)-614) == (float)7954.2) { echo 'Match'; } else { echo 'No Match'; } Expected result: ---------------- echo 'Match'; Actual result: -------------- echo 'No Match'; -- Edit bug report at https://bugs.php.net/bug.php?id=67201&edit=1 -- Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=67201&r=trysnapshot54 Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=67201&r=trysnapshot55 Try a snapshot (trunk): https://bugs.php.net/fix.php?id=67201&r=trysnapshottrunk Fixed in SVN: https://bugs.php.net/fix.php?id=67201&r=fixed Fixed in release: https://bugs.php.net/fix.php?id=67201&r=alreadyfixed Need backtrace: https://bugs.php.net/fix.php?id=67201&r=needtrace Need Reproduce Script: https://bugs.php.net/fix.php?id=67201&r=needscript Try newer version: https://bugs.php.net/fix.php?id=67201&r=oldversion Not developer issue: https://bugs.php.net/fix.php?id=67201&r=support Expected behavior: https://bugs.php.net/fix.php?id=67201&r=notwrong Not enough info: https://bugs.php.net/fix.php?id=67201&r=notenoughinfo Submitted twice: https://bugs.php.net/fix.php?id=67201&r=submittedtwice register_globals: https://bugs.php.net/fix.php?id=67201&r=globals PHP 4 support discontinued: https://bugs.php.net/fix.php?id=67201&r=php4 Daylight Savings: https://bugs.php.net/fix.php?id=67201&r=dst IIS Stability: https://bugs.php.net/fix.php?id=67201&r=isapi Install GNU Sed: https://bugs.php.net/fix.php?id=67201&r=gnused Floating point limitations: https://bugs.php.net/fix.php?id=67201&r=float No Zend Extensions: https://bugs.php.net/fix.php?id=67201&r=nozend MySQL Configuration Error: https://bugs.php.net/fix.php?id=67201&r=mysqlcfg

« previous php.bugs (#185616) next »