public class BigInteger extends Number implements Comparable<BigInteger>
算术运算语义完全模仿那些java的整数算术运算,定义在第三版。例如,被零除抛出一个ArithmeticException,由正产生一个负和负分(或零)余数。所有的规格有关溢出被忽略的细节,如关于大整数是一样大,要容纳一个操作的结果。
移位操作的语义扩展的java的移位运算符允许负移距。左移中的一个负移距离的右移,反之亦然。无符号右移操作符(>>>)被省略了,这个操作是没有意义的与“无限字长”抽象所提供的这类组合。
位逻辑运算的语义完全模仿那些java的位的整数操作符。二元操作符(and,or,xor)隐式执行的两个操作数较短的符号扩展到执行运算之前。
比较操作执行有符号整数比较,类似于那些通过java的关系和平等的运算符执行。
模块化的算术运算,是用来计算残留,进行幂运算,计算乘法逆元。这些方法总是返回一个非负的结果,0和(modulus - 1)之间,包容。
位操作运行在一个单一的点其操作数的二进制补码表示。如果有必要,操作数是符号扩展,以便它包含指定的位。的单点操作都可以产生从BigInteger操作在不同的签BigInteger,因为他们只会影响单位,与“无限字长”提供的抽象这类保证有无穷多的“虚拟的符号位”前每个BigInteger。
为了清晰、明了,伪代码是在使用BigInteger方法的描述。伪代码是“表达(i + j) BigInteger值对BigInteger i加的BigInteger j速记。“伪码表达(i == j)是“true若BigInteger i表示相同的值为BigInteger j速记。”类似地解释其他伪代码表达式。
在这个类中的所有方法和构造函数抛出NullPointerException当为任何输入参数传递null对象的引用。BigInteger必须支持值的范围2Integer.MAX_VALUE(独家)+ 2Integer.MAX_VALUE(独家),可以支持的值在这个范围。可能最好的值的范围是有限的,可能是比全负载范围BigInteger阳性。范围必须至少为1 2五亿。
ArithmeticException时扔出来的结果是支持的范围- 2
Integer.MAX_VALUE(独家)+ 2
Integer.MAX_VALUE(独家)。
BigDecimal,
Serialized Form
| Modifier and Type | Field and Description |
|---|---|
static BigInteger |
ONE
BigInteger恒一。
|
static BigInteger |
TEN
BigInteger常数十。
|
static BigInteger |
ZERO
BigInteger恒为零。
|
| Constructor and Description |
|---|
BigInteger(byte[] val)
将含有二进制补码二进制表示BigInteger为BigInteger的字节数组。
|
BigInteger(int signum, byte[] magnitude)
翻译BigInteger的符号数值表示法为BigInteger。
|
BigInteger(int bitLength, int certainty, Random rnd)
构建了一个随机产生的积极BigInteger可能是素数,用指定的个位长度。
|
BigInteger(int numBits, Random rnd)
构建了一个随机生成的BigInteger,均匀地分布在范围0到(2
numBits - 1),包括。
|
BigInteger(String val)
翻译BigInteger的十进制字符串表示为BigInteger。
|
BigInteger(String val, int radix)
将在指定的基数BigInteger的字符串表示形式为BigInteger。
|
| Modifier and Type | Method and Description |
|---|---|
BigInteger |
abs()
返回的值BigInteger是BigInteger的绝对值。
|
BigInteger |
add(BigInteger val)
返回的值是
(this + val) BigInteger。
|
BigInteger |
and(BigInteger val)
返回的值是
(this & val) BigInteger。
|
BigInteger |
andNot(BigInteger val)
返回的值是
(this & ~val) BigInteger。
|
int |
bitCount()
返回在补码表示这个BigInteger不同于其符号位的比特数。
|
int |
bitLength()
返回最小的二进制补码表示这个BigInteger的比特数,不包括符号位。
|
byte |
byteValueExact()
将这一
byte
BigInteger,检查丢失的信息。
|
BigInteger |
clearBit(int n)
返回一个BigInteger其值等效于这个BigInteger与指定点清除。
|
int |
compareTo(BigInteger val)
这个BigInteger与指定BigInteger比较。
|
BigInteger |
divide(BigInteger val)
返回的值是
(this / val) BigInteger。
|
BigInteger[] |
divideAndRemainder(BigInteger val)
返回两个关于大整数包含
(this / val)随后
(this % val)数组。
|
double |
doubleValue()
将这一
double BigInteger。
|
boolean |
equals(Object x)
这与平等BigInteger指定对象比较。
|
BigInteger |
flipBit(int n)
返回一个BigInteger其值等效于这个BigInteger与指定的位翻转。
|
float |
floatValue()
将这一
float BigInteger。
|
BigInteger |
gcd(BigInteger val)
返回的值是
abs(this) BigInteger和
abs(val)最大公约数。
|
int |
getLowestSetBit()
返回最右边的指数(低级)在BigInteger这一点(在最右边的一位右零比特数)。
|
int |
hashCode()
返回此BigInteger的哈希代码。
|
int |
intValue()
BigInteger将这一
int。
|
int |
intValueExact()
将这一
int
BigInteger,检查丢失的信息。
|
boolean |
isProbablePrime(int certainty)
返回
true如果这很可能就是BigInteger总理,
false如果它肯定复合。
|
long |
longValue()
将这一
long BigInteger。
|
long |
longValueExact()
将这一
long
BigInteger,检查丢失的信息。
|
BigInteger |
max(BigInteger val)
返回此BigInteger和
val最大。
|
BigInteger |
min(BigInteger val)
返回此BigInteger和
val最小。
|
BigInteger |
mod(BigInteger m)
返回一个BigInteger的价值
(this mod m)。
|
BigInteger |
modInverse(BigInteger m)
返回的值是
(this
- 1
mod m) BigInteger。
|
BigInteger |
modPow(BigInteger exponent, BigInteger m)
返回的值是
(thisexponent mod m) BigInteger。
|
BigInteger |
multiply(BigInteger val)
返回的值是
(this * val) BigInteger。
|
BigInteger |
negate()
返回的值是
(-this) BigInteger。
|
BigInteger |
nextProbablePrime()
返回第一个整数大于这个
BigInteger可能是素数。
|
BigInteger |
not()
返回的值是
(~this) BigInteger。
|
BigInteger |
or(BigInteger val)
返回的值是
(this | val) BigInteger。
|
BigInteger |
pow(int exponent)
返回的值是
(thisexponent) BigInteger。
|
static BigInteger |
probablePrime(int bitLength, Random rnd)
返回一个正的BigInteger可能是素数,用指定的个位长度。
|
BigInteger |
remainder(BigInteger val)
返回的值是
(this % val) BigInteger。
|
BigInteger |
setBit(int n)
返回一个BigInteger其值等效于这个BigInteger与指定的点集。
|
BigInteger |
shiftLeft(int n)
返回的值是
(this << n) BigInteger。
|
BigInteger |
shiftRight(int n)
返回的值是
(this >> n) BigInteger。
|
short |
shortValueExact()
将这一
short
BigInteger,检查丢失的信息。
|
int |
signum()
返回此BigInteger的符号函数。
|
BigInteger |
subtract(BigInteger val)
返回的值是
(this - val) BigInteger。
|
boolean |
testBit(int n)
返回
true当且仅当指定的位设置。
|
byte[] |
toByteArray()
返回一个包含此BigInteger的二进制补码表示的字节数组。
|
String |
toString()
返回此BigInteger十进制字符串表示形式。
|
String |
toString(int radix)
返回在给定的基本BigInteger的字符串表示形式。
|
static BigInteger |
valueOf(long val)
返回一个BigInteger其值等于指定的
long。
|
BigInteger |
xor(BigInteger val)
返回的值是
(this ^ val) BigInteger。
|
byteValue, shortValuepublic static final BigInteger ZERO
public static final BigInteger ONE
public static final BigInteger TEN
public BigInteger(byte[] val)
val -大端二进制补码二进制表示BigInteger。
NumberFormatException -
val是零字节。
public BigInteger(int signum,
byte[] magnitude)
signum -数字符号(- 1为阴性,0为零,1为阳性)。
magnitude -大小的数量级的二进制表示。
NumberFormatException -
signum不是三个法律价值(1,0,1),或
signum 0和
magnitude包含一个或多个非零字节。
public BigInteger(String val, int radix)
Character.digit。字符串不能包含任何多余的字符(空格,例如)。
val - BigInteger的字符串表示形式。
radix基被用于解释
val。
NumberFormatException -
val不是在指定的基数BigInteger的有效表达,或是从外面来
radix
Character.MIN_RADIX
Character.MAX_RADIX范围,包括。
Character.digit(char, int)
public BigInteger(String val)
Character.digit。字符串不能包含任何多余的字符(空格,例如)。
val - BigInteger十进制字符串表示形式。
NumberFormatException -
val不是BigInteger合法表示。
Character.digit(char, int)
public BigInteger(int numBits,
Random rnd)
numBits - 1),包括。分布的均匀性假设,一个公平的随机位源设置在
rnd。注意,这个构造函数总是构造一个非负的BigInteger。
numBits --新BigInteger最大个位长度。
rnd -随机源是用于计算新的BigInteger。
IllegalArgumentException -
numBits是负的。
bitLength()
public BigInteger(int bitLength,
int certainty,
Random rnd)
建议probablePrime方法优先使用此构造函数,除非有迫切需要指定一个确定的。
bitLength -返回BigInteger个位长度。
certainty -衡量的,打电话的人是愿意容忍不确定性。这一新的BigInteger代表一个素数将超越概率(1 - 1 / 2
certainty)。此构造函数的执行时间与此参数的值成正比。
rnd -随机位用于选择候选人进行素性源。
ArithmeticException -
bitLength < 2或
bitLength太大。
bitLength()
public static BigInteger probablePrime(int bitLength, Random rnd)
bitLength -返回BigInteger个位长度。
rnd -随机位用于选择候选人进行素性源。
bitLength位可能是最好的
ArithmeticException -
bitLength < 2或
bitLength太大。
bitLength()
public BigInteger nextProbablePrime()
BigInteger可能是素数。数,该方法返回的是复合的概率不超过2
- 100。这种方法不会跳过一个素数搜索时:如果它返回
p,没有总理
q这样
this < q < p。
BigInteger可能是素数。
ArithmeticException -
this < 0或
this太大。
public static BigInteger valueOf(long val)
long。这种“静态工厂方法”是优先设置(
long)构造函数,因为它允许重用常用的关于大整数。
val BigInteger返回值。
public BigInteger add(BigInteger val)
(this + val) BigInteger。
val值被添加到这个BigInteger。
this + val
public BigInteger subtract(BigInteger val)
(this - val) BigInteger。
val值是从这个BigInteger减去。
this - val
public BigInteger multiply(BigInteger val)
(this * val) BigInteger。
val值被乘以这个BigInteger。
this * val
public BigInteger divide(BigInteger val)
(this / val) BigInteger。
val值由BigInteger分。
this / val
ArithmeticException -如果
val是零。
public BigInteger[] divideAndRemainder(BigInteger val)
(this / val)随后
(this % val)数组。
val值由BigInteger分,而其余的计算。
(this / val)是第一要素,而其余的
(this % val)是最后的元素。
ArithmeticException -如果
val是零。
public BigInteger remainder(BigInteger val)
(this % val) BigInteger。
val值由BigInteger分,而其余的计算。
this % val
ArithmeticException -如果
val是零。
public BigInteger pow(int exponent)
exponent是整数而不是BigInteger。
exponent指数,这是BigInteger复活。
ArithmeticException -
exponent是负的。(这将导致操作产生一个非整数值。)
public BigInteger gcd(BigInteger val)
abs(this) BigInteger和
abs(val)最大公约数。返回0,如果
this == 0 && val == 0。
val值与GCD是要计算。
GCD(abs(this), abs(val))
public BigInteger abs()
abs(this)
public BigInteger negate()
(-this) BigInteger。
-this
public int signum()
public BigInteger mod(BigInteger m)
(this mod m)。这种方法不同于
remainder,它总是返回一个非负BigInteger。
m -模。
this mod m
ArithmeticException -
m≤0
remainder(java.math.BigInteger)
public BigInteger modPow(BigInteger exponent, BigInteger m)
pow,这种方法允许负指数。)
exponent -指数。
m -模。
ArithmeticException -
m≤0或指数是负的,这不是BigInteger互质到
m。
modInverse(java.math.BigInteger)
public BigInteger modInverse(BigInteger m)
(this
- 1
mod m) BigInteger。
m -模。
this
- 1
mod m。
ArithmeticException -
m≤0,或者BigInteger没有乘法逆模M(就是这个BigInteger是不是互质M)。
public BigInteger shiftLeft(int n)
(this << n) BigInteger。移动的距离,
n,可能是负的,在这种情况下,此方法执行右移。(计算
floor(this * 2n)。)
n移距离,位。
this << n
shiftRight(int)
public BigInteger shiftRight(int n)
(this >> n) BigInteger。进行符号扩展。移动的距离,
n,可能是负的,在这种情况下,此方法执行左移。(计算
floor(this / 2n)。)
n移距离,位。
this >> n
shiftLeft(int)
public BigInteger and(BigInteger val)
(this & val) BigInteger。(如果这和价值都是负的。此方法返回一个负的BigInteger)
val值是and'ed这个BigInteger。
this & val
public BigInteger or(BigInteger val)
(this | val) BigInteger。(如果不是这个或价值是负的。此方法返回一个负的BigInteger)
val值是or'ed这个BigInteger。
this | val
public BigInteger xor(BigInteger val)
(this ^ val) BigInteger。(如果是一本和Val是负的。此方法返回一个负的BigInteger)
val值是xor'ed这个BigInteger。
this ^ val
public BigInteger not()
(~this) BigInteger。(如果BigInteger是非负的。此方法返回一个负值)
~this
public BigInteger andNot(BigInteger val)
(this & ~val) BigInteger。这种方法,这相当于
and(val.not()),设置为屏蔽操作方便。(如果
this是负的,
val阳性。此方法返回一个负的BigInteger)
val值加以补充和and'ed这个BigInteger。
this & ~val
public boolean testBit(int n)
true当且仅当指定的位设置。(计算
((this & (1<<n)) != 0)。)
n指数位测试。
true当且仅当指定的位设置。
ArithmeticException -
n是负的。
public BigInteger setBit(int n)
(this | (1<<n))。)
n指数位设置。
this | (1<<n)
ArithmeticException -
n是负的。
public BigInteger clearBit(int n)
(this & ~(1<<n))。)
n指数位明确。
this & ~(1<<n)
ArithmeticException -
n是负的。
public BigInteger flipBit(int n)
(this ^ (1<<n))。)
n指数位翻转。
this ^ (1<<n)
ArithmeticException -
n是负的。
public int getLowestSetBit()
(this == 0? -1 : log2(this & -this))。)
public int bitLength()
(ceil(log2(this < 0 ? -this : this+1)))。)
public int bitCount()
public boolean isProbablePrime(int certainty)
true如果这很可能就是BigInteger总理,
false如果它肯定复合。如果
certainty是≤0,
true返回。
certainty -衡量的,打电话的人是愿意容忍不确定性:如果调用返回的概率,这
true BigInteger总理超过(1 - 1 / 2
certainty)。此方法的执行时间与此参数的值成正比。
true如果BigInteger可能是素数,
false如果它肯定复合。
public int compareTo(BigInteger val)
(x.compareTo(y) < >
0) OP,OP>,<六个比较运算符。
compareTo 接口
Comparable<BigInteger>
val - BigInteger这BigInteger做比较。
val。
public boolean equals(Object x)
equals 方法重写,继承类
Object
x对象,这个BigInteger是比较。
true当且仅当指定的对象是一个BigInteger值在数值上等于这个BigInteger。
Object.hashCode(),
HashMap
public BigInteger min(BigInteger val)
val最小。
val值,最小的是计算机。
val较小。如果他们是平等的,要么可能会回来。
public BigInteger max(BigInteger val)
val最大。
val值与最大值被计算。
val大。如果他们是平等的,要么可能会回来。
public int hashCode()
hashCode 方法重写,继承类
Object
Object.equals(java.lang.Object),
System.identityHashCode(java.lang.Object)
public String toString(int radix)
Character.MIN_RADIX到
Character.MAX_RADIX包容的范围,它将默认为10(如
Integer.toString案例)。数字字符映射提供
Character.forDigit使用,和一个减号前面是否合适。(这表示与
(String, int)构造函数。兼容)
radix -字符串表示的基。
Integer.toString(int, int),
Character.forDigit(int, int),
BigInteger(java.lang.String, int)
public String toString()
Character.forDigit使用,和一个减号前面是否合适。(这表示与
(String)构造函数,兼容,允许与java的字符串串联运算符。)
toString 方法重写,继承类
Object
Character.forDigit(int, int),
BigInteger(java.lang.String)
public byte[] toByteArray()
(ceil((this.bitLength() + 1)/8))。(这表示与
(byte[])构造函数。兼容)
BigInteger(byte[])
public int intValue()
int。这种转换是从一个类似于
long缩小基本转换到
int在
The Java™ Language Specification第定义:如果BigInteger太大,装在一个
int,只返回低阶32位。请注意,这种转换也能返回一个具有相反的符号结果失去对BigInteger值总体数量信息。
intValue 方法重写,继承类
Number
int。
intValueExact()
public long longValue()
long BigInteger。这种转换是从一个类似于
long缩小基本转换到
int在
The Java™ Language Specification第定义:如果BigInteger太大,适合在一个
long,只返回低阶64位。请注意,这种转换也能返回一个具有相反的符号结果失去对BigInteger值总体数量信息。
longValue 方法重写,继承类
Number
long。
longValueExact()
public float floatValue()
float BigInteger。这种转换是类似的缩小基本转换从
double到
float在
The Java™ Language Specification第定义:如果BigInteger有太大的值代表一个
float,它将被转换为
Float.NEGATIVE_INFINITY或
Float.POSITIVE_INFINITY适当。请注意,即使当返回值是有限的,这种转换可能会丢失对BigInteger值的精度信息。
floatValue 方法重写,继承类
Number
float。
public double doubleValue()
double BigInteger。这种转换是类似的缩小基本转换从
double到
float在
The Java™ Language Specification第定义:如果BigInteger有太大的值代表一个
double,它将被转换为
Double.NEGATIVE_INFINITY或
Double.POSITIVE_INFINITY适当。请注意,即使当返回值是有限的,这种转换可能会丢失对BigInteger值的精度信息。
doubleValue 方法重写,继承类
Number
double。
public long longValueExact()
long
BigInteger,检查丢失的信息。如果这
BigInteger值从
long类型的范围,然后
ArithmeticException抛出。
BigInteger转换为
long。
ArithmeticException -如果
this价值将不适合在
long。
longValue()
public int intValueExact()
int
BigInteger,检查丢失的信息。如果这
BigInteger值从
int类型的范围,然后
ArithmeticException抛出。
BigInteger转换为
int。
ArithmeticException -如果
this价值将不适合在
int。
intValue()
public short shortValueExact()
short
BigInteger,检查丢失的信息。如果这
BigInteger值从
short类型的范围,然后
ArithmeticException抛出。
BigInteger转换为
short。
ArithmeticException -如果
this价值将不适合在
short。
Number.shortValue()
public byte byteValueExact()
byte
BigInteger,检查丢失的信息。如果这
BigInteger值从
byte类型的范围,然后
ArithmeticException抛出。
BigInteger转换为
byte。
ArithmeticException -如果
this价值将不适合在
byte。
Number.byteValue()
Submit a bug or feature
For further API reference and developer documentation, see Java SE Documentation. That documentation contains more detailed, developer-targeted descriptions, with conceptual overviews, definitions of terms, workarounds, and working code examples.
Copyright © 1993, 2014, Oracle and/or its affiliates. All rights reserved.