首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >BigInteger有上限吗?

BigInteger有上限吗?
EN

Stack Overflow用户
提问于 2012-10-02 23:21:10
回答 1查看 130.6K关注 0票数 91

可能重复:

What does BigInteger having no limit mean?

BigInteger的Javadoc没有定义任何最大值或最小值。然而,它确实说:

(已添加强调)

不可变的arbitrary-precision整数

即使在理论上,也有这样的最大值吗?或者,BigInteger的操作方式是根本不同的,以至于除了计算机上可用的内存量之外,实际上没有最大值?

EN

回答 1

Stack Overflow用户

发布于 2012-10-02 23:28:50

BigInteger只有在您知道它不是小数并且long数据类型可能不够大的情况下才会使用。BigInteger没有对其最大大小的限制(就像计算机上的内存可以容纳的那样大)。

来自here

它是使用int[]实现的

  110       /**
  111        * The magnitude of this BigInteger, in <i>big-endian</i> order: the
  112        * zeroth element of this array is the most-significant int of the
  113        * magnitude.  The magnitude must be "minimal" in that the most-significant
  114        * int ({@code mag[0]}) must be non-zero.  This is necessary to
  115        * ensure that there is exactly one representation for each BigInteger
  116        * value.  Note that this implies that the BigInteger zero has a
  117        * zero-length mag array.
  118        */
  119       final int[] mag;

来自the source

来自维基百科的文章Arbitrary-precision arithmetic

几种现代编程语言具有对bignums的内置支持,其他语言则具有可用于任意精度整数和浮点数学的库。这些实现通常使用可变长度的数字数组,而不是将值存储为与处理器寄存器大小相关的固定数量的二进制位。

票数 19
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/12693273

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档