ID: 38321 User updated by: ibexris at gmail dot com Reported By: ibexris at gmail dot com -Status: Bogus +Status: Open Bug Type: Unknown/Other Function Operating System: Fedora Core PHP Version: 5.1.4 New Comment:
Reopening this in case no one sees the comments for "bogus" bugs. Close it again if you want, but I still consider it to be a valid bug -- the false information provided resulted in numerous financial errors in my code. Previous Comments: ------------------------------------------------------------------------ [2006-08-04 08:13:38] ibexris at gmail dot com My point was that if php displays the value as 110 when I print it out, it *should* be 110 when I run a function like ceil() on it. If php thinks the value is 110.00000000000001, then that's what it should be printing when I echo. I don't care so much that floats are inaccurate (I already knew that), but that php is giving me false information (saying 110 when the actual value is 110.00000000000001). ------------------------------------------------------------------------ [2006-08-04 07:54:07] [EMAIL PROTECTED] Floating point values have a limited precision. Hence a value might not have the same string representation after any processing. That also includes writing a floating point value in your script and directly printing it without any mathematical operations. If you would like to know more about "floats" and what IEEE 754 is read this: http://docs.sun.com/source/806-3568/ncg_goldberg.html Thank you for your interest in PHP. ------------------------------------------------------------------------ [2006-08-04 00:35:06] ibexris at gmail dot com 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 ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=38321&edit=1