Forums
New posts
Search forums
Members
Current visitors
Log in
Register
What's new
Search
Search
Search titles only
By:
New posts
Search forums
Menu
Log in
Register
Install the app
Install
Forums
Archive
Archive
Python
Rounding a number to nearest even
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
[QUOTE="Lie, post: 3534230"] That old-school rounding method you're taught is based on a wrong assumption of the nature of number. In the past, rounding algorithm is based on this: Original => (RoundUp(u|d|n), RoundNearestEven(u|d|n) .... 1.0 => 1(n), 1(n) 1.1 => 1(d), 1(d) 1.2 => 1(d), 1(d) 1.3 => 1(d), 1(d) 1.4 => 1(d), 1(d) 1.5 => 2(u), 2(u) 1.6 => 2(u), 2(u) 1.7 => 2(u), 2(u) 1.8 => 2(u), 2(u) 1.9 => 2(u), 2(u) 2.0 => 2(n), 2(n) 2.1 => 2(d), 2(d) 2.2 => 2(d), 2(d) 2.3 => 2(d), 2(d) 2.4 => 2(d), 2(d) 2.5 => 3(u), 2(d) 2.6 => 3(u), 3(u) 2.7 => 3(u), 3(u) 2.8 => 3(u), 3(u) 2.9 => 3(u), 3(u) .... In this used-to-be-thought-correct table, Round Ups algorithm have 2 Unrounded, 8 Round Down, and 10 Round Ups which seems incorrect while Round Even have 2 Unrounded, 9 Round Down, and 9 Round Up which seems correct. The misunderstanding comes from a view that thinks that there is such thing as Not Rounded while in fact the only number that is Not Rounded is 1 and 2 while 1.0 and 2.0 must still be rounded, in practice we can just say that all number must be rounded somewhere. Original => (RoundUp(u|d), RoundNearestEven(u|d) .... 1.0 => 1(d), 1(d) 1.1 => 1(d), 1(d) 1.2 => 1(d), 1(d) 1.3 => 1(d), 1(d) 1.4 => 1(d), 1(d) 1.5 => 2(u), 2(u) 1.6 => 2(u), 2(u) 1.7 => 2(u), 2(u) 1.8 => 2(u), 2(u) 1.9 => 2(u), 2(u) 2.0 => 2(d), 2(d) 2.1 => 2(d), 2(d) 2.2 => 2(d), 2(d) 2.3 => 2(d), 2(d) 2.4 => 2(d), 2(d) 2.5 => 3(u), 2(d) 2.6 => 3(u), 3(u) 2.7 => 3(u), 3(u) 2.8 => 3(u), 3(u) 2.9 => 3(u), 3(u) .... In this table, we consider that a number is rounded down when the number is equal to truncated value (the number without fractional part), while round up is equal to truncated value + 1 or truncated value -1 if value is negative (Actually this is not round-half-up algorithm, it's a round-half-away-from-zero algorithm, but lets just consider that to be the same for now). In this revised table, you get 10 round ups and 10 round down (i.e. Average Rounding Error == 0), while by rounding to nearest even you get 9 round up and 11 round down (i.e. Average Rounding Error != 0). Another mistake, in an unquantized value the probability of getting exactly 0.5 (or any other number specified) is not 0 but an infinitesimal (i.e. lim(x) where x -> 0 (BUT NOT ZERO)) No the reason is not that, it's because 1) it is much easier to input integral numbers to computer (calculator or cashier machine), to input .5 to computer you have to press two more buttons or at least one shortcut button and 2) if you have two lists, one with a bunch of . 5's and the other just a few of them you would know that it's easier to sum the latter list with or without calculator. A false assertion from a false understanding. The use of Round Up algorithm is a refinement of the false understanding we used to practice in the past. [/QUOTE]
Verification
Post reply
Forums
Archive
Archive
Python
Rounding a number to nearest even
Top