Bug #78294 [NEW]: Unexpected lose equality result
| From: | iuli dot butuc at yahoo dot com | Date: | Mon, 15 Jul 2019 12:45:39 +0000 |
| Subject: | Bug #78294 [NEW]: Unexpected lose equality result | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-221782@lists.php.net to get a copy of this message | ||
From: iuli dot butuc at yahoo dot com
Operating system: Windows 10
PHP version: Irrelevant
Package: *Math Functions
Bug Type: Bug
Bug description:Unexpected lose equality result
Description:
------------
Tested on php versions >= 5.6.
The lose equality result for '201905025815311.33' ==
'201905025815311.34' is true for some reason i cannot identify. Needless
to say using using the === operator fixes the issue.
But the result for me is strange. Those strings are probably stored as
floats in memory because they have a perfect valid float format. But the
float comparison for 201905025815311.33 == 201905025815311.34 fails as
well(evaluates to true).
Even if the numbers are rounded, it does not explain how can give the
right result for 201905025815311.33 == 201905025815311.32 which should
have the same "rounding" rules as 201905025815311.33 ==
201905025815311.34. Maybe the 1.33 ending is the problem, but does not
ring a bell to me from a mathematical perspective.
Dumping the PHP_FLOAT_MAX constant on php versions that have it (7.2+)
suggest that php should not have any trouble working with these numbers.
Test script:
---------------
var_dump('201905025815311.33' == '201905025815311.34');
var_dump('201905025815311.33' == '201905025815311.32');
var_dump(201905025815311.33 == 201905025815311.34);
var_dump(201905025815311.33 == 201905025815311.32);
var_dump(201905025815311.32);
var_dump(201905025815311.33);
var_dump(201905025815311.34);
var_dump(PHP_FLOAT_MAX);
Expected result:
----------------
bool(false)
bool(false)
bool(false)
bool(false)
float(2.0190502581531E+14)
float(2.0190502581531E+14)
float(2.0190502581531E+14)
float(1.7976931348623E+308)
Actual result:
--------------
bool(true)
bool(false)
bool(true)
bool(false)
float(2.0190502581531E+14)
float(2.0190502581531E+14)
float(2.0190502581531E+14)
float(1.7976931348623E+308)
--
Edit bug report at https://bugs.php.net/bug.php?id=78294&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=78294&r=trysnapshot54
Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=78294&r=trysnapshot55
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=78294&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=78294&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=78294&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=78294&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=78294&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=78294&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=78294&r=support
Expected behavior: https://bugs.php.net/fix.php?id=78294&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=78294&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=78294&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=78294&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=78294&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=78294&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=78294&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=78294&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=78294&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=78294&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=78294&r=mysqlcfg