note 110825 deleted from function.round by googleguy
| From: | googleguy@php.net | Date: | Wed, 12 Dec 2012 04:03:04 +0000 |
| Subject: | note 110825 deleted from function.round by googleguy | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-192483@lists.php.net to get a copy of this message | ||
Note Submitter: verdy_p
----
Examples 3 in documentation are wrong.
All the 4 rounding modes will return the same values when the fractional part is not exactly 0.5.
The examples 3 are making a confusion with other IEEE rounding modes not supported:
- PHP_ROUND_HALF_ZERO
- PHP_ROUND_HALF_INFINITY
(those modes will not balance halves between up and down roundings, in periods of length 2, but will
use a period of 1; but they will be symetric around zero).
Other useful IEEE rounding modes would be:
- PHP_ROUND_UP (equivalent to using ceil() after scaling down, and then scaling up the result)
- PHP_ROUND_DOWN (equivalent to using floor() after scaling down, and then scaling down the result)
(these modes are NOT symetric around zero and NOT balanced)
- PHP_ROUND_UNIT_TO_ZERO (uses floor() if value is positive, ceil() otherwise)
- PHP_ROUND_UNIT_TO_INFINITY (uses ceil() if value is positive, floor() otherwise)
(these modes are symetric around zero, but still NOT balanced; the period of rounding differences
is 1, rounding differences have the same sign as the input for PHP_ROUND_UNIT_TO_ZERO, or the
opposite sign of the input for PHP_ROUND_UNIT_TO_INFINITY)
- PHP_ROUND_UNIT_TO_EVEN
- PHP_ROUND_UNIT_TO_ODD
(these rare modes are symetric around zero, and are balanced ; the result least significant digit
will be even or odd accordingly, but with an absolute roundiing difference always lower than 1; if
there are no other digits after the least significant one kept, that digit will be kept unchanged
even if it's not even or odd as indicated; the period of rounding differences is 2;rounding
differences are in linear subranges between -1 and 1, passing though 0 on that period, separated
from the next period by a discontinuous point with rounding difference 0).
The default rounding mode PHP_ROUND_HALF_TO_EVEN is recommanded to minimize the total of rounding
errors, with a period of 1, in a perfectly balanced way.