|
JavaTM 2 Platform Std. Ed. v1.4.0 |
||||||||||
| 前のクラス 次のクラス | フレームあり フレームなし | ||||||||||
| 概要: 入れ子 | フィールド | コンストラクタ | メソッド | 詳細: フィールド | コンストラクタ | メソッド | ||||||||||
java.lang.Object
|
+--java.lang.Number
|
+--java.math.BigInteger
変更が不可能な、任意精度の整数です。すべての演算は、BigInteger が (Java のプリミティブ整数型のような) 2 値補数表記法で表されたかのように動作します。BigInteger は、Java のすべてのプリミティブ整数演算子と、java.lang.Math の関連するすべてのメソッドに同等のものを提供します。また、BigInteger は、モジュラ算術、GCD 計算、素数度テスト、素数生成、ビット操作、その他のいくつかの操作に対する演算も提供します。
算術演算のセマンティクスは、「Java 言語仕様」に定義されているように Java の整数算術演算子を正確に模倣します。たとえば、ゼロ除算は ArithmeticException をスローし、正の数による負の数の除算は負 (または 0) の剰余を出します。オーバーフローに関する仕様内の詳細はすべて無視され、BigInteger は演算の結果の受け入れに必要なだけ大きくなります。
シフト演算のセマンティクスは、負のシフト移動量を考慮するため Java のシフト演算子を拡張しています。負のシフト移動量を持つ右シフトは左シフトとなります。逆の場合も同じです。符号なしの右シフト演算子 (>>>) は、この演算ではこのクラスが提供する「無限のワードサイズ」抽出と組み合わせる意味がほとんどないため省かれています。
ビット単位の論理演算のセマンティクスは、Java のビット整数演算子のセマンティクスを正確に模倣しています。2 項演算子 (and、or、xor) は、演算前に 2 つのオペランドの短い方に対して暗黙に符号拡張を行います。
比較演算は符号付き整数の比較を行います。これは、Java の関連する演算子および同等の演算子により行われるものと同じです。
モジュラ算術演算は、剰余計算、べき乗、および乗法逆数計算のために提供されています。これらのメソッドは、常に 0 と (モジュラス - 1) の間の負でない結果を返します (モジュラス - 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 |
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 〜 (2numBits - 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 を返します (このメソッドは、this と val の両方が負の場合は負の BigInteger を返す)。 |
BigInteger |
andNot(BigInteger val)
値が (this & ‾val) である BigInteger を返します。 |
int |
bitCount()
この BigInteger の 2 の補数表現内の、符号ビットと異なるビットの数を返します。 |
int |
bitLength()
この BigInteger の最小の 2 の補数表現内のビット数を返します。 |
BigInteger |
clearBit(int n)
値がこの BigInteger に等しい BigInteger を、指定されたビットをクリアして返します ((this & ‾(1<<n)) を計算する)。 |
int |
compareTo(BigInteger val)
この BigInteger を指定された BigInteger と比較します。 |
int |
compareTo(Object o)
この BigInteger を指定した Object と比較します。 |
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 を、指定されたビットを反転させて返します ((this ^ (1<<n)) を計算する)。 |
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 を返します (pow と違って、このメソッドは負の指数を許容する)。 |
BigInteger |
multiply(BigInteger val)
値が (this * val) の BigInteger を返します。 |
BigInteger |
negate()
値が (-this) の BigInteger を返します。 |
BigInteger |
not()
値が (‾this) の BigInteger を返します (このメソッドは、この BigInteger が負でない場合に負の値を返す)。 |
BigInteger |
or(BigInteger val)
値が (this | val) の BigInteger を返します (このメソッドは、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 を、指定されたビットを設定して返します ((this | (1<<n)) を計算する)。 |
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 を返します ((this & (1<<n)) ! |
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 を返します (このメソッドは、this と val の片方だけが負の場合に負の BigInteger を返す)。 |
| クラス java.lang.Number から継承したメソッド |
byteValue, shortValue |
| クラス java.lang.Object から継承したメソッド |
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
| フィールドの詳細 |
public static final BigInteger ZERO
public static final BigInteger ONE
| コンストラクタの詳細 |
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)
val - BigInteger の String 表現radix - val の解釈で使用される基数
NumberFormatException - val が指定した基数内の BigInteger の有効な表現ではないか、radix が Character.MIN_RADIX (2) 〜 Character.MAX_RADIX (36) の範囲外にある場合Character.digit(char, int)public BigInteger(String val)
val - BigInteger の 10 進数の String 表現
NumberFormatException - val は BigInteger の表現としては無効であるCharacter.digit(char, int)
public BigInteger(int numBits,
Random rnd)
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 < 2bitLength()| メソッドの詳細 |
public static BigInteger probablePrime(int bitLength,
Random rnd)
bitLength - 返される BigInteger のビット長rnd - 素数度をテストする候補の選択で使用されるランダムビットのソース
ArithmeticException - bitLength < 2bitLength()public static BigInteger valueOf(long val)
val - 返される BigInteger の値
public BigInteger add(BigInteger val)
val - この BigInteger に加算する値
public BigInteger subtract(BigInteger val)
val - この BigInteger から減算する値
public BigInteger multiply(BigInteger val)
val - この BigInteger で乗算する値
public BigInteger divide(BigInteger val)
val - この BigInteger を除算する値
ArithmeticException - val==0public BigInteger[] divideAndRemainder(BigInteger val)
val - この BigInteger を除算する値、および計算された剰余
ArithmeticException - val==0public BigInteger remainder(BigInteger val)
val - この BigInteger を除算する値、および計算された剰余
ArithmeticException - val==0public BigInteger pow(int exponent)
exponent - この BigInteger を累乗する指数
ArithmeticException - exponent が負の場合 (非整数値を生成する演算が生じる)public BigInteger gcd(BigInteger val)
val - GCD で計算する値
public BigInteger abs()
public BigInteger negate()
public int signum()
public BigInteger mod(BigInteger m)
m - モジュラス
ArithmeticException - m <= 0remainder(java.math.BigInteger)
public BigInteger modPow(BigInteger exponent,
BigInteger m)
exponent - 指数m - モジュラス
ArithmeticException - m <= 0modInverse(java.math.BigInteger)public BigInteger modInverse(BigInteger m)
m - モジュラス
ArithmeticException - m <= 0 であるか、あるいはこの BigInteger が mod m の乗法逆数を持たない場合 (つまり、この BigInteger が m の「素数」ではない場合)public BigInteger shiftLeft(int n)
n - ビット単位でのシフト移動量
shiftRight(int)public BigInteger shiftRight(int n)
n - ビット単位でのシフト移動量
shiftLeft(int)public BigInteger and(BigInteger val)
val - この BigInteger との論理積をとる値
public BigInteger or(BigInteger val)
val - この BigInteger との論理和をとる値
public BigInteger xor(BigInteger val)
val - この BigInteger との排他的論理和をとる値
public BigInteger not()
public BigInteger andNot(BigInteger val)
val - この BigInteger で補数がとられ、論理積がとられる値
public boolean testBit(int n)
n - テストするビットのインデックス
ArithmeticException - n が負の場合public BigInteger setBit(int n)
n - 設定するビットのインデックス
ArithmeticException - n が負の場合public BigInteger clearBit(int n)
n - クリアするビットのインデックス
ArithmeticException - n が負の場合public BigInteger flipBit(int n)
n - 反転するビットのインデックス
ArithmeticException - n が負の場合public int getLowestSetBit()
public int bitLength()
public int bitCount()
public boolean isProbablePrime(int certainty)
certainty - 呼び出し側が許容しない確率の尺度。この BigInteger が素数である確率が (1 - 1/2certainty) を超える場合は true を返す。実行時間はこのパラメータの値に比例する
public int compareTo(BigInteger val)
val - この BigInteger と比較する BigInteger
public int compareTo(Object o)
Comparable 内の compareToo - この BigInteger と比較する Object
ClassCastException - o が BigInteger ではない場合compareTo(java.math.BigInteger),
Comparablepublic boolean equals(Object x)
Object 内の equalsx - この BigInteger と比較する Object
Object.hashCode(),
Hashtablepublic BigInteger min(BigInteger val)
val - 最小値を計算する値
public BigInteger max(BigInteger val)
val - 最大値を計算する値
public int hashCode()
Object 内の hashCodeObject.equals(java.lang.Object),
Hashtablepublic String toString(int radix)
radix - String 表現の基数
Integer.toString(int, int),
Character.forDigit(int, int),
BigInteger(java.lang.String, int)public String toString()
Object 内の toStringCharacter.forDigit(int, int),
BigInteger(java.lang.String)public byte[] toByteArray()
BigInteger(byte[])public int intValue()
Number 内の intValuepublic long longValue()
Number 内の longValuepublic float floatValue()
Number 内の floatValuepublic double doubleValue()
Number 内の doubleValue
|
JavaTM 2 Platform Std. Ed. v1.4.0 |
||||||||||
| 前のクラス 次のクラス | フレームあり フレームなし | ||||||||||
| 概要: 入れ子 | フィールド | コンストラクタ | メソッド | 詳細: フィールド | コンストラクタ | メソッド | ||||||||||
Java、Java 2D、および JDBC は米国ならびにその他の国における米国 Sun Microsystems, Inc. の商標もしくは登録商標です。
Copyright 1993-2002 Sun Microsystems, Inc. 901 San Antonio Road
Palo Alto, California, 94303, U.S.A. All Rights Reserved.