robertwb / issues-import-test

0 stars 0 forks source link

reversed(range(start, stop, step)) is wrong #126

Closed robertwb closed 7 years ago

robertwb commented 7 years ago

Reported by mark on 22 Mar 2012 12:27 UTC When iterating over reversed(range()), the reversed swaps the bounds of the range() and offsets it by one. This is wrong for a step that is not 1 or -1. Example:

cdef int i
for i in reversed(range(0, 10, 4)):
    print i

print list(reversed(range(0, 10, 4)))

output:

9
5
1
[4, 0](8,)

Migrated-From: http://trac.cython.org/ticket/763

robertwb commented 7 years ago

Comment by scoder on 24 Mar 2012 16:10 UTC I've disabled the optimised looping for this case:

https://github.com/cython/cython/commit/f766a7fc2a4b7fa67b2db8592034980bff9c5783

robertwb commented 7 years ago

Comment by scoder on 24 Mar 2012 16:13 UTC Follow-up ticket for optimising this case is in $trac_url/ticket/$id.