New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
3.0/3.1: Bad bug in range() computation (or possible Integer problem) #50583
Comments
Please note that the correct answer is 25, and the last element is missing ! This bug does not show on 64-bit versions (but 46337**2 is near 2**31). ~Markus C:\Python31>python
Python 3.1rc2 (r31rc2:73414, Jun 13 2009, 16:43:15) [MSC v.1500 32 bit
(Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> len(list(range(46337**2, 46349**2, 46337)))
24
C:\Python30>python.exe
Python 3.0.1 (r301:69561, Feb 13 2009, 20:04:18) [MSC v.1500 32 bit
(Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> len(list(range(46337**2, 46349**2, 46337)))
24 |
Simpler test case:
Py2.6:
>>> n = 46349**2
>>> n
2148229801L
>>> range(n-10, n, 3)
[2148229791L, 2148229794L, 2148229797L, 2148229800L]
Py3.0:
>>> n = 46349**2
>>> n
2148229801
>>> list(range(n-10, n, 3))
[2148229791, 2148229794, 2148229797] |
The length calculation in range_iter in Objects/rangeobject.c is I think this is serious enough to be considered a release blocker for 3.1; |
Here's a patch for py3k. There are also a whole bunch of tests that are commented |
The patch looks good. Please apply. |
Applied to py3k in r73547. Will backport to 3.0. |
Backported to release30-maint branch in r73549. Thanks for catching this, Markus! |
Many thanks for your quick fix! ~Markus |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: