From:             ibexris at gmail dot com
Operating system: Fedora Core
PHP version:      5.1.4
PHP Bug Type:     Unknown/Other Function
Bug description:  Oddness and errors with float precision

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 bug report at http://bugs.php.net/?id=38321&edit=1
-- 
Try a CVS snapshot (PHP 4.4): 
http://bugs.php.net/fix.php?id=38321&r=trysnapshot44
Try a CVS snapshot (PHP 5.2): 
http://bugs.php.net/fix.php?id=38321&r=trysnapshot52
Try a CVS snapshot (PHP 6.0): 
http://bugs.php.net/fix.php?id=38321&r=trysnapshot60
Fixed in CVS:                 http://bugs.php.net/fix.php?id=38321&r=fixedcvs
Fixed in release:             
http://bugs.php.net/fix.php?id=38321&r=alreadyfixed
Need backtrace:               http://bugs.php.net/fix.php?id=38321&r=needtrace
Need Reproduce Script:        http://bugs.php.net/fix.php?id=38321&r=needscript
Try newer version:            http://bugs.php.net/fix.php?id=38321&r=oldversion
Not developer issue:          http://bugs.php.net/fix.php?id=38321&r=support
Expected behavior:            http://bugs.php.net/fix.php?id=38321&r=notwrong
Not enough info:              
http://bugs.php.net/fix.php?id=38321&r=notenoughinfo
Submitted twice:              
http://bugs.php.net/fix.php?id=38321&r=submittedtwice
register_globals:             http://bugs.php.net/fix.php?id=38321&r=globals
PHP 3 support discontinued:   http://bugs.php.net/fix.php?id=38321&r=php3
Daylight Savings:             http://bugs.php.net/fix.php?id=38321&r=dst
IIS Stability:                http://bugs.php.net/fix.php?id=38321&r=isapi
Install GNU Sed:              http://bugs.php.net/fix.php?id=38321&r=gnused
Floating point limitations:   http://bugs.php.net/fix.php?id=38321&r=float
No Zend Extensions:           http://bugs.php.net/fix.php?id=38321&r=nozend
MySQL Configuration Error:    http://bugs.php.net/fix.php?id=38321&r=mysqlcfg

Reply via email to