[Python-bugs-list] [ python-Bugs-499708 ] Int(long) causes Integer Overflow
noreply@sourceforge.net
noreply@sourceforge.net
Fri, 04 Jan 2002 19:46:25 -0800
Bugs item #499708, was opened at 2002-01-04 19:46
You can respond by visiting:
http://sourceforge.net/tracker/?func=detail&atid=105470&aid=499708&group_id=5470
Category: Python Interpreter Core
Group: Python 2.2
Status: Open
Resolution: None
Priority: 5
Submitted By: Raymond Hettinger (rhettinger)
Assigned to: Nobody/Anonymous (nobody)
Summary: Int(long) causes Integer Overflow
Initial Comment:
In the spirit of unifying longs and ints,
should int() be the sole way of truncating
floats or should the programmer be responsible
for categorizing and handling ints and longs
separately?
>>> int( 12341234123.4 )
Traceback (most recent call last):
File "<interactive input>", line 1, in ?
OverflowError: float too large to convert
>>> def myint(f):
... try:
... return int(f)
... except OverflowError:
... return long(f)
...
>>> myint( 12341234123.4 )
12341234123L
>>> myint(123.4)
123
I have one misgiving about fixing this one.
assert type(int(x)) == int, 'should always succeed'
would fail for when x=12341234123.4
The only way around this is to make longs return
a IntType. Who knows what this would break.
----------------------------------------------------------------------
You can respond by visiting:
http://sourceforge.net/tracker/?func=detail&atid=105470&aid=499708&group_id=5470