可能重复:
What does BigInteger having no limit mean?
BigInteger
的Javadoc没有定义任何最大值或最小值。然而,它确实说:
(已添加强调)
不可变的arbitrary-precision整数
即使在理论上,也有这样的最大值吗?或者,BigInteger
的操作方式是根本不同的,以至于除了计算机上可用的内存量之外,实际上没有最大值?
发布于 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;
来自维基百科的文章Arbitrary-precision arithmetic
几种现代编程语言具有对bignums的内置支持,其他语言则具有可用于任意精度整数和浮点数学的库。这些实现通常使用可变长度的数字数组,而不是将值存储为与处理器寄存器大小相关的固定数量的二进制位。
https://stackoverflow.com/questions/12693273
复制相似问题