This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: int(1e200) should return long
Type: Stage:
Components: Interpreter Core Versions: Python 2.3
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: doerwalter Nosy List: doerwalter, gvanrossum
Priority: normal Keywords:

Created on 2002-11-07 19:02 by doerwalter, last changed 2022-04-10 16:05 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
diff.txt doerwalter, 2002-11-07 19:02
diff2.txt doerwalter, 2002-11-18 19:01
Messages (7)
msg13129 - (view) Author: Walter Dörwald (doerwalter) * (Python committer) Date: 2002-11-07 19:02
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.
msg13130 - (view) Author: Guido van Rossum (gvanrossum) * (Python committer) Date: 2002-11-14 23:22
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.
msg13131 - (view) Author: Walter Dörwald (doerwalter) * (Python committer) Date: 2002-11-18 19:01
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?
msg13132 - (view) Author: Guido van Rossum (gvanrossum) * (Python committer) Date: 2002-11-18 19:46
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! :-)
msg13133 - (view) Author: Walter Dörwald (doerwalter) * (Python committer) Date: 2002-11-19 11:09
Logged In: YES 
user_id=89016

So should I add a note to Misc/NEWS and check it in?

Are there any changes to the documentation that should be done?
msg13134 - (view) Author: Guido van Rossum (gvanrossum) * (Python committer) Date: 2002-11-19 15:45
Logged In: YES 
user_id=6380

Please do check it in and add a note to NEWS.

I dunno about docs, please look and ask around. int() should
be easy to find.
msg13135 - (view) Author: Walter Dörwald (doerwalter) * (Python committer) Date: 2002-11-19 20:54
Logged In: YES 
user_id=89016

Doc/api/abstract.tex 1.20
Checked in as:
Doc/lib/libfuncs.tex 1.120
Lib/test/test_b1.py 1.58
Lib/test/test_long.py  1.21
Lib/test/test_types.py 1.40
Misc/NEWS 1.529
Objects/floatobject.c 2.117
Objects/intobject.c 2.95
Objects/longobject.c 1.145
History
Date User Action Args
2022-04-10 16:05:49adminsetgithub: 37435
2002-11-07 19:02:32doerwaltercreate