- java.lang.Object
-
- java.lang.Number
-
- java.math.BigInteger
-
- 实现的所有接口
-
Serializable,Comparable<BigInteger>
public class BigInteger extends Number implements Comparable<BigInteger>
不可变的任意精度整数。 所有操作都表现得好像BigIntegers用二进制补码表示法表示(如Java的原始整数类型)。 BigInteger为所有Java的原始整数运算符以及java.lang.Math中的所有相关方法提供类似物。 此外,BigInteger还提供模块化算术,GCD计算,素性测试,素数生成,位操作以及一些其他杂项操作的操作。算术运算的语义完全模仿Java的整数算术运算符,如Java语言规范中所定义。 例如,除以零会抛出
ArithmeticException,将负值除以正值会产生负(或零)余数。移位操作的语义扩展了Java移位操作符的语义,以允许负移位距离。 具有负移位距离的右移导致左移,反之亦然。 省略无符号右移位运算符(
>>>),因为该操作仅对固定大小的字有意义,而对概念上具有无限数量的前导虚拟符号位的表示有意义。按位逻辑运算的语义完全模仿Java的按位整数运算符。 二进制运算符(
and,or,xor)隐式地对两个操作数的较短执行操作之前执行符号扩展。比较操作执行有符号整数比较,类似于Java的关系运算符和相等运算符执行的比较。
提供模块化算术运算以计算残差,执行取幂和计算乘法逆。 这些方法始终返回非负结果,介于
0和(modulus - 1)之间。位操作在其操作数的二进制补码表示的单个位上操作。 如有必要,操作数将进行符号扩展,以使其包含指定的位。 没有任何一位操作可以产生一个与操作BigInteger具有不同符号的BigInteger,因为它们只影响一个位,并且该类提供的任意大抽象确保概念上存在无限多个“虚拟符号位” “在每个BigInteger之前。
为了简洁和清楚起见,在整个BigInteger方法的描述中使用伪代码。 伪代码表达式
(i + j)是“BigInteger的缩写,其值为BigIntegeri加上BigIntegerj。” 的伪代码表达(i == j)是简写“true当且仅当所述的BigIntegeri表示相同的值的BigIntegerj”。 其他伪代码表达式的解释类似。当为任何输入参数传递空对象引用时,此类中的所有方法和构造函数都会抛出
NullPointerException。 BigInteger必须支持-2Integer.MAX_VALUE(不包括)至+2Integer.MAX_VALUE(不包括)范围内的值,并且可以支持该范围之外的值。 当BigInteger构造函数或方法生成超出支持范围的值时,将引发ArithmeticException。 可能的素数值的范围是有限的,可能小于BigInteger的完全支持的正值范围。 范围必须至少为1到2 500000000 。- Implementation Note:
-
在参考实现中,当结果超出支持范围-2
Integer.MAX_VALUE(不包括)到+2Integer.MAX_VALUE(不包括)时,BigInteger构造函数和操作抛出ArithmeticException。 - 从以下版本开始:
- 1.1
- 另请参见:
-
BigDecimal, Serialized Form - See The Java™ Language Specification:
- 4.2.2整数运算
-
-
字段汇总
字段 变量和类型 字段 描述 static BigIntegerONEBigInteger常量一个。static BigIntegerTENBigInteger常数十。static BigIntegerTWOBigInteger常数两个。static BigIntegerZEROBigInteger常数为零。
-
构造方法摘要
构造方法 构造器 描述 BigInteger(byte[] val)将包含BigInteger的二进制补码二进制表示的字节数组转换为BigInteger。BigInteger(byte[] val, int off, int len)将包含BigInteger的二进制补码二进制表示的字节子数组转换为BigInteger。BigInteger(int signum, byte[] magnitude)将BigInteger的符号幅度表示转换为BigInteger。BigInteger(int signum, byte[] magnitude, int off, int len)将BigInteger的符号幅度表示转换为BigInteger。BigInteger(int bitLength, int certainty, Random rnd)使用指定的bitLength构造一个随机生成的可能为素数的正BigInteger。BigInteger(int numBits, Random rnd)构造一个随机生成的BigInteger,均匀分布在0到(2numBits- 1)的范围内。BigInteger(String val)将BigInteger的十进制字符串表示形式转换为BigInteger。BigInteger(String val, int radix)将指定基数中BigInteger的String表示形式转换为BigInteger。
-
方法摘要
所有方法 静态方法 实例方法 具体的方法 变量和类型 方法 描述 BigIntegerabs()返回一个BigInteger,其值是此BigInteger的绝对值。BigIntegeradd(BigInteger val)返回一个值为(this + val)的BigInteger。BigIntegerand(BigInteger val)返回值为(this & val)的BigInteger。BigIntegerandNot(BigInteger val)返回值为(this & ~val)的BigInteger。intbitCount()返回此BigInteger的二进制补码表示中与其符号位不同的位数。intbitLength()返回此BigInteger的最小二进制补码表示中的位数, 不包括符号位。bytebyteValueExact()将BigInteger转换为byte,检查是否丢失了信息。BigIntegerclearBit(int n)返回一个BigInteger,其值等于此BigInteger且指定位已清除。intcompareTo(BigInteger val)将此BigInteger与指定的BigInteger进行比较。BigIntegerdivide(BigInteger val)返回值为(this / val)的BigInteger。BigInteger[]divideAndRemainder(BigInteger val)返回两个BigIntegers的数组,其中包含(this / val)后跟(this % val)。doubledoubleValue()将此BigInteger转换为double。booleanequals(Object x)将此BigInteger与指定的Object进行相等性比较。BigIntegerflipBit(int n)返回一个BigInteger,其值等于此BigInteger,并且指定的位被翻转。floatfloatValue()将此BigInteger转换为float。BigIntegergcd(BigInteger val)返回一个BigInteger,其值是abs(this)和abs(val)。intgetLowestSetBit()返回此BigInteger中最右边(最低位)一位的索引(最右边一位右边的零位数)。inthashCode()返回此BigInteger的哈希码。intintValue()将此BigInteger转换为int。intintValueExact()将此BigInteger转换为int,检查是否丢失了信息。booleanisProbablePrime(int certainty)返回true如果此BigInteger可能为素数,false,如果它一定为合。longlongValue()将此BigInteger转换为long。longlongValueExact()将此BigInteger转换为long,检查是否丢失了信息。BigIntegermax(BigInteger val)返回此BigInteger和val。BigIntegermin(BigInteger val)返回此BigInteger和val。BigIntegermod(BigInteger m)返回一个值为(this mod m的BigInteger。BigIntegermodInverse(BigInteger m)返回BigInteger,其值为(this-1mod m)。BigIntegermodPow(BigInteger exponent, BigInteger m)返回一个值为(thisexponent mod m)的BigInteger。BigIntegermultiply(BigInteger val)返回值为(this * val)的BigInteger。BigIntegernegate()返回值为(-this)的BigInteger。BigIntegernextProbablePrime()返回大于此BigInteger的第一个整数,该整数可能是素数。BigIntegernot()返回一个值为(~this)的BigInteger。BigIntegeror(BigInteger val)返回一个值为(this | val)的BigInteger。BigIntegerpow(int exponent)返回值为(thisexponent)的BigInteger。static BigIntegerprobablePrime(int bitLength, Random rnd)使用指定的bitLength返回可能为素数的正BigInteger。BigIntegerremainder(BigInteger val)返回一个值为(this % val)的BigInteger。BigIntegersetBit(int n)返回一个BigInteger,其值等于此BigInteger并设置了指定的位。BigIntegershiftLeft(int n)返回值为(this << n)的BigInteger。BigIntegershiftRight(int n)返回值为(this >> n)的BigInteger。shortshortValueExact()将此BigInteger转换为short,检查是否丢失了信息。intsignum()返回此BigInteger的signum函数。BigIntegersqrt()返回此BigInteger的整数平方根。BigInteger[]sqrtAndRemainder()返回两个BigIntegers的数组,其中包含s的整数平方根this及其余部分this - s*s。BigIntegersubtract(BigInteger val)返回值为(this - val)的BigInteger。booleantestBit(int n)当且仅当指定位置位时,返回true。byte[]toByteArray()返回一个包含此BigInteger的二进制补码表示的字节数组。StringtoString()返回此BigInteger的十进制String表示形式。StringtoString(int radix)返回给定基数中此BigInteger的String表示形式。static BigIntegervalueOf(long val)返回一个BigInteger,其值等于指定的long。BigIntegerxor(BigInteger val)返回值为(this ^ val)的BigInteger。-
声明方法的类 java.lang.Number
byteValue, shortValue
-
-
-
-
字段详细信息
-
ZERO
public static final BigInteger ZERO
BigInteger常数为零。- 从以下版本开始:
- 1.2
-
ONE
public static final BigInteger ONE
BigInteger常量一个。- 从以下版本开始:
- 1.2
-
TWO
public static final BigInteger TWO
BigInteger常数两个。- 从以下版本开始:
- 9
-
TEN
public static final BigInteger TEN
BigInteger常数十。- 从以下版本开始:
- 1.5
-
-
构造方法详细信息
-
BigInteger
public BigInteger(byte[] val, int off, int len)将包含BigInteger的二进制补码二进制表示的字节子数组转换为BigInteger。 通过数组中的偏移量和长度指定子数组。 假设子阵列是大端字节顺序:最重要的字节是索引off处的元素。 假定val数组在构造函数调用期间保持不变。 一个IndexOutOfBoundsException如果数组的长度被抛出val是非零的并且或者off是否定的,len是否定的,或off+len比的长度大val。- 参数
-
val- 包含子数组的字节数组,该子数组是BigInteger的big-endian二进制补码表示形式。 -
off- 二进制表示的起始偏移量。 -
len- 要使用的字节数。 - 异常
-
NumberFormatException-val是零字节长。 -
IndexOutOfBoundsException- 如果提供的数组偏移量和长度将导致字节数组的索引为负数或大于或等于数组长度。 - 从以下版本开始:
- 9
-
BigInteger
public BigInteger(byte[] val)
将包含BigInteger的二进制补码二进制表示的字节数组转换为BigInteger。 假设输入数组采用大端字节顺序:最重要的字节位于第0个元素中。 假定val数组在构造函数调用期间保持不变。- 参数
-
val- BigInteger的big-endian二进制补码表示形式。 - 异常
-
NumberFormatException-val是零字节长。
-
BigInteger
public BigInteger(int signum, byte[] magnitude, int off, int len)将BigInteger的符号幅度表示转换为BigInteger。 符号表示为整数符号值:-1表示负数,0表示零,或1表示正数。 幅度是big-endian字节顺序的字节数组的子数组:最高有效字节是索引off处的元素。 长度为零的值为len是允许的,并且将导致BigInteger值为0,无论signum是-1,0还是1.假定magnitude数组在构造函数调用期间保持不变。 一个IndexOutOfBoundsException如果数组的长度被抛出magnitude是非零的并且或者off是否定的,len是否定的,或off+len比的长度大magnitude。- 参数
-
signum- 数字的符号(-1表示负数,0表示零,1表示正数)。 -
magnitude- 数字大小的big-endian二进制表示。 -
off- 二进制表示的起始偏移量。 -
len- 要使用的字节数。 - 异常
-
NumberFormatException-signum不是三个合法值之一(-1,0和1),或signum为0且magnitude包含一个或多个非零字节。 -
IndexOutOfBoundsException- 如果提供的数组偏移量和长度将导致字节数组的索引为负数或大于或等于数组长度。 - 从以下版本开始:
- 9
-
BigInteger
public BigInteger(int signum, byte[] magnitude)将BigInteger的符号幅度表示转换为BigInteger。 符号表示为整数符号值:-1表示负数,0表示零,或1表示正数。 大小是big-endian字节顺序的字节数组:最重要的字节是第0个元素。 允许使用零长度数组,并且将导致BigInteger值为0,无论signum是-1,0还是1.假定magnitude数组在构造函数调用期间保持不变。- 参数
-
signum- 数字的符号(-1表示负数,0表示零,1表示正数)。 -
magnitude- 数字大小的big-endian二进制表示。 - 异常
-
NumberFormatException-signum不是三个合法值之一(-1,0和1),或signum为0且magnitude包含一个或多个非零字节。
-
BigInteger
public BigInteger(String val, int radix)
将指定基数中BigInteger的String表示形式转换为BigInteger。 字符串表示由可选的减号或加号组成,后跟指定基数中的一个或多个数字的序列。 字符到数字的映射由Character.digit提供。 字符串可能不包含任何无关的字符(例如,空格)。- 参数
-
val- BigInteger的字符串表示形式。 -
radix- 用于解释的基数val。 - 异常
-
NumberFormatException-val不是指定基数中BigInteger的有效表示形式,或radix超出Character.MIN_RADIX到Character.MAX_RADIX(包括Character.MIN_RADIX和radix)的范围。 - 另请参见:
-
Character.digit(char, int)
-
BigInteger
public BigInteger(String val)
将BigInteger的十进制字符串表示形式转换为BigInteger。 字符串表示由可选的减号后跟一个或多个十进制数字的序列组成。 字符到数字的映射由Character.digit提供。 字符串可能不包含任何无关的字符(例如,空格)。- 参数
-
val- BigInteger的十进制字符串表示形式。 - 异常
-
NumberFormatException-val不是BigInteger的有效表示形式。 - 另请参见:
-
Character.digit(char, int)
-
BigInteger
public BigInteger(int numBits, Random rnd)构造一个随机生成的BigInteger,均匀分布在0到(2numBits- 1)的范围内。 分布的一致性假设在rnd提供了公平的随机比特源。 请注意,此构造函数始终构造非负BigInteger。- 参数
-
numBits- 新BigInteger的最大bitLength。 -
rnd- 计算新BigInteger时使用的随机源。 - 异常
-
IllegalArgumentException-numBits是否定的。 - 另请参见:
-
bitLength()
-
BigInteger
public BigInteger(int bitLength, int certainty, Random rnd)使用指定的bitLength构造一个随机生成的可能为素数的正BigInteger。- API Note:
-
建议优先使用
probablePrime方法,除非有必要指定确定性。 - 参数
-
bitLength- 返回的BigInteger的bitLength。 -
certainty- 衡量呼叫者愿意容忍的不确定性的指标。 新BigInteger表示素数的概率将超过(1 - 1/2certainty)。 此构造函数的执行时间与此参数的值成比例。 -
rnd- 用于选择要测试素数的候选者的随机比特源。 - 异常
-
ArithmeticException-bitLength < 2或bitLength太大了。 - 另请参见:
-
bitLength()
-
-
方法详细信息
-
probablePrime
public static BigInteger probablePrime(int bitLength, Random rnd)
使用指定的bitLength返回可能为素数的正BigInteger。 此方法返回的BigInteger是复合的概率不超过2 -100 。- 参数
-
bitLength- 返回的BigInteger的bitLength。 -
rnd- 用于选择要测试素数的候选者的随机比特源。 - 结果
-
一个可能是素数的
bitLength位的BigInteger - 异常
-
ArithmeticException-bitLength < 2或bitLength太大了。 - 从以下版本开始:
- 1.4
- 另请参见:
-
bitLength()
-
nextProbablePrime
public BigInteger nextProbablePrime()
返回大于此BigInteger的第一个整数,该整数可能是素数。 此方法返回的数字是复合的概率不超过2 -100 。 搜索时,此方法永远不会跳过素数:如果它返回p,则没有素数q如this < q < p。- 结果
-
第一个大于
BigInteger整数,可能是素数。 - 异常
-
ArithmeticException-this < 0或this太大了。 - 从以下版本开始:
- 1.5
-
valueOf
public static BigInteger valueOf(long val)
返回一个BigInteger,其值等于指定的long。- API Note:
-
这个静态工厂方法优先于(
long)构造函数提供,因为它允许重用常用的BigIntegers。 - 参数
-
val- 要返回的BigInteger的值。 - 结果
- 具有指定值的BigInteger。
-
add
public BigInteger add(BigInteger val)
返回值为(this + val)的BigInteger。- 参数
-
val- 要添加到此BigInteger的值。 - 结果
-
this + val
-
subtract
public BigInteger subtract(BigInteger val)
返回值为(this - val)的BigInteger。- 参数
-
val- 要从此BigInteger中减去的值。 - 结果
-
this - val
-
multiply
public BigInteger multiply(BigInteger val)
返回值为(this * val)的BigInteger。- Implementation Note:
-
当实现
val == this时,实现可以提供更好的算法性能。 - 参数
-
val- 要与此BigInteger相乘的值。 - 结果
-
this * val
-
divide
public BigInteger divide(BigInteger val)
返回值为(this / val)的BigInteger。- 参数
-
val- 要分割此BigInteger的值。 - 结果
-
this / val - 异常
-
ArithmeticException- 如果val为零。
-
divideAndRemainder
public BigInteger[] divideAndRemainder(BigInteger val)
返回两个BigIntegers的数组,其中包含(this / val)后跟(this % val)。- 参数
-
val- 要分割此BigInteger的值,并计算余数。 - 结果
-
两个BigIntegers的数组:商
(this / val)是初始元素,余数(this % val)是最后一个元素。 - 异常
-
ArithmeticException- 如果val为零。
-
remainder
public BigInteger remainder(BigInteger val)
返回值为(this % val)的BigInteger。- 参数
-
val- 要分割此BigInteger的值,并计算余数。 - 结果
-
this % val - 异常
-
ArithmeticException- 如果val为零。
-
pow
public BigInteger pow(int exponent)
返回值为(thisexponent)的BigInteger。 请注意,exponent是整数而不是BigInteger。- 参数
-
exponent- 要引发此BigInteger的指数。 - 结果
-
thisexponent - 异常
-
ArithmeticException-exponent是否定的。 (这会导致操作产生非整数值。)
-
sqrt
public BigInteger sqrt()
返回此BigInteger的整数平方根。 对应的数学整数n的整数n是最大的数学整数s,使得s*s <= n。 它等于的值floor(sqrt(n)),其中sqrt(n)表示的实平方根n作为一个真正的处理。 请注意,如果后者不能表示为整数值,则整数平方根将小于实平方根。- 结果
-
整数平方根
this - 异常
-
ArithmeticException- 如果this为负数。 (负整数val是(i * sqrt(-val)),其中i是虚数单位 ,等于sqrt(-1)) - 从以下版本开始:
- 9
-
sqrtAndRemainder
public BigInteger[] sqrtAndRemainder()
返回包含整数平方根两个BigInteger的阵列s的this及其剩余this - s*s分别。- 结果
- 两个BigIntegers的数组,其中整数平方根位于偏移0处,余数位于偏移量1处
- 异常
-
ArithmeticException- 如果this为负数。 (负整数val是(i * sqrt(-val)),其中i是虚数单位 ,等于sqrt(-1)) - 从以下版本开始:
- 9
- 另请参见:
-
sqrt()
-
gcd
public BigInteger gcd(BigInteger val)
返回一个BigInteger,其值是abs(this)和abs(val)。 如果this == 0 && val == 0返回0。- 参数
-
val- 用于计算GCD的值。 - 结果
-
GCD(abs(this), abs(val))
-
abs
public BigInteger abs()
返回一个BigInteger,其值是此BigInteger的绝对值。- 结果
-
abs(this)
-
negate
public BigInteger negate()
返回值为(-this)的BigInteger。- 结果
-
-this
-
signum
public int signum()
返回此BigInteger的signum函数。- 结果
- -1,0或1,因为此BigInteger的值为负,零或正。
-
mod
public BigInteger mod(BigInteger m)
返回值为(this mod m的BigInteger。 此方法与remainder不同之处在于它始终返回非负 BigInteger。- 参数
-
m- 模数。 - 结果
-
this mod m - 异常
-
ArithmeticException-m‰0 - 另请参见:
-
remainder(java.math.BigInteger)
-
modPow
public BigInteger modPow(BigInteger exponent, BigInteger m)
返回值为(thisexponent mod m)的BigInteger。 (与pow不同,此方法允许负指数。)- 参数
-
exponent- 指数。 -
m- 模数。 - 结果
-
thisexponent mod m - 异常
-
ArithmeticException-m= 0或指数为负且此BigInteger不是 相对素数为m。 - 另请参见:
-
modInverse(java.math.BigInteger)
-
modInverse
public BigInteger modInverse(BigInteger m)
返回BigInteger,其值为(this-1mod m)。- 参数
-
m- 模数。 - 结果
-
this-1mod m。 - 异常
-
ArithmeticException-m= 0,或者这个BigInteger没有乘法逆mod m(也就是说,这个BigInteger不是m的 相对素数 )。
-
shiftLeft
public BigInteger shiftLeft(int n)
返回值为(this << n)的BigInteger。 移位距离n可以是负的,在这种情况下,该方法执行右移。 (计算floor(this * 2n))- 参数
-
n- 移位距离,以位为单位。 - 结果
-
this << n - 另请参见:
-
shiftRight(int)
-
shiftRight
public BigInteger shiftRight(int n)
返回值为(this >> n)的BigInteger。 执行签名扩展。 移位距离n可以是负的,在这种情况下该方法执行左移。 (计算floor(this / 2n))- 参数
-
n- 移位距离,以位为单位。 - 结果
-
this >> n - 另请参见:
-
shiftLeft(int)
-
and
public BigInteger and(BigInteger val)
返回值为(this & val)的BigInteger。 (当且仅当this和val都为负时,此方法返回负BigInteger。)- 参数
-
val- 与此BigInteger进行ANDval值。 - 结果
-
this & val
-
or
public BigInteger or(BigInteger val)
返回值为(this | val)的BigInteger。 (当且仅当this或val为负数时,此方法返回负BigInteger。)- 参数
-
val- 要与此BigInteger进行“或”运算的值。 - 结果
-
this | val
-
xor
public BigInteger xor(BigInteger val)
返回值为(this ^ val)的BigInteger。 (当且仅当此和val中的一个为负时,此方法返回负BigInteger。)- 参数
-
val- 与此BigInteger进行XOR的值。 - 结果
-
this ^ val
-
not
public BigInteger not()
返回值为(~this)的BigInteger。 (当且仅当此BigInteger为非负数时,此方法才返回负值。)- 结果
-
~this
-
andNot
public BigInteger andNot(BigInteger val)
返回值为(this & ~val)的BigInteger。 该方法等同于and(val.not()),是为了屏蔽操作的便利而提供的。 (当且仅当this为负且val为正时,此方法返回负BigInteger。)- 参数
-
val- 要使用此BigInteger进行补充和AND的值。 - 结果
-
this & ~val
-
testBit
public boolean testBit(int n)
当且仅当指定位置位时,返回true。 (计算((this & (1<<n)) != 0))- 参数
-
n- 要测试的位索引。 - 结果
-
true当且仅当指定位置位时。 - 异常
-
ArithmeticException-n为负数。
-
setBit
public BigInteger setBit(int n)
返回一个BigInteger,其值等于此BigInteger并设置了指定的位。 (计算(this | (1<<n)))- 参数
-
n- 要设置的位索引。 - 结果
-
this | (1<<n) - 异常
-
ArithmeticException-n是否定的。
-
clearBit
public BigInteger clearBit(int n)
返回一个BigInteger,其值等于此BigInteger且指定位已清除。 (计算(this & ~(1<<n)))- 参数
-
n- 要清除的位索引。 - 结果
-
this & ~(1<<n) - 异常
-
ArithmeticException-n为负数。
-
flipBit
public BigInteger flipBit(int n)
返回一个BigInteger,其值等于此BigInteger,并且指定的位被翻转。 (计算(this ^ (1<<n)))- 参数
-
n- 要翻转的位索引。 - 结果
-
this ^ (1<<n) - 异常
-
ArithmeticException-n为负数。
-
getLowestSetBit
public int getLowestSetBit()
返回此BigInteger中最右边(最低位)一位的索引(最右边一位右边的零位数)。 如果此BigInteger不包含任何位,则返回-1。 (计算(this == 0? -1 : log2(this & -this)))- 结果
- 此BigInteger中最右边一位的索引。
-
bitLength
public int bitLength()
返回此BigInteger的最小二进制补码表示中的位数, 不包括符号位。 对于正BigIntegers,这相当于普通二进制表示中的位数。 对于零,此方法返回0。 (计算(ceil(log2(this < 0 ? -this : this+1))))- 结果
- 此BigInteger的最小二进制补码表示中的位数, 不包括符号位。
-
bitCount
public int bitCount()
返回此BigInteger的二进制补码表示中与其符号位不同的位数。 在BigIntegers上实现位向量样式集时,此方法很有用。- 结果
- 此BigInteger的二进制补码表示中的位数与其符号位不同。
-
isProbablePrime
public boolean isProbablePrime(int certainty)
返回true如果此BigInteger可能为素数,false,如果它一定为合。 如果certainty是0,则返回true。- 参数
-
certainty- 呼叫者愿意容忍的不确定性的度量:如果呼叫返回true,则此BigInteger为素数的概率超过(1 - 1/2certainty)。 此方法的执行时间与此参数的值成比例。 - 结果
-
true如果这个BigInteger可能是素数,false如果它肯定是复合的。
-
compareTo
public int compareTo(BigInteger val)
将此BigInteger与指定的BigInteger进行比较。 对于六个布尔比较运算符(<,==,>,> =,!=,<=)中的每一个,优先考虑该方法。 建议执行这些比较的习惯用法是:(x.compareTo(y)< op >0),其中< op >是六个比较运算符之一。- Specified by:
-
compareTo,界面Comparable<BigInteger> - 参数
-
val- 将BigInteger与之比较的BigInteger。 - 结果
-
-1,0或1,因为此BigInteger在数值上小于,等于或大于
val。
-
equals
public boolean equals(Object x)
将此BigInteger与指定的Object进行相等性比较。- 重写:
-
equals,类Object - 参数
-
x- 要与此BigInteger进行比较的对象。 - 结果
-
true当且仅当指定的Object是BigInteger时,其值在数字上等于此BigInteger。 - 另请参见:
-
Object.hashCode(),HashMap
-
min
public BigInteger min(BigInteger val)
返回此BigInteger和val。- 参数
-
val- 用于计算最小值的值。 - 结果
-
BigInteger的值是BigInteger和
val较小的val。 如果它们相等,则可以返回任何一个。
-
max
public BigInteger max(BigInteger val)
返回此BigInteger和val。- 参数
-
val- 用于计算最大值的值。 - 结果
-
BigInteger的值是这个和
val较大的val。 如果它们相等,则可以返回任何一个。
-
hashCode
public int hashCode()
返回此BigInteger的哈希码。- 重写:
-
hashCode在类Object - 结果
- 此BigInteger的哈希码。
- 另请参见:
-
Object.equals(java.lang.Object),System.identityHashCode(java.lang.Object)
-
toString
public String toString(int radix)
返回给定基数中此BigInteger的String表示形式。 如果基数超出Character.MIN_RADIX至Character.MAX_RADIX(含)的范围,则默认为10(与Integer.toString的情况Integer.toString)。 使用由Character.forDigit提供的数字到字符映射,并且如果合适,则添加减号。 (此表示形式与(String, int)构造函数兼容。)- 参数
-
radix- 字符串表示的基数。 - 结果
- 给定基数中此BigInteger的字符串表示形式。
- 另请参见:
-
Integer.toString(int, int),Character.forDigit(int, int),BigInteger(java.lang.String, int)
-
toString
public String toString()
返回此BigInteger的十进制String表示形式。 使用由Character.forDigit提供的数字到字符映射,并且如果合适,则添加减号。 (此表示形式与(String)构造函数兼容,并允许使用Java的+运算符进行字符串连接。)- 重写:
-
toString在类Object - 结果
- 十进制此BigInteger的字符串表示形式。
- 另请参见:
-
Character.forDigit(int, int),BigInteger(java.lang.String)
-
toByteArray
public byte[] toByteArray()
返回一个包含此BigInteger的二进制补码表示的字节数组。 字节数组将采用big-endian字节顺序:最重要的字节位于第0个元素中。 该数组将包含表示此BigInteger所需的最小字节数,包括至少一个符号位,即(ceil((this.bitLength() + 1)/8))。 (此表示形式与(byte[])构造函数兼容。)- 结果
- 包含此BigInteger的二进制补码表示的字节数组。
- 另请参见:
-
BigInteger(byte[])
-
intValue
public int intValue()
将此BigInteger转换为int。 此转换类似于从一个基本收缩转换long到int如The Java™ Language Specification定义:如果此BigInteger太大而不适合用int,只返回低位32位。 请注意,此转换可能会丢失有关BigInteger值的总体大小的信息,并返回具有相反符号的结果。- Specified by:
-
intValue在课程Number - 结果
-
这个BigInteger转换为
int。 - 另请参见:
-
intValueExact() - See The Java™ Language Specification:
- 5.1.3缩小原始转换
-
longValue
public long longValue()
将此BigInteger转换为long。 此转换类似于从一个基本收缩转换long到int如The Java™ Language Specification定义:如果此BigInteger太大而不适合在一个long,只返回低位64位。 请注意,此转换可能会丢失有关BigInteger值的总体大小的信息,并返回具有相反符号的结果。- Specified by:
-
longValue类Number - 结果
-
这个BigInteger转换为
long。 - 另请参见:
-
longValueExact() - See The Java™ Language Specification:
- 5.1.3缩小原始转换
-
floatValue
public float floatValue()
将此BigInteger转换为float。 这种转换是类似于从基本收缩转换double到float如The Java™ Language Specification定义:如果此BigInteger有太大的幅度来表示作为float,它会被转换为Float.NEGATIVE_INFINITY或Float.POSITIVE_INFINITY适当。 请注意,即使返回值是有限的,此转换也可能会丢失有关BigInteger值精度的信息。- Specified by:
-
floatValue类Number - 结果
-
这个BigInteger转换为
float。 - See The Java™ Language Specification:
- 5.1.3缩小原始转换
-
doubleValue
public double doubleValue()
将此BigInteger转换为double。 这种转换是类似于从基本收缩转换double到float如The Java™ Language Specification定义:如果此BigInteger有太大的幅度来表示作为double,它会被转换为Double.NEGATIVE_INFINITY或Double.POSITIVE_INFINITY适当。 请注意,即使返回值是有限的,此转换也可能会丢失有关BigInteger值精度的信息。- Specified by:
-
doubleValue类Number - 结果
-
这个BigInteger转换为
double。 - See The Java™ Language Specification:
- 5.1.3缩小原始转换
-
longValueExact
public long longValueExact()
将此BigInteger转换为long,检查是否丢失了信息。 如果此BigInteger的值超出long类型的范围,则抛出ArithmeticException。- 结果
-
这个
BigInteger转换为long。 - 异常
-
ArithmeticException-如果价值this将不完全适合在long。 - 从以下版本开始:
- 1.8
- 另请参见:
-
longValue()
-
intValueExact
public int intValueExact()
将此BigInteger转换为int,检查是否丢失了信息。 如果此BigInteger的值超出int类型的范围,则抛出ArithmeticException。- 结果
-
这个
BigInteger转换为int。 - 异常
-
ArithmeticException-如果价值this将不完全适合于int。 - 从以下版本开始:
- 1.8
- 另请参见:
-
intValue()
-
shortValueExact
public short shortValueExact()
将此BigInteger转换为short,检查是否丢失了信息。 如果此BigInteger的值超出short类型的范围,则抛出ArithmeticException。- 结果
-
这个
BigInteger转换为short。 - 异常
-
ArithmeticException-如果价值this将不完全适合在short。 - 从以下版本开始:
- 1.8
- 另请参见:
-
Number.shortValue()
-
byteValueExact
public byte byteValueExact()
将此BigInteger转换为byte,检查是否丢失了信息。 如果此BigInteger的值超出byte类型的范围,则抛出ArithmeticException。- 结果
-
这个
BigInteger转换为byte。 - 异常
-
ArithmeticException-如果价值this将不完全适合在byte。 - 从以下版本开始:
- 1.8
- 另请参见:
-
Number.byteValue()
-
-