python怎么表达整数_python如何表示如此大的整数?

在C,C和Java中,整数具有一定范围.我在Python中意识到的一件事是我可以计算出很大的整数,比如pow(2,100). C,pow(2,100)中的相同等效代码显然会导致溢出,因为在32位架构中,无符号整数类型的范围为0到2 ^ 32-1. Python如何计算这些大数字?

解决方法:

基本上,Python中的大数字存储在“数字”数组中.这是正确的,因为每个’数字’本身实际上可能是一个很大的数字. )

There are two different sets of parameters: one set for 30-bit digits,

stored in an unsigned 32-bit integer type, and one set for 15-bit

digits with each digit stored in an unsigned short. The value of

PYLONG_BITS_IN_DIGIT, defined either at configure time or in pyport.h,

is used to decide which digit size to use.

/* Long integer representation.

The absolute value of a number is equal to

SUM(for i=0 through abs(ob_size)-1) ob_digit[i] * 2**(SHIFT*i)

Negative numbers are represented with ob_size < 0;

zero is represented by ob_size == 0.

In a normalized number, ob_digit[abs(ob_size)-1] (the most significant

digit) is never zero. Also, in all cases, for all valid i,

0 <= ob_digit[i] <= MASK.

The allocation function takes care of allocating extra memory

so that ob_digit[0] ... ob_digit[abs(ob_size)-1] are actually available.

*/

struct _longobject {

PyObject_VAR_HEAD

digit ob_digit[1];

};

标签:python,integer,architecture

来源: https://codeday.me/bug/20190612/1225835.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值