public class BigInteger extends Number implements Comparable<BigInteger>
算術演算のセマンティクスは、『Java 言語仕様』に定義されているように Java の整数算術演算子を正確に模倣します。たとえば、ゼロ除算は ArithmeticException をスローし、正の数による負の数の除算は負 (または 0) の剰余を出します。オーバーフローに関する仕様内の詳細はすべて無視され、BigInteger は演算の結果の受け入れに必要なだけ大きくなります。
シフト演算のセマンティクスは、負のシフト移動量を可能にするため Java のシフト演算子を拡張しています。負のシフト移動量を持つ右シフトは左シフトとなります。 逆の場合も同じです。符号なしの右シフト演算子 (>>>) は、この演算ではこのクラスが提供する「無限のワードサイズ」抽出と組み合わせる意味がほとんどないため省かれています。
ビット単位の論理演算のセマンティクスは、Java のビット整数演算子のセマンティクスを正確に模倣しています。2 項演算子 (and、or、xor) は、演算前に 2 つのオペランドの短い方に対して暗黙的に符号拡張を行います。
比較演算は符号付き整数の比較を行います。これは、Java の関連する演算子および同等の演算子により行われるものと同じです。
モジュラ算術演算は、剰余計算、べき乗、および乗法逆数計算のために提供されています。これらのメソッドは、常に 0 と (modulus - 1) の間の負でない結果を返します。
ビット演算は、オペランドの 2 の補数表現のシングルビットに使用します。必要に応じて、オペランドの符号は指示するビットを持つように拡張されます。演算中の BigInteger と異なる符号を持つ BigInteger を生成するシングルビット演算はありません。これは、シングルビット演算が単一のビットにだけ影響し、このクラスが提供する「無限のワードサイズ」抽出によって、各 BigInteger に先行する無限の「仮想符号ビット」が存在するためです。
説明をわかりやすく簡潔にするために、BigInteger メソッドの説明では全体を通して擬似コードを使用します。擬似コード式 (i + j) は、「値が BigInteger i の値と BigInteger j の値の和である BigInteger」を示します。擬似コード式 (i == j) は、「BigInteger i が BigInteger j と同じ値を表す場合にだけ true であること」を示します。ほかの擬似コード式も同じように解釈されます。
このクラスのメソッドおよびコンストラクタはすべて、入力パラーメータに対して null オブジェクト参照が渡されると NullPointerException をスローします。
BigDecimal、直列化された形式| 修飾子と型 | フィールドと説明 |
|---|---|
static BigInteger |
ONE
BigInteger 定数 1 です。
|
static BigInteger |
TEN
BigInteger 定数 10 です。
|
static BigInteger |
ZERO
BigInteger 定数 0 です。
|
| コンストラクタと説明 |
|---|
BigInteger(byte[] val)
BigInteger の 2 の補数 2 進表現を含むバイト配列を BigInteger に変換します。
|
BigInteger(int signum, byte[] magnitude)
BigInteger の符号絶対値表現を BigInteger に変換します。
|
BigInteger(int bitLength, int certainty, Random rnd)
ランダムに生成された (おそらく素数である) 正の BigInteger を、指定したビット長で構築します。
|
BigInteger(int numBits, Random rnd)
0 - (2
numBits - 1) の範囲に一様に分散されている、ランダムに生成された BigInteger を構築します。 |
BigInteger(String val)
BigInteger の 10 進 String 表現を BigInteger に変換します。
|
BigInteger(String val, int radix)
指定された基数内の BigInteger の String 表現を BigInteger に変換します。
|
| 修飾子と型 | メソッドと説明 |
|---|---|
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 の 2 の補数表現内の、符号ビットと異なるビットの数を返します。
|
int |
bitLength()
この BigInteger の最小の 2 の補数表現内のビット数を返します。ただし、符号ビットを除きます。
|
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) と続く、2 つの BigInteger の配列を返します。 |
double |
doubleValue()
この BigInteger を
double に変換します。 |
boolean |
equals(Object x)
この BigInteger と指定された Object が等しいかどうかを比較します。
|
BigInteger |
flipBit(int n)
値がこの BigInteger に等しい BigInteger を、指定されたビットを反転させて返します。
|
float |
floatValue()
この BigInteger を
float に変換します。 |
BigInteger |
gcd(BigInteger val)
値が
abs(this) と abs(val) の最大公約数である BigInteger を返します。 |
int |
getLowestSetBit()
この BigInteger のもっとも右側 (1 番低い位) の 1 ビットのインデックス (もっとも右側の 1 ビットの右方向の 0 ビットの数) を返します。
|
int |
hashCode()
この BigInteger のハッシュコードを返します。
|
int |
intValue()
この BigInteger を
int に変換します。 |
boolean |
isProbablePrime(int certainty)
この BigInteger が素数である可能性が高い場合は
true、必ず合成数である場合は false を返します。 |
long |
longValue()
この BigInteger を
long に変換します。 |
BigInteger |
max(BigInteger val)
この BigInteger と
val の最大値を返します。 |
BigInteger |
min(BigInteger val)
この BigInteger と
val の最小値を返します。 |
BigInteger |
mod(BigInteger m)
値が
(this mod m) である BigInteger を返します。 |
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 を返します。 |
int |
signum()
この BigInteger の符号要素を返します。
|
BigInteger |
subtract(BigInteger val)
値が
(this - val) である BigInteger を返します。 |
boolean |
testBit(int n)
指定されたビットが設定されている場合にだけ
true を返します。 |
byte[] |
toByteArray()
この BigInteger の 2 の補数表現を含むバイト配列を返します。
|
String |
toString()
この BigInteger の 10 進 String 表現を返します。
|
String |
toString(int radix)
指定された基数内のこの BigInteger の String 表現を返します。
|
static BigInteger |
valueOf(long val)
値が指定された
long の値と等しい BigInteger を返します。 |
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 の、ビックエンディアン 2 の補数バイナリ表現。NumberFormatException - val の長さが 0 バイトの場合。public BigInteger(int signum,
byte[] magnitude)
signum - 数字の符号 (負は -1、ゼロは 0、正は 1)。magnitude - 数字の絶対値のビックエンディアンバイナリ表現。NumberFormatException - signum が 3 つの有効な値 (-1、0、1) のどれでもないか、signum が 0 で、magnitude に 1 つ以上の 0 以外のバイトが含まれている場合。public BigInteger(String val, int radix)
Character.digit で提供されています。String には、不適切な文字 (空白など) を含めることはできません。val - BigInteger の String 表現。radix - val の解釈で使用される基数。NumberFormatException - val が、指定した基数内の BigInteger の有効な表現ではないか、radix が Character.MIN_RADIX から Character.MAX_RADIX の範囲外にある場合。Character.digit(char, int)public BigInteger(String val)
Character.digit で提供されています。String には、不適切な文字 (空白など) を含めることはできません。val - BigInteger の 10 進数の String 表現。NumberFormatException - val は BigInteger の表現としては無効である。Character.digit(char, int)public BigInteger(int numBits,
Random rnd)
numBits - 1) の範囲に一様に分散されている、ランダムに生成された BigInteger を構築します。分散の一様さは、rnd のランダムビットのソースに誤りがないことを前提とします。このコンストラクタは、常に負でない BigInteger を構築します。numBits - 新しい BigInteger の最大ビット長。rnd - 新しい BigInteger の計算で使用されるランダムビットのソース。IllegalArgumentException - numBits が負の場合。bitLength()public BigInteger(int bitLength,
int certainty,
Random rnd)
確実性を指定する必要がない場合は、このコンストラクタではなく probablePrime メソッドを使用することをお勧めします。
bitLength - 返される BigInteger のビット長。certainty - 呼び出し側が許容できる不確実性の程度。新しい BigInteger が素数である確率は、(1 - 1/2certainty) より大きい。このコンストラクタの実行時間はこのパラメータの値に比例するrnd - 素数度をテストする候補の選択で使用されるランダムビットのソース。ArithmeticException - bitLength < 2。bitLength()public static BigInteger probablePrime(int bitLength, Random rnd)
bitLength - 返される BigInteger のビット長。rnd - 素数度をテストする候補の選択で使用されるランダムビットのソース。bitLength ビットの BigInteger (おそらく素数)ArithmeticException - bitLength < 2。bitLength()public BigInteger nextProbablePrime()
BigInteger より大きい最初の整数 (おそらく素数) を返します。このメソッドの返す数が合成数である確率は 2-100 を超えません。このメソッドは検索時に素数をスキップしません。p を返す場合、this < q < p が成り立つような素数 q はありません。BigInteger より大きい最初の整数 (おそらく素数)。ArithmeticException - this < 0。public static BigInteger valueOf(long val)
long の値と等しい BigInteger を返します。この「static ファクトリメソッド」は、よく使われる BigInteger を再利用できるようにするために、(long) コンストラクタの代わりに提供されます。val - 返される BigInteger の値。public BigInteger add(BigInteger val)
(this + val) である BigInteger を返します。val - この BigInteger に加算する値。this + valpublic BigInteger subtract(BigInteger val)
(this - val) である BigInteger を返します。val - この BigInteger から減算する値。this - valpublic BigInteger multiply(BigInteger val)
(this * val) である BigInteger を返します。val - この BigInteger で乗算する値。this * valpublic BigInteger divide(BigInteger val)
(this / val) である BigInteger を返します。val - この BigInteger を除算する値。this / valArithmeticException - val が 0 の場合。public BigInteger[] divideAndRemainder(BigInteger val)
(this / val) そして (this % val) と続く、2 つの BigInteger の配列を返します。val - この BigInteger を除算する値、および計算された剰余。(this / val) が最初の要素で、剰余 (this % val) が最後の要素。ArithmeticException - val が 0 の場合。public BigInteger remainder(BigInteger val)
(this % val) である BigInteger を返します。val - この BigInteger を除算する値、および計算された剰余。this % valArithmeticException - val が 0 の場合。public BigInteger pow(int exponent)
exponent は BigInteger ではなく整数です。exponent - この BigInteger を累乗する指数。ArithmeticException - exponent が負の場合。(非整数値を生成する演算が生じる。)public BigInteger gcd(BigInteger val)
abs(this) と abs(val) の最大公約数である BigInteger を返します。this==0 && val==0 の場合は 0 を返します。val - GCD の計算に使用する値。GCD(abs(this), abs(val))public BigInteger abs()
abs(this)public BigInteger negate()
(-this) である BigInteger を返します。-thispublic int signum()
public BigInteger mod(BigInteger m)
(this mod m) である BigInteger を返します。このメソッドは、常に負でない BigInteger を返す remainder とは異なります。m - モジュラス。this mod mArithmeticException - m ≤ 0remainder(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 が mod m の乗法逆数を持たない場合 (つまり、この BigInteger が m の素数ではない場合)。public BigInteger shiftLeft(int n)
(this << n) である BigInteger を返します。シフト移動量 n が負の場合は、このメソッドは右シフトを実行します。(floor(this * 2n) を計算する。)n - ビット単位でのシフト移動量。this << nArithmeticException - シフト移動量が Integer.MIN_VALUE の場合。shiftRight(int)public BigInteger shiftRight(int n)
(this >> n) である BigInteger を返します。符号拡張が行われます。シフト移動量 n が負の場合は、このメソッドは左シフトを実行します。(floor(this / 2n) を計算する。)n - ビット単位でのシフト移動量。this >> nArithmeticException - シフト移動量が Integer.MIN_VALUE の場合。shiftLeft(int)public BigInteger and(BigInteger val)
(this & val) である BigInteger を返します。(このメソッドは、this と val の両方が負の場合は負の BigInteger を返す。)val - この BigInteger との論理積をとる値。this & valpublic BigInteger or(BigInteger val)
(this | val) である BigInteger を返します。(このメソッドは、this または val が負の場合は負の BigInteger を返す。)val - この BigInteger との論理和をとる値。this | valpublic BigInteger xor(BigInteger val)
(this ^ val) である BigInteger を返します。(このメソッドは、this と val の片方だけが負の場合に負の BigInteger を返す。)val - この BigInteger との排他的論理和をとる値。this ^ valpublic BigInteger not()
(~this) である BigInteger を返します。(このメソッドは、この BigInteger が負でない場合に負の値を返す。)~thispublic BigInteger andNot(BigInteger val)
(this & ~val) である BigInteger を返します。and(val.not()) と同等のこのメソッドは、マスキング演算の便宜を図るために提供されています。(このメソッドは、this が負で val が正の場合に負の BigInteger 数値を返す。)val - この BigInteger で補数がとられ、論理積がとられる値。this & ~valpublic 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、必ず合成数である場合は false を返します。certainty が ≤ 0 の場合、true が返されます。certainty - 呼び出し側が許容できる不確実性の程度。この呼び出しが true を返す場合、この BigInteger が素数である確率は (1 - 1/2certainty) を超えます。このメソッドの実行時間はこのパラメータの値に比例します。true、必ず合成数である場合は false。public int compareTo(BigInteger val)
(x.compareTo(y) <op> 0) という組み合わせをお勧めします。この場合、<op> には 6 つの演算子のうちの 1 つが入ります。compareTo、インタフェース: Comparable<BigInteger>val - この BigInteger と比較する BigInteger。val より小さい場合は -1、等しい場合は 0、大きい場合は 1。public boolean equals(Object x)
equals、クラス: Objectx - この BigInteger と比較する Object。true。Object.hashCode(), HashMappublic BigInteger min(BigInteger val)
val の最小値を返します。val - 最小値の計算に使用する値。val のうちで小さい方の値を持つ BigInteger。値が等しい場合はどちらかが返される。public BigInteger max(BigInteger val)
val の最大値を返します。val - 最大値の計算に使用する値。val のうちで大きい方の値を持つ BigInteger。値が等しい場合はどちらかが返される。public int hashCode()
hashCode、クラス: ObjectObject.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 - String 表現の基数。Integer.toString(int, int), Character.forDigit(int, int), BigInteger(java.lang.String, int)public String toString()
Character.forDigit による数値から文字へのマッピングが使用され、必要に応じてマイナス符号が前に付けられます。(この表現は (String) コンストラクタと互換性があり、Java の + 演算子との連結を可能にします。)toString、クラス: ObjectCharacter.forDigit(int, int), BigInteger(java.lang.String)public byte[] toByteArray()
(ceil((this.bitLength() + 1)/8))) が含まれます (この表現は (byte[]) コンストラクタと互換性があります)。BigInteger(byte[])public int intValue()
int に変換します。この変換は、『Java™ 言語仕様』のセクション 5.1.3 で定義された long から int へのナロープリミティブ変換と同様です。この BigInteger が長すぎて int 内に収まらない場合、下位 32 ビットだけが返されます。この変換により、この BigInteger 値の絶対値全体に関する情報が失われ、逆の符号で返される可能性があります。public long longValue()
long に変換します。この変換は、『Java™ 言語仕様』のセクション 5.1.3 で定義された long から int へのナロープリミティブ変換と同様です。この BigInteger が長すぎて long 内に収まらない場合、下位 64 ビットだけが返されます。この変換により、この BigInteger 値の絶対値全体に関する情報が失われ、逆の符号で返される可能性があります。public float floatValue()
float に変換します。この変換は、『Java™ 言語仕様』のセクション 5.1.3 で定義された double から float へのナロープリミティブ変換と同様です。この BigInteger が大きすぎて float として表現できない場合、適宜 Float.NEGATIVE_INFINITY または Float.POSITIVE_INFINITY に変換されます。戻り値が有限である場合も、この変換により、BigInteger 値の精度に関する情報が失われる可能性があります。floatValue、クラス: Numberfloat に変換されたこの BigInteger。public double doubleValue()
double に変換します。この変換は、『Java™ 言語仕様』のセクション 5.1.3 で定義された double から float へのナロープリミティブ変換と同様です。この BigInteger が大きすぎて double として表現できない場合、適宜 Double.NEGATIVE_INFINITY または Double.POSITIVE_INFINITY に変換されます。戻り値が有限である場合も、この変換により、BigInteger 値の精度に関する情報が失われる可能性があります。doubleValue、クラス: Numberdouble に変換されたこの BigInteger。 バグまたは機能を送信
詳細な API リファレンスおよび開発者ドキュメントについては、Java SE のドキュメントを参照してください。そのドキュメントには、概念的な概要、用語の定義、回避方法、有効なコード例などの、開発者を対象にしたより詳細な説明が含まれています。
Copyright © 1993, 2013, Oracle and/or its affiliates. All rights reserved.