STINNER Victor <[email protected]> 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 <[email protected]>
<http://bugs.python.org/issue5377>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com