|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2019-07-15 12:54 UTC] daverandom@php.net
-Status: Open
+Status: Not a bug
[2019-07-15 12:54 UTC] daverandom@php.net
[2019-07-15 12:59 UTC] danack@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Fri Dec 19 17:00:01 2025 UTC |
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)