php.net |  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
Votes:1
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
Description:
------------
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.

*1 http://wiki.php.net/rfc/rounding
*2 http://svn.php.net/viewvc/php/php-src/branches/PHP_5_3/ext/standard/math.c?r1=301991&r2=301990&pathrev=301991
*3 http://bugs.php.net/bug.php?id=52550

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

Expected result:
----------------
float(4.0E-60)

Actual result:
--------------
float(3.0E-60)

Patches

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

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2011-03-21 22:44 UTC] felipe@php.net
-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
var_dump(round(0.499999999999999));

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] yohgaki@php.net
-Status: Open +Status: Closed -Assigned To: +Assigned To: yohgaki
 [2013-06-28 09:16 UTC] yohgaki@php.net
Thank you for your bug report. This issue has already been fixed
in the latest released version of PHP, which you can download at 
http://www.php.net/downloads.php

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: Wed Dec 11 19:01:27 2024 UTC