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

 ID:                 54334
 Comment by:         for-bugs at hnw dot jp
 Reported by:        for-bugs at hnw dot jp
 Summary:            The behavior for rounding to small precision was
                     changed and is against RFC
 Status:             Open
 Type:               Bug
 Package:            Math related
 Operating System:   Intel Linux and Intel MacOSX
 PHP Version:        5.3.6
 Block user comment: N
 Private report:     N

 New Comment:

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.


Previous Comments:
------------------------------------------------------------------------
[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 http://bugs.php.net/bug.php?id=54334&edit=1

Reply via email to