|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2008-12-02 05:44 UTC] magicaltux@php.net
[2008-12-02 05:47 UTC] magicaltux@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Fri Dec 05 21:00:01 2025 UTC |
Description: ------------ My PHP version is PHP 5.2.5 (cli): This wasn't listed in the select. It seems that a for loop that deals with floats has bad logic when evaluating equivalence against another number (in my situation an int). Reproduce code: --------------- $values = array(); for ($val = 0; $val <= 2; $val = $val + .1) { $values[] = $val; } print_r($values); Expected result: ---------------- Array ( [0] => 0 [1] => 0.1 [2] => 0.2 [3] => 0.3 [4] => 0.4 [5] => 0.5 [6] => 0.6 [7] => 0.7 [8] => 0.8 [9] => 0.9 [10] => 1 [11] => 1.1 [12] => 1.2 [13] => 1.3 [14] => 1.4 [15] => 1.5 [16] => 1.6 [17] => 1.7 [18] => 1.8 [19] => 1.9 [20] => 2 ) Actual result: -------------- Array ( [0] => 0 [1] => 0.1 [2] => 0.2 [3] => 0.3 [4] => 0.4 [5] => 0.5 [6] => 0.6 [7] => 0.7 [8] => 0.8 [9] => 0.9 [10] => 1 [11] => 1.1 [12] => 1.2 [13] => 1.3 [14] => 1.4 [15] => 1.5 [16] => 1.6 [17] => 1.7 [18] => 1.8 [19] => 1.9 )