New submission from Christian Taylor <di...@chello.at>: 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+20000, 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)) 650000.0 >>> next(check(8)) 14500000000.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 <rep...@bugs.python.org> <http://bugs.python.org/issue5473> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com