note 110825 added to function.round

From: Date: Wed, 12 Dec 2012 03:35:27 +0000
Subject: note 110825 added to function.round
Groups: php.notes 
Request: Send a blank email to php-notes+get-192482@lists.php.net to get a copy of this message
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. ---- Server IP: 69.147.83.199 Probable Submitter: 72.52.91.2 (proxied: 89.2.191.39) ---- Manual Page -- http://php.net/manual/en/function.round.php Edit -- https://master.php.net/note/edit/110825 Del: integrated -- https://master.php.net/note/delete/110825/integrated Del: useless -- https://master.php.net/note/delete/110825/useless Del: bad code -- https://master.php.net/note/delete/110825/bad+code Del: spam -- https://master.php.net/note/delete/110825/spam Del: non-english -- https://master.php.net/note/delete/110825/non-english Del: in docs -- https://master.php.net/note/delete/110825/in+docs Del: other reasons-- https://master.php.net/note/delete/110825 Reject -- https://master.php.net/note/reject/110825 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#192482) next »