Python等语言如何克服C的Integral数据限制? [英] How do languages such as Python overcome C's Integral data limits?

查看:138
本文介绍了Python等语言如何克服C的Integral数据限制?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在C,Python和Scheme中使用factorial程序进行一些随机实验。我发现了这个事实:

While doing some random experimentation with a factorial program in C, Python and Scheme. I came across this fact:

在C中,使用'unsigned long long'数据类型,我可以打印的最大因子是65.这是'9223372036854775808',这是指定的19位数字此处

In C, using 'unsigned long long' data type, the largest factorial I can print is of 65. which is '9223372036854775808' that is 19 digits as specified here.

在Python中,我可以找到一个大小为999的阶乘,它由大量数字组成,远远超过19。

In Python, I can find the factorial of a number as large as 999 which consists of a large number of digits, much more than 19.

CPython如何实现这一目标?它是否使用 octaword 等数据类型?

How does CPython achieve this? Does it use a data type like 'octaword' ?

我可能会遗漏一些基本事实。所以,我会很感激一些见解和/或参考阅读。谢谢!

I might be missing some fundamental facts here. So, I would appreciate some insights and/or references to read. Thanks!

更新:谢谢大家的解释。这是否意味着,CPython正在使用GNU多精度库(或其他类似的库)?

UPDATE: Thank you all for the explanation. Does that means, CPython is using the GNU Multi-precision library (or some other similar library)?

更新2:我在源代码中寻找Python的'bignum'实现。到底在哪里?它位于 http://svn.python.org /view/python/trunk/Objects/longobject.c?view=markup 。谢谢Baishampayan。

UPDATE 2: I am looking for Python's 'bignum' implementation in the sources. Where exactly it is? Its here at http://svn.python.org/view/python/trunk/Objects/longobject.c?view=markup. Thanks Baishampayan.

推荐答案

它被称为任意精度算术。还有更多内容: http://en.wikipedia.org/wiki/Arbitrary-precision_arithmetic

It's called Arbitrary Precision Arithmetic. There's more here: http://en.wikipedia.org/wiki/Arbitrary-precision_arithmetic

这篇关于Python等语言如何克服C的Integral数据限制?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆