[issue5377] Strange behavior when performing int on a Decimal made from -sys.maxint-1
STINNER Victor
report at bugs.python.org
Fri Feb 27 00:32:56 CET 2009
STINNER Victor <victor.stinner at haypocalc.com> added the comment:
For a Decimal object (d), int(d) calls d.__int__(). In your example, d
has the attributes:
* _sign=1 (negative)
* _exp=0 (10^0=1)
* _int='2147483648'
d.__int__() uses s*int(self._int)*10**self._exp
<=> -(int('2147483648')). Since int('2147483648') creates a long, you
finally get a long instead of an integer.
Workaround to get a small integer even with -2147483648:
int(int(d)) ;-)
For me, it's not a bug because __int__() can return a long! The
following code works in Python 2.5 and 2.6:
class A:
def __int__(self):
return 10**20
----------
nosy: +haypo
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue5377>
_______________________________________
More information about the Python-bugs-list
mailing list