有没有什么办法来强制Python来使用64位整数的Windows?整数、有没有什么、办法、Python

2023-09-08 10:31:12 作者:_爷一个人过生活

我注意到,每当任意整数超过2 ^ 31-1我的电话号码重code遭受较大的经济放缓,尽管我使用Python的64位版本的Windows的64位版本。这似乎是真正关于Python 2.7和Python 3。我读过的这中的Windows做了他们的多头头寸为32位,但是,这并不意味着对我来说这是不可能的使用64位数字。

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.

有没有办法使用64位整数或者虽然类或模块,甚至是不同版本的Python?

Is there a way to use 64 bit integers either though a class or module or even a different build of Python?

推荐答案

我不知道,它使用一个64位原生类型 INT 与任何Windows版本Python的2.7。所有的C编译器将使用来指代32位的类型。更改Python中使用很长很长的内部重新presentation INT 将可能打破扩展模块。

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.

在Python的3​​.x的,唯一的整数类型是任意的precision型(被称为下的Python 2.x的)。在64位系统上,任意precision型的2 ^ 30位数据块的工作原理。在32位系统中,任意precision型的2 ^ 15位数据块的工作原理。值15和30将是难以改变的。

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.

有关外部库,我保持 gmpy2 库。它提供了访问任意precision GMP / MPIR库。该 gmpy2.mpz 整数类型通常是更有效的一次,人数达到128〜位长。情况因人而异。

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.

 
精彩推荐
图片推荐