[issue5377] Strange behavior when performing int on a Decimal made from -sys.maxint-1
STINNER Victor
report at bugs.python.org
Fri Feb 27 02:09:38 CET 2009
STINNER Victor <victor.stinner at haypocalc.com> added the comment:
> the question is why would the second int() return an int,
> if it's indeed a long?
Python doesn't convert long to int even if the long can fit in an int.
Example:
>>> type(1)
<type 'int'>
>>> type(1L)
<type 'long'>
>>> type(1L+1)
<type 'long'>
>>> type(2)
<type 'int'>
Even if 1L and 2L can fit in a int, Python keeps the long type.
> why the difference in this behavior between 2.5.1 and 2.5.2
No idea. You can simplify your test script with :
# example with python 2.5.1 (32 bits CPU)
>>> type(-int('2147483648'))
<type 'long'>
>>> sys.maxint
On a 64 bits CPU, sys.maxint is much bigger, so don't have the problem
with -2147483648 but with -9223372036854775808:
# example with python 2.5.2 (*64 bits CPU*)
>>> sys.maxint + 1
9223372036854775808L
>>> -int('9223372036854775808')
-9223372036854775808L
>>> int(-int('9223372036854775808'))
-9223372036854775808
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue5377>
_______________________________________
More information about the Python-bugs-list
mailing list