- java.lang.Object
-
- java.lang.Number
-
- java.math.BigInteger
-
- All Implemented Interfaces:
-
Serializable,Comparable<BigInteger>
public class BigInteger extends Number implements Comparable<BigInteger>
不可变的任意精度整数。 所有操作的行为就好像BigIntegers以二进制补码表示(如Java的原始整数类型)表示。 BigInteger提供了所有Java的原始整数运算符和java.lang.Math中所有相关方法的类比。 此外,BigInteger还提供了模数运算,GCD计算,原始测试,初级生成,位操作以及其他一些其他操作的操作。算术运算的语义完全模仿Java的整数运算符,如Java语言规范中定义的那样。 例如,除以零,抛出一个
ArithmeticException,并且一个负数除以一个正数产生负数(或零)余数。 Spec中关于溢出的所有细节都将被忽略,因为BigInteger是必要的,以适应操作的结果。移位操作的语义扩展了Java的移位运算符,以允许负移位距离。 具有负移位距离的右移导致左移,反之亦然。 未签名的右移位运算符(
>>>)被省略,因为该操作与由该类提供的“无限字大小”抽象结合很少。按位逻辑运算的语义完全模仿Java的按位整数运算符。 二进制运算符(
and,or,xor)隐式地对两个操作数的较短执行操作之前执行符号扩展。比较操作执行带符号的整数比较,类似于Java关系和等式运算符执行的整数比较。
提供模块化算术运算以计算残差,执行取幂和计算乘法反转。 这些方法总是返回一个非负的结果,包括
0和(modulus - 1)之间。位操作对其操作数的二进制补码表示的一位进行操作。 如有必要,操作数将被扩展,以便它包含指定的位。 没有一个单位操作可以产生一个BigInteger,它与正在操作的BigInteger具有不同的符号,因为它们只影响一个位,并且此类提供的“无限大小”抽象确保了无限多的“虚拟每个BigInteger之前的符号位“。
为了简洁起见,在整个BigInteger方法的描述中都使用伪代码。 伪代码表达式
(i + j)是“BigInteger的缩写,它的值是BigIntegeri加上BigIntegerj。 如果且仅当BigIntegeri表示与BigIntegeri相同的值时,伪代码表达式(i == j)是“true”的j。 类似地解释其他伪代码表达式。当传递任何输入参数的空对象引用时,此类中的所有方法和构造函数抛出
NullPointerException。 BigInteger必须支持-2Integer.MAX_VALUE(排他)范围内的值到+2Integer.MAX_VALUE(排他),并且可以支持该范围之外的值。 可能的素数值的范围是有限的,可能小于完全支持的正值范围BigInteger。 范围必须至少为1到2.5 亿 。- Implementation Note:
-
当BigInteger构造函数和操作抛出
ArithmeticException时,结果超出了支持的范围-2Integer.MAX_VALUE(排他)到+2Integer.MAX_VALUE(排他)。 - 从以下版本开始:
- 1.1
- 另请参见:
-
BigDecimal, Serialized Form - See The Java™ Language Specification:
- 4.2.2整数运算
-
-
Field Summary
Fields Modifier and Type Field 描述 static BigIntegerONEBigInteger常数。static BigIntegerTENBigInteger常数十。static BigIntegerTWOBigInteger常数二。static BigIntegerZEROBigInteger常数为零。
-
构造方法摘要
构造方法 Constructor 描述 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)构造一个随机生成的正BigInteger,它可能是素数,具有指定的bitLength。BigInteger(int numBits, Random rnd)构造一个随机生成的BigInteger,均匀分布在0到(2numBits- 1)的范围内。BigInteger(String val)将BigInteger的十进制字符串表示形式转换为BigInteger。BigInteger(String val, int radix)将指定基数中的BigInteger的String表示形式转换为BigInteger。
-
方法摘要
所有方法 静态方法 接口方法 具体的方法 Modifier and Type 方法 描述 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)返回两个BigInteger的数组,其中包含(this / val)后跟(this % val)。doubledoubleValue()将此BigInteger转换为double。booleanequals(Object x)将此BigInteger与指定的对象进行比较以实现相等。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)返回值为(this-1mod m)的BigInteger。BigIntegermodPow(BigInteger exponent, BigInteger m)返回值为(thisexponent mod m)的BigInteger。BigIntegermultiply(BigInteger val)返回值为(this * val)的BigInteger。BigIntegernegate()返回值为(-this)的BigInteger。BigIntegernextProbablePrime()返回大于此BigInteger的第一个整数BigInteger。BigIntegernot()返回值为(~this)的BigInteger。BigIntegeror(BigInteger val)返回值为(this | val)的BigInteger。BigIntegerpow(int exponent)返回值为(thisexponent)的BigInteger。static BigIntegerprobablePrime(int bitLength, Random rnd)返回一个正的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()返回两个BigInteger的数组,它们分别包含s的整数平方根this及其余数this - s*s。BigIntegersubtract(BigInteger val)返回值为(this - val)的BigInteger。booleantestBit(int n)当且仅当指定的位被置位时,返回true。byte[]toByteArray()返回一个包含此BigInteger的二进制补码表示的字节数组。StringtoString()返回此BigInteger的十进制字符串表示形式。StringtoString(int radix)返回给定基数中BigInteger的String表示形式。static BigIntegervalueOf(long val)返回一个BigInteger,其值等于指定的long。BigIntegerxor(BigInteger val)返回值为(this ^ val)的BigInteger。-
Methods inherited from class 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。 输入数组被假定为大字节顺序:最高有效字节在第零个元素中。 假设在构造函数调用的持续时间内,val数组是不变的。- 参数
-
val- BigInteger的big-endian二进制补码二进制表示法。 - 异常
-
NumberFormatException-val为零字节长。
-
BigInteger
public BigInteger(int signum, byte[] magnitude, int off, int len)将BigInteger的符号大小表示形式转换为BigInteger。 符号表示为整数值:-1表示负数,0表示零,或表示1表示正数。 幅度是大字节序列中的字节数组的子阵列:最高有效字节是索引off处的元素。 长度为len零值是允许的,并且将导致BigInteger值为0,无论signum为-1,0还是1.在构造函数调用期间,假定magnitude数组不变。 一个IndexOutOfBoundsException如果数组的长度被抛出magnitude是非零的并且或者off是否定的,len为负,或者off+len比的长度大magnitude。- 参数
-
signum- 数字的符号(-1为负,0为零,1为正)。 -
magnitude- 大端二进制表示的数量的大小。 -
off- 二进制表示的起始偏移量。 -
len- 要使用的字节数。 - 异常
-
NumberFormatException-signum不是三个合法值(-1,0和1)之一,或signum为0,而magnitude包含一个或多个非零字节。 -
IndexOutOfBoundsException- 如果提供的数组偏移量和长度将导致字节数组中的索引为负数或大于或等于数组长度。 - 从以下版本开始:
- 9
-
BigInteger
public BigInteger(int signum, byte[] magnitude)将BigInteger的符号大小表示形式转换为BigInteger。 符号表示为整数值:-1表示负数,0表示零,或表示1表示正数。 幅度是大字节字节顺序的字节数组:最高有效字节是第零个元素。 零长度幅度阵列是允许的,并且将导致BigInteger值为0,无论signum为-1,0还是1.在构造函数调用的持续时间内假定magnitude数组不变。- 参数
-
signum- 数字的符号(-1表示负数,0表示零,1表示正数)。 -
magnitude- 大端二进制表示的数量的大小。 - 异常
-
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.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)的范围内。 分布的均匀性假设在rnd提供了公平的随机比特rnd。 注意,这个构造函数总是构造一个非负的BigInteger。- 参数
-
numBits- 新BigInteger的最大位长度。 -
rnd- 用于计算新BigInteger的随机源。 - 异常
-
IllegalArgumentException-numBits为负数。 - 另请参见:
-
bitLength()
-
BigInteger
public BigInteger(int bitLength, int certainty, Random rnd)构造一个随机生成的正BigInteger,它可能是素数,具有指定的bitLength。- 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)
返回一个正的BigInteger,它可能是素数,具有指定的位长度。 BigInteger通过此方法返回的概率是复合的不超过2 -100 。- 参数
-
bitLength- 返回的BigInteger的bitLength。 -
rnd- 用于选择要测试原始候选人的随机比特来源。 - 结果
-
一个BigInteger的
bitLength位,这可能是首要的 - 异常
-
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)构造函数,因为它允许重用常用的BigInteger。 - 参数
-
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)
返回两个BigInteger的数组,其中包含(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。- 结果
- 两个BigInteger的数组,其中偏移量为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 - 另请参见:
-
remainder(java.math.BigInteger)
-
modPow
public BigInteger modPow(BigInteger exponent, BigInteger m)
返回值为(thisexponent mod m)的BigInteger。 (与pow不同,此方法允许负指数。)- 参数
-
exponent- 指数。 -
m- 模数。 - 结果
-
thisexponent mod m - 异常
-
ArithmeticException-m0或指数为负,而此BigInteger不是m主要m。 - 另请参见:
-
modInverse(java.math.BigInteger)
-
modInverse
public BigInteger modInverse(BigInteger m)
返回一个BigInteger,其值为(this-1mod m)。- 参数
-
m- 模数。 - 结果
-
this-1mod m。 - 异常
-
ArithmeticException-m0,或者这个BigInteger没有乘法逆模态(即,这个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。 (这个方法返回一个负的BigInteger,当且仅当这个和val都是负的。)- 参数
-
val- 值与此BigInteger进行ANDval。 - 结果
-
this & val
-
or
public BigInteger or(BigInteger val)
返回值为(this | val)的BigInteger。 (当且仅当这个或val是负数时,此方法返回一个负的BigInteger。)- 参数
-
val- 要与此BigInteger进行ORval值。 - 结果
-
this | val
-
xor
public BigInteger xor(BigInteger val)
返回值为(this ^ val)的BigInteger。 (当且仅当这个和val中的一个为负时,该方法返回一个负的BigInteger。)- 参数
-
val- 值将与此BigInteger异或。 - 结果
-
this ^ val
-
not
public BigInteger not()
返回值为(~this)的BigInteger。 (当且仅当BigInteger为非负值时,此方法返回负值。)- 结果
-
~this
-
andNot
public BigInteger andNot(BigInteger val)
返回值为(this & ~val)的BigInteger。 该方法等同于and(val.not()),作为掩蔽操作的便利。 (当且仅当this为负数时,此方法返回负BigInteger,而val为正)。- 参数
-
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的最小二进制补码表示中的位数, 不包括符号位。 对于正的BigInteger,这相当于普通二进制表示中的位数。 (计算(ceil(log2(this < 0 ? -this : this+1))))- 结果
- 该BigInteger的最小二进制补码表示中的位数, 不包括符号位。
-
bitCount
public int bitCount()
返回与其符号位不同的BigInteger的二进制补码表示中的位数。 当在BigInteger上面实现位矢量样式集时,此方法非常有用。- 结果
- 该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与指定的对象进行比较以实现相等。- 重写:
-
equals在Object - 参数
-
x- 要比较BigInteger的对象。 - 结果
-
true如果且仅当指定的对象是BigInteger,其值在数字上等于该BigInteger。 - 另请参见:
-
Object.hashCode(),HashMap
-
min
public BigInteger min(BigInteger val)
返回此BigInteger和val。- 参数
-
val- 要计算最小值的值。 - 结果
-
BigInteger的值是该BigInteger和
val的较小者。 如果他们相等,可以退还。
-
max
public BigInteger max(BigInteger val)
返回此BigInteger和val。- 参数
-
val- 要计算最大值的值。 - 结果
-
BigInteger的值是这个和
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)。 使用由Character.forDigit提供的数字到字符映射,如果合适,则使用减号。 (此表示与(String, int)构造函数兼容。)- 参数
-
radix- 字符串表示的基数。 - 结果
- 此BigInteger在给定基数中的字符串表示形式。
- 另请参见:
-
Integer.toString(int, int),Character.forDigit(int, int),BigInteger(java.lang.String, int)
-
toString
public String toString()
返回此BigInteger的十进制字符串表示形式。 使用Character.forDigit提供的数字到字符映射,如果合适,则添加减号。 (该表示与(String)构造函数兼容,并允许使用Java +运算符进行字符串连接。)- 重写:
-
toString在Object - 结果
- decimal这个BigInteger的字符串表示形式。
- 另请参见:
-
Character.forDigit(int, int),BigInteger(java.lang.String)
-
toByteArray
public byte[] toByteArray()
返回一个包含此BigInteger的二进制补码表示的字节数组。 字节数组将以大字节顺序排列:最高字节位于第零个元素中。 该数组将包含表示此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()
-
-