[Python-Dev] ints not overflowing into longs?

Derek Shockey derek.shockey at gmail.com
Thu Nov 3 03:32:38 CET 2011

I just found an unexpected behavior and I'm wondering if it is a bug.
In my 2.7.2 interpreter on OS X, built and installed via MacPorts, it
appears that integers are not correctly overflowing into longs and
instead are yielding bizarre results. I can only reproduce this when
using the exponent operator with two ints (declaring either operand
explicitly as long prevents the behavior).

>>> 2**100
>>> 2**100L

>>> 20**20
>>> 20L**20

>>> 10**20
>>> 10L**20L

To confirm I'm not crazy, I tried in the 2.7.1 and 2.6.7 installations
included in OS X 10.7, and also a 2.7.2+ (not sure what the + is) on
an Ubuntu machine and didn't see this behavior. This looks like some
kind of truncation error, but I don't know much about the internals of
Python and have no idea what's going on. I assume since it's only in
my MacPorts installation, it must be build configuration issue that is
specific to OS X, perhaps only 10.7, or MacPorts.

Am I doing something wrong, and is there a way to fix it before I
compile? I could find any references to this problem as a known issue.


More information about the Python-Dev mailing list