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.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值