This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author dingo
Recipients dingo
Date 2009-03-10.23:18:51
SpamBayes Score 5.9967005e-09
Marked as misclassified No
Message-id <[email protected]>
In-reply-to
Content
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
History
Date User Action Args
2009-03-10 23:18:55dingosetrecipients: + dingo
2009-03-10 23:18:54dingosetmessageid: <[email protected]>
2009-03-10 23:18:53dingolinkissue5473 messages
2009-03-10 23:18:51dingocreate