I’ve noticed that whenever any integer surpasses 2^31-1 my number heavy code suffers a large slowdown, despite the fact I’m using a 64 bit build of Python on a 64bit version of Windows. This seems to be true on Python 2.7 and Python 3. I’ve read that Windows made their longs to be 32 bits, but that doesn’t suggest to me it is impossible to use 64 bit numbers.
Is there a way to use 64 bit integers either though a class or module or even a different build of Python?
解决方案
I'm not aware of any Windows build that uses a 64-bit native type for int with Python 2.7. All C compilers will use long to refer to a 32 bit type. Changing Python to use long long for the internal representation of int would likely break extension modules.
On Python 3.x, the only integer type is the arbitrary precision type (known as long under Python 2.x). On 64-bit systems, the arbitrary precision type works in chunks of 2^30 bits. On 32-bit systems, the arbitrary precision type works in chunks of 2^15 bits. The values 15 and 30 would be difficult to change.
For external libraries, I maintain the gmpy2 library. It provides access to the arbitrary precision GMP/MPIR library. The gmpy2.mpz integer type is usually more efficient once numbers reach ~128 bits in length. YMMV.