#19029: doctest Python vs Sage ints
-------------------------------------+-------------------------------------
Reporter: vbraun | Owner:
Type: enhancement | Status: new
Priority: major | Milestone: sage-6.9
Component: user interface | Resolution:
Keywords: | Merged in:
Authors: Volker Braun | Reviewers:
Report Upstream: N/A | Work issues:
Branch: | Commit:
u/vbraun/doctest_python_vs_sage_ints|
129259d7e537f92b1e55fbb414477231117456fc
Dependencies: | Stopgaps:
-------------------------------------+-------------------------------------
Comment (by nbruin):
Replying to [comment:14 vbraun]:
> BTW I don't think that we always have to return Sage ints; E.g. if a
Python int/float is used as a label then I don't really care. But Sage
functions that '''count''' something should return Sage integers as that
number has a combinatorial / number theoretic meaning.
... which already goes wrong on a rather fundamental level with a
`__len__` (which ''counts'' the number of elements), which is mandated in
python to return a machine-length integer to fit in the protocol it is
for, and for efficiency reasons should return an `int` to avoid an extra
conversion when `len(...)` is used.
{{{
sage: class A(object):
....: def __len__(self):
....: return 10^40
....:
sage: a=A()
sage: len(a)
OverflowError: Python int too large to convert to C long
sage: a.__len__()
10000000000000000000000000000000000000000
}}}
I think this makes is rather hard to formulate a clear rule for when an
`Integer` should really be returned.
--
Ticket URL: <http://trac.sagemath.org/ticket/19029#comment:15>
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/d/optout.