BigInteger有上限吗? [英] Is there an upper bound to BigInteger?
问题描述
可能重复:
BigInteger没有限制意味着什么?
BigInteger
的Javadoc没有定义任何最大值或最小值。但是,它确实说:
The Javadoc for BigInteger
does not define any maximum or minimum. However, it does say:
(强调添加)
不可变任意精度整数
是否存在这样的最大值,即使在理论上也是如此?或者 BigInteger
的操作方式根本不同,这样实际上除了计算机上可用的内存量之外,实际上没有最多?
Is there such a maximum, even in theory? Or is the way BigInteger
operates fundamentally different, such that there is in reality no maximum except for the amount of memory available on the computer?
推荐答案
该数字保存在 int []
中 - 最大值数组是 Integer.MAX_VALUE
。所以最大BigInteger可能是(2 ^ 32)^ Integer.MAX_VALUE
。
The number is held in an int[]
- the maximum size of an array is Integer.MAX_VALUE
. So the maximum BigInteger probably is (2 ^ 32) ^ Integer.MAX_VALUE
.
不可否认,这是依赖于实现的,不是规范的一部分。
Admittedly, this is implementation dependent, not part of the specification.
在Java 8中,一些信息被添加到 BigInteger javadoc ,给出了最小支持范围和当前实现的实际限制:
In Java 8, some information was added to the BigInteger javadoc, giving a minimum supported range and the actual limit of the current implementation:
BigInteger
必须支持范围内的值 - 2
Integer.MAX_VALUE
(独家)到+2
Integer.MAX_VALUE
(不包括)并且可能支持该范围之外的值。
BigInteger
must support values in the range-2
Integer.MAX_VALUE
(exclusive) to+2
Integer.MAX_VALUE
(exclusive) and may support values outside of that range.
实现说明: BigInteger
构造函数和操作抛出 ArithmeticException
,当结果超出支持的 -2
Integer.MAX_VALUE
(独家)到 +2
Integer.MAX_VALUE
(不包括)。
Implementation note: BigInteger
constructors and operations throw ArithmeticException
when the result is out of the supported range of -2
Integer.MAX_VALUE
(exclusive) to +2
Integer.MAX_VALUE
(exclusive).
这篇关于BigInteger有上限吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!