|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #54334 The behavior for rounding to small precision was changed and is against RFC
Submitted: 2011-03-21 12:21 UTC Modified: 2013-06-28 09:16 UTC
Avg. Score:2.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: for-bugs at hnw dot jp Assigned: yohgaki (profile)
Status: Closed Package: Math related
PHP Version: 5.3.6 OS: Intel Linux and Intel MacOSX
Private report: No CVE-ID: None
 [2011-03-21 12:21 UTC] for-bugs at hnw dot jp
The behavior of function round() was changed with revision 301991. So when a small number is rounded to small precision, round() of PHP5.3.4-5.3.6 returns different value from PHP5.3.0-5.3.3. Additionally, the current behavior is different from referred RFC(*1). I suppose it is not intended change.

For example, test script returns "float(4.0E-60)" for PHP 5.3.0-5.3.3 and PHP 5.2.17. However, PHP 5.3.4-5.3.6 shows "float(3.0E-60)".

This behavior changing was affected with revision 301991(*2) for fixing Bug #52550(*3). However, I think this fix was useless.

Bug #52550 reports probability for integer overflow/underflow. However, the C function php_intlog10abs() returns integer between -324 and 308 because of property for IEEE754 64bit floating point numbers, so overflow/underflow never occur for this part.


Test script:
var_dump(round(3.5e-60, 60));

Expected result:

Actual result:


php-5.3.6-rounding-patch (last revision 2011-03-21 11:22 UTC by for-bugs at hnw dot jp)

Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2011-03-21 22:44 UTC]
-Summary: The behavior for rounding to small presicion was changed and is against RFC +Summary: The behavior for rounding to small precision was changed and is against RFC
 [2011-04-03 16:14 UTC] for-bugs at hnw dot jp
I found another example.


PHP 5.3.0-5.3.3 returns float(0). However, PHP 5.3.4-5.3.6 returns float(1). Of cource, this number 0.499999999999999 is different from 0.5 within IEEE754 double precision.

It seems to be BC break.
 [2013-06-28 09:16 UTC]
-Status: Open +Status: Closed -Assigned To: +Assigned To: yohgaki
 [2013-06-28 09:16 UTC]
Thank you for your bug report. This issue has already been fixed
in the latest released version of PHP, which you can download at

It seems this is fixed. Tested by 5.5.1-dev/5.4.16
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Apr 23 20:01:29 2024 UTC