|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2017-07-14 14:49 UTC] krakjoe@php.net
-Status: Open
+Status: Not a bug
[2017-07-14 14:49 UTC] krakjoe@php.net
[2017-07-17 16:41 UTC] tuepp at gmx dot de
[2017-07-17 16:47 UTC] rasmus@php.net
[2017-07-18 18:28 UTC] neclimdul at gmail dot com
|
|||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sat Oct 25 01:00:01 2025 UTC |
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;