python3中的int类型占64位,有没有什么办法来强制Python来使用64位整数的Windows?
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.
總結
以上是生活随笔為你收集整理的python3中的int类型占64位,有没有什么办法来强制Python来使用64位整数的Windows?的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: java 计算器类图_多态计算器(封装、
- 下一篇: html一个空格多少像素,一个空格占几个