[Python-bugs-list] [ python-Bugs-635115 ] int(1e200) should return long

noreply@sourceforge.net noreply@sourceforge.net
Mon, 18 Nov 2002 11:46:47 -0800


Bugs item #635115, was opened at 2002-11-07 14:02
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=635115&group_id=5470

Category: Type/class unification
Group: Python 2.3
Status: Open
>Resolution: Accepted
Priority: 5
Submitted By: Walter Dörwald (doerwalter)
>Assigned to: Walter Dörwald (doerwalter)
Summary: int(1e200) should return long

Initial Comment:
To remove the distinction between int and long
int(1e200) should return a long object instead of
raising an OverflowError.

This is related to bug #629989:
int("123123123123123123") doesn't work.

Fixing this could be done by changing
Objects/floatobject.c/float_int (see attached patch),
but this changes the meaning of the nb_int slot.

----------------------------------------------------------------------

>Comment By: Guido van Rossum (gvanrossum)
Date: 2002-11-18 14:46

Message:
Logged In: YES 
user_id=6380

Looks good (I haven't run this).

I was shocked to see that int(2**1000) will now return a
long rather than failing, but that's actually correct! :-)


----------------------------------------------------------------------

Comment By: Walter Dörwald (doerwalter)
Date: 2002-11-18 14:01

Message:
Logged In: YES 
user_id=89016

This second patch (diff2.txt) fixes PyInt_AsLong(), so it is
able to cope with longs. In addition to that int(long) has
been changed to return a long, if the int overflows:

>>> int(1L<<100) 
1267650600228229401496703205376L

For subinstances of long the patch ensures that a proper
long instance will be created. (See the additional test in
test_long.py).

If I understood the sourcecode correctly nb_int, nb_long and
nb_float might return objects, that are not instances of
int, long or float, but instances of subclasses of int, long
or float. Is this a bug or an (undocumented?) feature?


----------------------------------------------------------------------

Comment By: Guido van Rossum (gvanrossum)
Date: 2002-11-14 18:22

Message:
Logged In: YES 
user_id=6380

PyInt_AsLong() insists that nb_int returns a PyInt_Object.

I think it's okay that nb_int returns a non-int -- classes
don't require __int__ to do this either. So PyInt_AsLong()
should accept a PyLong_Object as well, I guess.

----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=635115&group_id=5470