#15084: xsrange int-overflow
---------------------------------------------+-------------------------
Reporter: dkrenn | Owner:
Type: defect | Status: new
Priority: major | Milestone: sage-5.12
Component: misc | Resolution:
Keywords: xsrange int long overflow | Merged in:
Authors: | Reviewers:
Report Upstream: N/A | Work issues:
Branch: | Commit:
Dependencies: | Stopgaps:
---------------------------------------------+-------------------------
Comment (by nbruin):
This is a [http://docs.python.org/library/functions.html#xrange
documented] restriction on `xrange` and sage's code will only run into it
in situations where the full iterator would never be exhausted
(implementation uses `xrange(icount)`). Compare:
{{{
sage: for _ in xsrange(Integer(2^63-10), Integer(2^63)): pass #no problem
sage: for _ in xrange(Integer(2^63-10), Integer(2^63)): pass
OverflowError: Python int too large to convert to C long
}}}
so the question is really whether `xsrange` should also be usable to
create (effectively) infinite arithmetic progressions. Incidentally,
`xrange` and `xsrange` model different kinds of objects: `xrange`
implements `__getitem__` and `__iter__` but not `next`, so it's really
just modelling a finite arithmetic progression as (something close to) a
list, whereas `xsrange` is a generator expression, i.e., an iterator:
{{{
sage: xrange(2^63-1)[2^33]
8589934592
sage: xsrange(2^63-1)[2^33]
TypeError: 'generator' object has no attribute '__getitem__'
}}}
--
Ticket URL: <http://trac.sagemath.org/ticket/15084#comment:3>
Sage <http://www.sagemath.org>
Sage: Creating a Viable Open Source Alternative to Magma, Maple, Mathematica,
and MATLAB
--
You received this message because you are subscribed to the Google Groups
"sage-trac" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sage-trac.
For more options, visit https://groups.google.com/groups/opt_out.