#38321 [Opn->Bgs]: Oddness and errors with float precision
| From: | tony2001@php.net | Date: | Fri, 04 Aug 2006 07:54:07 +0000 |
| Subject: | #38321 [Opn->Bgs]: Oddness and errors with float precision | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-100322@lists.php.net to get a copy of this message | ||
ID: 38321
Updated by: tony2001@php.net
Reported By: ibexris at gmail dot com
-Status: Open
+Status: Bogus
Bug Type: Unknown/Other Function
Operating System: Fedora Core
PHP Version: 5.1.4
New Comment:
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.
Previous Comments:
------------------------------------------------------------------------
[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