|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2006-08-04 07:54 UTC] tony2001@php.net
[2006-08-04 08:13 UTC] ibexris at gmail dot com
[2006-08-04 20:34 UTC] ibexris at gmail dot com
[2006-08-04 21:25 UTC] tony2001@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Fri Dec 05 22:00:02 2025 UTC |
Description: ------------ I just got bitten by a float precision problem and ceil() that affects several versions of php and definitely doesn't behave in a consistent manner. I've tested this on linux (x86 and x86_64) and OSX with the same results, so I don't believe that it's dependent on the system libraries. You'll also notice that the problem goes away by rounding the results below PHP's 14 digit float precision, and that it only affects certain numbers (which made this rather hard to track down). Reproduce code: --------------- <?php $x = 1.2 * 100; echo "$x\n", ceil($x), "\n"; $x = 1.1 * 100; echo "$x\n", ceil($x), "\n", ceil(round($x, 13)), "\n", ceil(round($x, 14)), "\n"; ?> Expected result: ---------------- 120 120 110 110 110 110 Actual result: -------------- 120 120 110 111 110 111