[PHP-BUG] Bug #74925 [NEW]: Mismatching floating values
[email protected] ("tuepp at gmx dot de") Fri, 14 Jul 2017 14:42:12 GMT
| Newsgroups | php.standards |
|---|---|
| Message-ID | <[email protected]> |
From: tuepp at gmx dot de
Operating system: Windows
PHP version: 7.0.21
Package: PHP Language Specification
Bug Type: Bug
Bug description:Mismatching floating values
Description:
------------
Floating number comparison fails for numbers that have to be rounded
internal.
This bug may be over 10 years old. I've reported it 5 years ago and it
is still not fixed. Now I have an example with one instead of 3 lines of
code what might be more shoking. I've documented this bug in my final
exam 6 years ago and it feeled like I got some extra points for it - so
thank you. But now it's really time to fix it! I'm not sure if I'll
report it a third time in another 5 years... So go, get it!
Test script:
---------------
<?php
echo (54.83 + 0.01 == 54.84) ? 'ok' : 'fail'; //fail
echo "<br>\n";
echo ((3 * 202.3) == 606.9) ? 'ok' : 'fail'; //fail
echo "<br>\n";
for($v = -1; $v < 0; $v += 0.2){
echo "$v; "; // -1; -0.8; -0.6; -0.4; -0.2; -5.5511151231258E-17;
}
Expected result:
----------------
ok
ok
-1; -0.8; -0.6; -0.4; -0.2
Actual result:
--------------
fail
fail
-1; -0.8; -0.6; -0.4; -0.2; -5.5511151231258E-17;
--
Edit bug report at https://bugs.php.net/bug.php?id=74925&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=74925&r=trysnapshot54
Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=74925&r=trysnapshot55
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=74925&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=74925&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=74925&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=74925&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=74925&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=74925&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=74925&r=support
Expected behavior: https://bugs.php.net/fix.php?id=74925&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=74925&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=74925&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=74925&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=74925&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=74925&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=74925&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=74925&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=74925&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=74925&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=74925&r=mysqlcfg