Edit report at https://bugs.php.net/bug.php?id=54334&edit=1

 ID:                 54334
 Updated by:         yohg...@php.net
 Reported by:        for-bugs at hnw dot jp
 Summary:            The behavior for rounding to small precision was
                     changed and is against RFC
-Status:             Open
+Status:             Closed
 Type:               Bug
 Package:            Math related
 Operating System:   Intel Linux and Intel MacOSX
 PHP Version:        5.3.6
-Assigned To:        
+Assigned To:        yohgaki
 Block user comment: N
 Private report:     N

 New Comment:

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


Previous Comments:
------------------------------------------------------------------------
[2011-04-03 16:14:51] 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.

------------------------------------------------------------------------
[2011-03-21 12:21:56] 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)


------------------------------------------------------------------------



-- 
Edit this bug report at https://bugs.php.net/bug.php?id=54334&edit=1

Reply via email to