全パッケージ  クラス階層  このパッケージ  前項目  次項目  インデックス

クラス java.math.BigInteger

java.lang.Object
   |
   +----java.lang.Number
           |
           +----java.math.BigInteger

public class BigInteger
extends Number
変更不可能な任意の精度の整数。すべての演算は、BigInteger が (Java のプリミティブ整数型のような) 2 値補数表記法で表されたかのように動作します。BigInteger は Java のすべてのプリミティブ整数演算子と java.lang.Math の関連するすべての static メソッドに同等のものを提供します。また、BigInteger は、モジュラ算術、GCD 計算、素数度テスト、素数生成、シングルビット操作、その他いくつか雑多な操作に対する演算も提供します。

算術演算のセマンティクスは、Java 言語仕様に定義されているように Java の整数算術演算子を正確に模倣します。例えば、ゼロ除算は ArithmeticException をスローし、正の数による負の数の除算は負 (または 0) の剰余を出します。オーバーフローに関する仕様内の詳細はすべて無視され、BigIntegers は演算の結果の受け入れに必要なだけ大きくなります。

シフト演算のセマンティクスは、負のシフト距離を考慮するため Java のシフト演算子を拡張しています。負のシフト距離を持つ右シフトは左シフトとなります。符号なしの右シフト演算子 (>>>) は、この演算が このクラスが提供する "無限のワードサイズ" 抽出と組み合わせる意味がほとんどないため省かれています。

ビット毎の論理演算のセマンティクスは、Java のビット毎の整数演算子のセマンティクスを正確に模倣しています。2 項演算子 (and、or、xor) は、演算前に 2 つのオペランドの短い方に対し暗黙に符号拡張を行います。

比較演算は符号付き整数の比較を行います。 これは、Java の関連する演算子および同等の演算子により行われるものに同等です。

モジュラ算術演算は、剰余計算、 べき乗、および逆数計算のために提供されています。これらのメソッドは、常に 0 と (対数係数 - 1) の間の負でない結果を返します (対数係数 - 1 を含む)。

シングルビット演算は、オペランドの 2 の補数表現のシングルビットに使用します。必要に応じ、オペランドの符号は指示するビットを持つように拡張されます。演算中の BigInteger と異なる符号を持つ数値を生成するシングルビット演算はありません。これは、シングルビット演算が 単一のビットにのみ影響し、このクラスが提供する "無限のワードサイズ" 抽出が各 BigInteger に先行する無限の "仮想符号ビット" を存在させるためです。

参照:
BigDecimal

Constructor Index

 o BigInteger(byte[])
(符号付き) 整数の 2 の補数表現が入った 1 バイトの配列を BigInteger に変換する。
 o BigInteger(int, byte[])
整数の符号絶対値表現を BigInteger に変換する。
 o BigInteger(int, int, Random)
ランダムに選択した BigIngeger (おそらく素数) を指定した bitLength とともに返す。
 o BigInteger(int, Random)
[0, 2**numBits - 1] に一様に分散された乱数を返します (rndSrc のランダムビットが誤りのないソースであることを前提とする)。
 o BigInteger(文字列)
任意のマイナス符号とそれに続く 1 つ以上の小数点以下の桁列が入った文字列を、BigInteger に変換する。
 o BigInteger(文字列, int)
指定する基数内の任意のマイナス符号とそれに続く 1 つ以上の桁列が入った文字列を、BigInteger に変換する。

Method Index

 o abs()
値がこの数値の絶対値である BigInteger を返す。
 o add(BigInteger)
値が (this + val) である BigInteger を返す。
 o and(BigInteger)
値が (this & val) である BigInteger を返す。
 o andNot(BigInteger)
値が (this & ~val) である BigInteger を返す。
 o bitCount()
この数値の 2 の補数表現内の、符号ビットと異なるビットの数を返す。
 o bitLength()
この数値の最小の 2 の補数表現内のビットの数を返す。ただし、符号ビット (ceil(log2(this < 0 ? -this : this + 1))) を除く。
 o clearBit(int)
値がこの数値と等しい BigInteger を指定するビットをクリアーして返す。
 o compareTo(BigInteger)
この数値が val 未満の場合は -1、val に等しい場合は 0 を、val を超える場合は 1 を返す。
 o divide(BigInteger)
値が (this / val) である BigInteger を返す。
 o divideAndRemainder(BigInteger)
2 つの BigInteger の配列を返す。
 o doubleValue()
数値を double に変換します。
 o equals(Object)
x が、値がこの数値に等しい BigInteger の場合は真を返す。
 o flipBit(int)
値がこの数値に等しい BigInteger を、指定するビットを反転させて返す。
 o floatValue()
この数値を float に変換する。
 o gcd(BigInteger)
値が当該の絶対値と val の絶対値の最大公約数である BigInteger を返す。
 o getLowestSetBit()
この数値内の最も右側 (1 番低い位) の 1 ビットのインデックス (つまり、最も右側の 1 ビットの右方向への 0 ビットの数) を返す。
 o hashCode()
このオブジェクトのハッシュコードを計算する。
 o intValue()
この数値を int に変換する。
 o isProbablePrime(int)
この BigInteger が素数である可能性が高い場合は真を返し、必ず合成数である場合は偽を返す。
 o longValue()
この数値を long に変換する。
 o max(BigInteger)
this および val のうち大きい方と同じ値を持つ。
 o min(BigInteger)
this および val のうち小さい方と同じ値を持つ。
 o mod(BigInteger)
値が this mod mである BigInteger を返す。
 o modInverse(BigInteger)
this の mod m の逆数を返す。
 o modPow(BigInteger, BigInteger)
値が (this ** exponent) mod m であるBigInteger を返す。
 o multiply(BigInteger)
値が (this * val) である BigInteger を返す。
 o negate()
値が (-1 * this) である BigInteger を返す。
 o not()
値が (~this) である BigInteger を返す。
 o or(BigInteger)
値が (this | val) である BigInteger を返す。
 o pow(int)
値が (this ** exponent) である BigInteger を返す。
 o remainder(BigInteger)
値が (this % val) である BigInteger を返す。
 o setBit(int)
値がこの数値に等しい BigInteger を、指定するビットを付けて返す。
 o shiftLeft(int)
値が (this << n) である BigInteger を返す。
 o shiftRight(int)
値が (this >> n) である BigInteger を返す。
 o signum()
この数値の signum 関数を返す (この数値が負の場合は -1、ゼロの場合は 0、正の場合は 1)。
 o subtract(BigInteger)
値が (this - val) である BigInteger を返す。
 o testBit(int)
指定したビットがセットされる場合は真を返す。
 o toByteArray()
この数値の 2 の補数表現を返す。
 o toString()
この数値の基数 10 の文字列表現を返す。
 o toString(int)
この数値の文字列表現を一定の基数で返す。
 o valueOf(long)
BigInteger を指定する値とともに返す。
 o xor(BigInteger)
値が (this ^ val) である BigInteger を返す。

Constructors

 o BigInteger
 public BigInteger(byte val[]) throws NumberFormatException
(符号付き) 整数の 2 の補数表現を含むバイト配列を BigInteger に変換します。入力配列は big-endian (つまり最上位バイトは [0] の位置にある) と見なされます。 (最上位バイトの最上位ビットは、符号ビットである。)配列は少なくとも 1 バイト必要で、1 バイトを満たさない場合は NumberFormatException がスローされます。

 o BigInteger
 public BigInteger(int signum,
                   byte magnitude[]) throws NumberFormatException
整数の符号絶対値表現を BigInteger に変換します。符号は整数の signum 値 (負は -1、ゼロは 0、正は 1) として表される 。絶対値は big-endian 型のバイト配列 (つまり最上位バイトは[0]の位置にある)として表されます 。ゼロ以外の絶対値で対になった無効な signum 値または 0 signum 値には、NumberFormatException がスローされます。長さが 0 の絶対値配列は受容され、 (指定される signum 値に関わりなく) 値 0 となります。

 o BigInteger
 public BigInteger(String val,
                   int radix) throws NumberFormatException
指定した基数内の任意のマイナス符号とそれに続く 1 つ以上の桁の列を、BigInteger に変換します。文字型から数値型へのマッピングは Character.digit で提供されています。不適切な文字 (空白も含め) や Character.MIN_RADIX(2) から Character.MAX_RADIX(36) の範囲外の基数は、 NumberFormatException となります。

 o BigInteger
 public BigInteger(String val) throws NumberFormatException
任意のマイナス符号とそれに続く 1 つ以上の少数点以下の桁の列を BigInteger に変換する。文字型から数値型へのマッピングは Character.digit で提供されています。 不適切な文字 (空白も含め) はすべて NumberFormatException となります。

 o BigInteger
 public BigInteger(int numBits,
                   Random rndSrc) throws IllegalArgumentException
[0, 2**numBits - 1] に一様に分散された乱数を返します (rndSrc のランダムビットが誤りのないソースであることを前提とする)。この構築子は常に負でない BigInteger を返す点に注意。 numBits < 0 の場合は、 IllegalArgumentException をスローします。

 o BigInteger
  public BigInteger(int bitLength,
                    int certainty,
                    Random rnd)
ランダムに選択された (おそらく素数である) BigInteger を指定した bitLength とともに返します。確率パラメータは、呼び出し側が許容しない確率の尺度です。数値が素数である確率は、確率 1 - 1/2** certainty を超えます。実行時間は確率パラメータの値に比例します。指定される乱数生成子を使用し素数度をテストする候補を選択します。bitLength < 2 の場合は ArithmeticException をスローします。

Methods

 o valueOf
  public static BigInteger valueOf(long val)
指定した値を持つ BigInteger を返します。この項目は、よく使用される (0 や 1 のような) BigInteger の再使用を許し、エクスポートされる定数を不要にするために long を引数とする構築子の代わりに提供されます。

 o add
 public BigInteger add(BigInteger val) throws ArithmeticException
値が (this + val) の BigInteger を返します。

 o subtract
  public BigInteger subtract(BigInteger val)
値が (this - val) の BigInteger を返します。

 o multiply
  public BigInteger multiply(BigInteger val)
値が (this * val) の BigInteger を返します。

 o divide
 public BigInteger divide(BigInteger val) throws ArithmeticException
値が (this / val) の BigInteger を返します。val == 0 の場合は ArithmeticException をスローします。

 o remainder
 public BigInteger remainder(BigInteger val) throws ArithmeticException
値が (this % val) の BigInteger を返します。val == 0 の場合は ArithmeticException をスローします。

 o divideAndRemainder
 public BigInteger[] divideAndRemainder(BigInteger val) throws ArithmeticException
2 つの BigInteger の配列を返します。返り値の初めの ([0]) 要素は商 (this / val) で、2 番目の ([1]) 要素は剰余 (this % val) である。val == 0 の場合は ArithmeticException をスローします。

 o pow
 public BigInteger pow(int exponent) throws ArithmeticException
値が (this ** exponent) の BigInteger を返します。exponent < 0 の場合は ArithmeticException をスローします (演算は非整数値を生成)。exponentは BigInteger でなく整数であることに注意。

 o gcd
  public BigInteger gcd(BigInteger val)
値が abs (this) と abs (val) の最大公約数である BigInteger を返します。this == 0 && val == 0 の場合は 0 を返します。

 o abs
  public BigInteger abs()
値がこの数値の絶対値である BigInteger を返します。

 o negate
  public BigInteger negate()
値が (-1 * this) の BigInteger を返します。

 o signum
  public int signum()
この数値の signum 関数を返します (負の場合は -1、ゼロの場合は 0、正の場合は 1)。

 o mod
  public BigInteger mod(BigInteger m)
値が this mod m である BigInteger を返します。m <= 0 の場合は ArithmeticException をスローします。

 o modPow
  public BigInteger modPow(BigInteger exponent,
                           BigInteger m)
値が (this ** exponent) mod m のBigInteger を返します。(exponent == 1 の場合、返り値は (this mod m)。exponent < 0 の場合、返り値は (this ** -exponent) のモジュラ逆数。) m <= 0 の場合は ArithmeticException をスローします。

 o modInverse
 public BigInteger modInverse(BigInteger m) throws ArithmeticException
this の mod m の逆数を返します。 m <= 0、または this mod mの逆数を持たない場合 (すなわち gcd(this, m) != 1) を持たない場合は ArithmeticException をスローします。

 o shiftLeft
  public BigInteger shiftLeft(int n)
値が (this << n) の BigInteger を返します (floor(this * 2**n) を計算する)。

 o shiftRight
  public BigInteger shiftRight(int n)
値が (this >> n) の BigInteger を返します。符号拡張が行われます (floor(this / 2**n) が計算される)。

 o and
  public BigInteger and(BigInteger val)
値が (this & val) の BigInteger を返します。 (このメソッドは、this と val が双方とも負の場合は負の数値を返します)。

 o or
  public BigInteger or(BigInteger val)
値が (this | val) の BigInteger を返します (このメソッドは this または val が負の場合は負の数値を返します)。

 o xor
  public BigInteger xor(BigInteger val)
値が (this ^ val) の BigInteger を返します (このメソッドは this と val の片方だけが負の場合に負の数値を返します)。

 o not
  public BigInteger not()
値が (~this) の BigInteger を返します (このメソッドは、この数値が負でない場合に負の値を返します)。

 o andNot
  public BigInteger andNot(BigInteger val)
値が (this & ~val) である BigInteger を返します。 and(val.not()) に同等のこのメソッドは、マスキング演算の便宜を図るために提供されています (このメソッドは、this が負で val が正の場合は負の数値を返します)。

 o testBit
 public boolean testBit(int n) throws ArithmeticException
指定したビットがセットされている場合は真を返します ((this & (1<<n)) != 0) を計算する)。n < 0 の場合は ArithmeticException をスローします。

 o setBit
 public BigInteger setBit(int n) throws ArithmeticException
値がこの数値に等しい BigInteger を、指定したビットをセットして返します ((this | (1<<n))を計算する)。 n < 0 の場合は ArithmeticException をスローします。

 o clearBit
 public BigInteger clearBit(int n) throws ArithmeticException
値がこの数値に等しい BigInteger を、指定したビットをクリアーして返します ((this & ~(1<<n)) を計算する)。n < 0 の場合は ArithmeticException をスローします。

 o flipBit
 public BigInteger flipBit(int n) throws ArithmeticException
値がこの数値に等しい BigInteger を、指定したビットを反転させて返します ((this ^ (1<<n)) を計算する)。n < 0 の場合は ArithmeticException をスローします。

 o getLowestSetBit
  public int getLowestSetBit()
この数値内の最も右側 (1 番低い位) の 1 ビットのインデックス (最も右側の 1 ビットの右方向への 0 ビットの数)を返します。この数値に 1 ビットが 1 つも含まれない場合は -1 を返します。 ((this==0? -1 : log2(this & -this)) を計算する)。

 o bitLength
  public int bitLength()
この数値の最小の 2 の補数表現内のビットの数を返します。ただし、符号ビット (ceil(log2(this < 0 ? -this : this + 1))) を除く (正の数値については、これは通常の 2 進表現におけるビットの数に等しい)。

 o bitCount
  public int bitCount()
この数値の 2 の補数表現内の、符号ビットと異なるビットの数を返します。このメソッドは BigInteger 上にビット-ベクトル形式の設定を実装する場合に便利です。

 o isProbablePrime
  public boolean isProbablePrime(int certainty)
この BigInteger が素数である可能性が高い場合は真を返し、必ず合成数である場合は偽を返します。確率パラメータは、呼び出し側が許容しない確率の尺度である。メソッドは、この数値が素数である確率が 1 -1/2** certainty を超える場合は真を返します。実行時間は確率パラメータの値に比例します。

 o compareTo
  public int compareTo(BigInteger val)
この値が val よりも小さい場合は -1、val に等しい場合は 0、val を超える場合は 1 を返します。このメソッドは、6 つの boolean 型の比較演算子 (<, ==, >, >=, !=, <=) のそれぞれに対する個々のメソッドの代わりに提供されます。これらの比較を行うには (x.compareTo(y) <op> 0) という組み合わせを推奨します。この場合、<op> には 6 つの演算子のうちの 1 つが入ります。

 o equals
  public boolean equals(Object x)
x が、値がこの数値に等しい BigInteger の場合は真を返します。このメソッドは、BigInteger がハッシュキーとして使用できるように提供されています。

オーバーライド:
クラス Object 内の equals
 o min
  public BigInteger min(BigInteger val)
this および val のうち小さい方と同じ値を持つ BigInteger を返します。値が等しい場合はそれが返されます。

 o max
  public BigInteger max(BigInteger val)
this および val のうち大きい方と同じ値を持つ BigInteger を返します。値が等しい場合はそれが返されます。

 o hashCode
  public int hashCode()
このオブジェクトのハッシュコードを計算します。

オーバーライド:
クラス Object 内の hashCode
 o toString
  public String toString(int radix)
指定された基数内のこの数値の文字列表現を返します。基数が Character.MIN_RADIX(2) から Character.MAX_RADIX(36) の範囲外の場合は、10 にデフォルト設定します (Integer.toString の場合に同じ)。Character.forDigit による数値型から文字型へのマッピングが使用され、妥当な場合にはマイナス符号が先に付けられます (この表現は (String, int) の引数の構築子と互換性がある)。

 o toString
  public String toString()
この数値の基数 10 の文字列表現を返します。Character.forDigit による数値型から文字型へのマッピングが使用され、妥当な場合にはマイナス符号が先に付けられます (この表現は (String) の引数の構築子と互換性があり、Java の + 演算子との連結を考慮したものである)。

オーバーライド:
クラス Object 内の toString
 o toByteArray
  public byte[] toByteArray()
この数値の 2 の補数表現を返します。配列は big-endian です (最上位のバイトは [0] の位置にある)。配列のバイト数は、数値 (ceil((this.bitLength() + 1)/8)) の表現に必要な最小のものです (この表現は (byte[]) の引数の構築子と互換性がある)。

 o intValue
  public int intValue()
この数値を int に変換する。Java 言語仕様にもとづく標準の縮小プリミティブ変換。

オーバーライド:
クラス Number 内の intValue
 o longValue
  public long longValue()
この数値を long に変換します。Java 言語仕様にもとづく標準のプリミティブ変換。

オーバーライド:
クラス Number 内の longValue
 o floatValue
  public float floatValue()
この数値を float に変換します。Java 言語仕様に定義された double から float への縮小プリミティブ変換に類似しています。数値が float として表現するには大きすぎる絶対値を持つ場合には、正または負の無限大に変換されます。

オーバーライド:
クラス Number 内の floatValue
 o doubleValue
  public double doubleValue()
数値を double に変換します。 Java 言語仕様に定義された double から float への縮小プリミティブ変換に類似しています。数値が double として表現するには大きすぎる絶対値を持つ場合には、正または負の無限大に変換されます。

オーバーライド:
クラス Number 内の doubleValue

全パッケージ  クラス階層  このパッケージ  前項目  次項目  インデックス