[issue4707] round() shows undocumented behaviour
New submission from Christian Taylor : I've been playing around with the newly released Python 3.0, and I'm a bit confused about the built-in round()-function. To sum it up in a single example: Python 3.0 (r30:67503, Dec 7 2008, 04:54:04) [GCC 4.3.2] on linux2 >>> round(25, -1) 30.0 I had expected the result to be the integer 20, because: 1. The documentation on built-in functions says: "values are rounded to the closest multiple of 10 to the power minus n; if two multiples are equally close, rounding is done toward the even choice" 2. Both help(round) and the documentation on built-in functions claim that, if two arguments are given, the return value will be of the same type as the first argument. Is this unintended behaviour, or am I missing something? -- components: Interpreter Core messages: 78113 nosy: dingo severity: normal status: open title: round() shows undocumented behaviour type: behavior versions: Python 3.0 ___ Python tracker <http://bugs.python.org/issue4707> ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue4707] round() shows undocumented behaviour
Christian Taylor added the comment: I'm using Arch Linux (32 bit) with kernel 2.6.25 and glibc 2.8 on a core 2 duo. The described behaviour occurs in a precompiled binary of Python 3.0, but also in versions I've compiled just now, which includes Python 3.0+ (release30-maint:67879) As far as the rounding itself is concerned, round(x, n) seems to work as documented with n>=0 on my system, while giving the same results as the Python-2.6-version of round() for n<0. ___ Python tracker <http://bugs.python.org/issue4707> ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue5473] round(float, ndigits<0) sometimes rounds to odd
New submission from Christian Taylor : round(x, n) may unexpectedly round floats upwards to odd multiples of 10**(-n) if n is negative, depending on the system Python 3 is running on. I think this is distinct from issue 1869. Example: >>> round(25.0, -1) 30.0 I used the following function to check 1000 cases for a given exponent and yield the values where rounding to odd occurs: def check(exponent): factor = 10**exponent for x in range(5, 5+2, 20): if not round(float(x*factor), -1-exponent) < x*factor: yield float(x*factor) On a Core2 Duo running Arch Linux (32bit): Python 3.1a1+ (py3k:70302, Mar 10 2009, 21:43:09) [GCC 4.3.3] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> [len(list(check(exponent))) for exponent in range(10)] [1000, 1000, 1000, 1000, 1000, 0, 0, 1000, 1000, 1000] On an Athlon XP running Slackware (32bit): Python 3.1a1+ (py3k:70302, Mar 11 2009, 01:01:18) [GCC 4.1.2] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> [len(list(check(exponent))) for exponent in range(10)] [1000, 1000, 1000, 1000, 1000, 0, 0, 1000, 1000, 1000] On an Athlon 64 running Debian (32bit): Python 3.1a1+ (py3k:70302, Mar 10 2009, 22:45:59) [GCC 4.3.3] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> [len(list(check(exponent))) for exponent in range(10)] [0, 0, 0, 0, 630, 0, 0, 0, 195, 0] >>> next(check(4)) 65.0 >>> next(check(8)) 145.0 -- components: Interpreter Core messages: 83450 nosy: dingo severity: normal status: open title: round(float, ndigits<0) sometimes rounds to odd type: behavior versions: Python 3.0, Python 3.1 ___ Python tracker <http://bugs.python.org/issue5473> ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue5473] round(float, ndigits<0) sometimes rounds to odd
Christian Taylor added the comment: I see what you mean. I originally thought that intermediate numbers not being representable as floats was not the issue here, since for example 25.0/10.0 should give the exact result - despite issue 1869 clearly mentioning the *multiplication* by powers of 10. Thanks for clearing that up and sorry for the noise! -- ___ Python tracker <http://bugs.python.org/issue5473> ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com