|
Build 1.0_r1(from source) | |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectjava.lang.Number
java.math.BigInteger
public class BigInteger
Class which represents immutable arbitrary precision integer numbers. This class provides methods for arithmetic operations and methods for the comparison of two instances.
| Field Summary | |
|---|---|
(package private) BigInt |
bigInt
|
(package private) int[] |
digits
The magnitude of this in the little-endian representation. |
(package private) static int |
EQUALS
The BigInteger constant 0 used for comparison. |
(package private) static int |
GREATER
The BigInteger constant 1 used for comparison. |
(package private) static int |
LESS
The BigInteger constant -1 used for comparison. |
(package private) static BigInteger |
MINUS_ONE
The BigInteger constant -1. |
(package private) int |
numberLength
The length of this in measured in ints. |
static BigInteger |
ONE
The BigInteger constatn 1. |
(package private) int |
sign
The sign of this. |
(package private) static BigInteger[] |
SMALL_VALUES
All the BigInteger numbers in the range [0,10] are cached. |
static BigInteger |
TEN
The BigInteger constant 10. |
static BigInteger |
ZERO
The BigInteger constant 0. |
| Constructor Summary | |
|---|---|
BigInteger(BigInt a)
|
|
BigInteger(byte[] val)
Constructs a new BigInteger from the given two's complement
representation. |
|
BigInteger(int signum,
byte[] magnitude)
Constructs a new BigInteger instance with the given sign and the
given magnitude. |
|
BigInteger(int sign,
int numberLength,
int[] digits)
Constructs a number without to create new space. |
|
BigInteger(int bitLength,
int certainty,
Random rnd)
Constructs a random positive BigInteger instance in the range [0,
2^(bitLength)-1] which is probably prime. |
|
BigInteger(int sign,
long value)
|
|
BigInteger(int numBits,
Random rnd)
Constructs a random non-negative BigInteger instance in the range
[0, 2^(numBits)-1]. |
|
BigInteger(String val)
Constructs a new BigInteger instance from the string
representation. |
|
BigInteger(String val,
int radix)
Constructs a new BigInteger instance from the string
representation. |
|
| Method Summary | |
|---|---|
BigInteger |
abs()
Returns a (new) BigInteger whose value is the absolute value of
this. |
BigInteger |
add(BigInteger val)
Returns a new BigInteger whose value is this + val. |
BigInteger |
and(BigInteger val)
Returns a new BigInteger whose value is this & val. |
BigInteger |
andNot(BigInteger val)
Returns a new BigInteger whose value is this & ~val. |
int |
bitCount()
Returns the number of bits in the binary representation of this
wich differ from the sign bit. |
int |
bitLength()
Returns the number of bits of the binary representation of this
without the sign bit. |
BigInteger |
clearBit(int n)
Returns a new BigInteger which has the same binary representation
as this but with the bit at position n cleared. |
int |
compareTo(BigInteger val)
Compares this BigInteger with val. |
(package private) BigInteger |
copy()
|
(package private) void |
cutOffLeadingZeroes()
Decreases numberLength if there are zero high elements. |
BigInteger |
divide(BigInteger divisor)
Returns a new BigInteger whose value is this / divisor. |
BigInteger[] |
divideAndRemainder(BigInteger divisor)
Returns a BigInteger array which contains this / divisor
at index 0 and this % divisor at index 1. |
double |
doubleValue()
Returns this BigInteger as an double value. |
boolean |
equals(Object x)
Returns true if x is a BigInteger instance and if this
instance is equal to this BigInteger. |
(package private) void |
establishOldRepresentation(String caller)
|
BigInteger |
flipBit(int n)
Returns a new BigInteger which has the same binary representation
as this but with the bit at position n flipped. |
float |
floatValue()
Returns this BigInteger as an float value. |
BigInteger |
gcd(BigInteger val)
Returns a new BigInteger whose value is greatest common divisor
of this and val. |
(package private) int |
getFirstNonzeroDigit()
|
int |
getLowestSetBit()
Returns the position of the lowest set bit in the two's complement representation of this BigInteger. |
int |
hashCode()
Returns a hash code for this BigInteger. |
(package private) static int |
inplaceAdd(int[] a,
int aSize,
int addend)
|
int |
intValue()
Returns this BigInteger as an int value. |
(package private) boolean |
isOne()
Tests if this.abs() is equals to ONE |
boolean |
isProbablePrime(int certainty)
Tests whether this BigInteger is probably prime. |
long |
longValue()
Returns this BigInteger as an long value. |
BigInteger |
max(BigInteger val)
Returns the maximum of this BigInteger and val. |
BigInteger |
min(BigInteger val)
Returns the minimum of this BigInteger and val. |
BigInteger |
mod(BigInteger m)
Returns a new BigInteger whose value is this mod m. |
BigInteger |
modInverse(BigInteger m)
Returns a new BigInteger whose value is 1/this mod m. |
BigInteger |
modPow(BigInteger exponent,
BigInteger m)
Returns a new BigInteger whose value is
this^exponent mod m. |
BigInteger |
multiply(BigInteger val)
Returns a new BigInteger whose value is this * val. |
(package private) static int |
multiplyByInt(int[] res,
int[] a,
int aSize,
int factor)
|
BigInteger |
negate()
Returns a new BigInteger whose value is the -this. |
BigInteger |
nextProbablePrime()
Returns the smallest integer x > this which is probably prime as
a BigInteger instance. |
BigInteger |
not()
Returns a new BigInteger whose value is ~this. |
BigInteger |
or(BigInteger val)
Returns a new BigInteger whose value is this | val. |
BigInteger |
pow(int exp)
Returns a new BigInteger whose value is this ^ exp. |
static BigInteger |
probablePrime(int bitLength,
Random rnd)
Returns a random positive BigInteger instance in the range [0,
2^(bitLength)-1] which is probably prime. |
BigInteger |
remainder(BigInteger divisor)
Returns a new BigInteger whose value is this % divisor. |
BigInteger |
setBit(int n)
Returns a new BigInteger which has the same binary representation
as this but with the bit at position n set. |
BigInteger |
shiftLeft(int n)
Returns a new BigInteger whose value is this << n. |
BigInteger |
shiftRight(int n)
Returns a new BigInteger whose value is this >> n. |
int |
signum()
Returns the sign of this BigInteger. |
BigInteger |
subtract(BigInteger val)
Returns a new BigInteger whose value is this - val. |
boolean |
testBit(int n)
Tests whether the bit at position n in this is set. |
byte[] |
toByteArray()
Returns the two's complement representation of this BigInteger in a byte array. |
String |
toString()
Returns a string representation of this BigInteger in decimal
form. |
String |
toString(int radix)
Returns a string containing a string representation of this BigInteger with base radix. |
(package private) void |
unCache()
|
(package private) void |
validate(String caller,
String param)
|
(package private) static void |
validate1(String caller,
BigInteger a)
|
(package private) static void |
validate2(String caller,
BigInteger a,
BigInteger b)
|
(package private) static void |
validate3(String caller,
BigInteger a,
BigInteger b,
BigInteger c)
|
(package private) static void |
validate4(String caller,
BigInteger a,
BigInteger b,
BigInteger c,
BigInteger d)
|
static BigInteger |
valueOf(long val)
Creates a new BigInteger whose value is equal to the specified
long argument. |
(package private) BigInteger |
withNewRepresentation(String caller)
|
BigInteger |
xor(BigInteger val)
Returns a new BigInteger whose value is this ^ val. |
| Methods inherited from class java.lang.Number |
|---|
byteValue, shortValue |
| Methods inherited from class java.lang.Object |
|---|
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
| Field Detail |
|---|
transient BigInt bigInt
transient int[] digits
transient int numberLength
transient int sign
public static final BigInteger ZERO
BigInteger constant 0.
public static final BigInteger ONE
BigInteger constatn 1.
public static final BigInteger TEN
BigInteger constant 10.
static final BigInteger MINUS_ONE
BigInteger constant -1.
static final int EQUALS
BigInteger constant 0 used for comparison.
static final int GREATER
BigInteger constant 1 used for comparison.
static final int LESS
BigInteger constant -1 used for comparison.
static final BigInteger[] SMALL_VALUES
BigInteger numbers in the range [0,10] are cached.
| Constructor Detail |
|---|
BigInteger(BigInt a)
BigInteger(int sign,
long value)
BigInteger(int sign,
int numberLength,
int[] digits)
sign - the sign of the numbernumberLength - the length of the internal arraydigits - a reference of some array created before
public BigInteger(int numBits,
Random rnd)
BigInteger instance in the range
[0, 2^(numBits)-1].
numBits - maximum lenght of the new BigInteger in bits.rnd - random generator used to generate the new BigInteger.
IllegalArgumentException - if numBits < 0
public BigInteger(int bitLength,
int certainty,
Random rnd)
BigInteger instance in the range [0,
2^(bitLength)-1] which is probably prime. The probability that the
returned BigInteger is prime is beyond (1-1/2^certainty).
bitLength - lenght of the new BigInteger in bits.certainty - tolerated primality uncertainty.rnd - random generator used to generate the new BigInteger.
IllegalArgumentException - if bitLength < 2public BigInteger(String val)
BigInteger instance from the string
representation. The string representation consists of an optional minus
sign followed by a non-empty sequence of decimal digits.
val - string representation of the new BigInteger.
NullPointerException - if val == null.
NumberFormatException - if val is not a valid representation of a BigInteger.
public BigInteger(String val,
int radix)
BigInteger instance from the string
representation. The string representation consists of an optional minus
sign followed by a non-empty sequence of digits in the specified radix.
For the conversion the method Character.digit(char, radix) is
used.
val - string representation of the new BigInteger.radix - the base to be used for the conversion.
NullPointerException - if val == null
NumberFormatException - if val is not a valid representation of a BigInteger
or if radix < Character.MIN_RADIX or radix >
Character.MAX_RADIX.
public BigInteger(int signum,
byte[] magnitude)
BigInteger instance with the given sign and the
given magnitude. The sign is given as an integer (-1 for negative, 0 for
zero, 1 for positive). The magnitude is specified as a byte array. The
most significant byte is the entry at index 0.
signum - sign of the new BigInteger (-1 for negative, 0 for
zero, 1 for positive).magnitude - magnitude of the new BigInteger with the most
significant byte first.
NullPointerException - if magnitude == null
NumberFormatException - if the sign is not one of -1, 0, 1 or if the sign is zero and
the magnitute contains non-zero entries.public BigInteger(byte[] val)
BigInteger from the given two's complement
representation. The most significant byte is the entry at index 0. The
most significant bit of this entry determines the sign of the new
BigInteger instance. The given array must not be empty.
val - two's complement representation of the new BigInteger.
NullPointerException - if val == null
NumberFormatException - if the lenght of val == 0.| Method Detail |
|---|
void establishOldRepresentation(String caller)
BigInteger withNewRepresentation(String caller)
void validate(String caller,
String param)
static void validate1(String caller,
BigInteger a)
static void validate2(String caller,
BigInteger a,
BigInteger b)
static void validate3(String caller,
BigInteger a,
BigInteger b,
BigInteger c)
static void validate4(String caller,
BigInteger a,
BigInteger b,
BigInteger c,
BigInteger d)
public static BigInteger valueOf(long val)
BigInteger whose value is equal to the specified
long argument.
val - the value of the new BigInteger.
BigInteger instance with the value val.public byte[] toByteArray()
this.public BigInteger abs()
BigInteger whose value is the absolute value of
this.
abs(this)public BigInteger negate()
BigInteger whose value is the -this.
-this.public BigInteger add(BigInteger val)
BigInteger whose value is this + val.
val - value to be added to this.
this + val.
NullPointerException - if val == nullpublic BigInteger subtract(BigInteger val)
BigInteger whose value is this - val.
val - value to be subtracted from this.
this - val.
NullPointerException - if val == nullpublic int signum()
BigInteger.
this < 0, 0 if this == 0, 1 if
this > 0.public BigInteger shiftRight(int n)
BigInteger whose value is this >> n. For
negative arguments, the result is also negative. The shift distance may
be negative which means that this is shifted left.
n - shift distance.
public BigInteger shiftLeft(int n)
BigInteger whose value is this << n. The
result is equvalent to this * 2^n if n ≥ 0. The shift
distance may be negative which means that this is shifted right.
The result then corresponds to floor(this / 2^(-n)).
n - shift distance.
public int bitLength()
this
without the sign bit. For positive values this is equivalent to the
number of bits, and for negative values this is equivalent to the number
of bits used to represent -value-1.
mc: In other words: the number a can be coded in
a.bitLength() + 1 bits two's complement.
E.g. for a.bitLength() == 31, an int will hold a correctly and
for a.bitLength() == 32 an int will NOT hold a correctly.
this
without the sign bit.public boolean testBit(int n)
this is set. The result is
equivalent to this & (2^n) != 0.
n - position where the bit in this has to be inspected.
this & (2^n) != 0.
ArithmeticException - if n < 0public BigInteger setBit(int n)
BigInteger which has the same binary representation
as this but with the bit at position n set. The result is
equivalent to this | 2^n.
n - position where the bit in this has to be set.
this | 2^n.
ArithmeticException - if n < 0public BigInteger clearBit(int n)
BigInteger which has the same binary representation
as this but with the bit at position n cleared. The result is
equivalent to this & ~(2^n).
n - position where the bit in this has to be cleared.
this & ~(2^n).
ArithmeticException - if n < 0public BigInteger flipBit(int n)
BigInteger which has the same binary representation
as this but with the bit at position n flipped. The result is
equivalent to this ^ 2^n.
n - position where the bit in this has to be flipped.
this ^ 2^n.
ArithmeticException - if n < 0public int getLowestSetBit()
BigInteger. If all bits are zero (this=0)
then -1 is returned as result.
public int bitCount()
this
wich differ from the sign bit. If this is positive the result is
equivalent to the number of bits set in the binary representation of
this. If this is netative the result is equivalent to
the number of bits set in the binary representation of -this-1.
this wich
differ from the sign bit.public BigInteger not()
BigInteger whose value is ~this. The
result of this operation is -this-1.
~this.public BigInteger and(BigInteger val)
BigInteger whose value is this & val.
val - value to be and'ed with this.
this & val.
NullPointerException - if val == nullpublic BigInteger or(BigInteger val)
BigInteger whose value is this | val.
val - value to be or'ed with this.
this | val.
NullPointerException - if val == nullpublic BigInteger xor(BigInteger val)
BigInteger whose value is this ^ val.
val - value to be xor'ed with this.
this ^ val.
NullPointerException - if val == nullpublic BigInteger andNot(BigInteger val)
BigInteger whose value is this & ~val.
Evaluating x.andNot(val) returns the same result as
x.and(val.not()).
val - value to be not'ed and then and'ed with this.
this & ~val.
NullPointerException - if val == nullpublic int intValue()
BigInteger as an int value. If this is too
big to be represented as an int, then this % 2^32 is returned.
intValue in class NumberBigInteger as an int value.public long longValue()
BigInteger as an long value. If this is too
big to be represented as an long, then this % 2^64 is returned.
longValue in class NumberBigInteger as a long value.public float floatValue()
BigInteger as an float value. If this is too
big to be represented as an float, then Float.POSITIVE_INFINITY
or Float.NEGATIVE_INFINITY is returned. Note, that not all
integers x in the range [-Float.MAX_VALUE, Float.MAX_VALUE] can be
represented as a float. The float representation has a mantissa of length
24. For example, 2^24+1 = 16777217 is returned as float 16777216.0.
floatValue in class NumberBigInteger as a float value.public double doubleValue()
BigInteger as an double value. If this is
too big to be represented as an double, then
Double.POSITIVE_INFINITY or Double.NEGATIVE_INFINITY is
returned. Note, that not all integers x in the range [-Dobule.MAX_VALUE,
Dobule.MAX_VALUE] can be represented as a double. The double
representation has a mantissa of length 53. For example, 2^53+1 =
9007199254740993 is returned as double 9007199254740992.0.
doubleValue in class NumberBigInteger as a double value.public int compareTo(BigInteger val)
BigInteger with val. Returns one of the
three values 1, 0, or -1.
compareTo in interface Comparable<BigInteger>val - value to be compared with this.
NullPointerException - if val == nullpublic BigInteger min(BigInteger val)
BigInteger and val.
val - value to be used to compute the minimum with this.
min(this, val.
NullPointerException - if val == nullpublic BigInteger max(BigInteger val)
BigInteger and val.
val - value to be used to compute the maximum with this.
max(this, val.
NullPointerException - if val == nullpublic int hashCode()
BigInteger.
hashCode in class ObjectObject.equals(java.lang.Object)public boolean equals(Object x)
true if x is a BigInteger instance and if this
instance is equal to this BigInteger.
equals in class Objectx - object to be compared with this.
Object.hashCode()public String toString()
BigInteger in decimal
form.
toString in class Objectthis in decimal form.public String toString(int radix)
BigInteger with base radix. If radix < Character.MIN_RADIX or
radix > Character.MAX_RADIX then a decimal representation is returned.
The characters of the string representation are generated with method
Character.forDigit.
radix - base to be used for the string representation.
public BigInteger gcd(BigInteger val)
BigInteger whose value is greatest common divisor
of this and val. If this==0 and val==0 then zero is
returned, otherwise the result is positive.
val - value with which the greatest common divisor is computed.
gcd(this, val).
NullPointerException - if val == nullpublic BigInteger multiply(BigInteger val)
BigInteger whose value is this * val.
val - value to be multiplied with this.
this * val.
NullPointerException - if val == nullpublic BigInteger pow(int exp)
BigInteger whose value is this ^ exp.
exp - exponent to which this is raised.
this ^ exp.
ArithmeticException - if exp < 0public BigInteger[] divideAndRemainder(BigInteger divisor)
BigInteger array which contains this / divisor
at index 0 and this % divisor at index 1.
divisor - value by which this is divided.
[this / divisor, this % divisor].
NullPointerException - if divisor == null
ArithmeticException - if divisor == 0divide(java.math.BigInteger),
remainder(java.math.BigInteger)public BigInteger divide(BigInteger divisor)
BigInteger whose value is this / divisor.
divisor - value by which this is divided.
this / divisor.
NullPointerException - if divisor == null
ArithmeticException - if divisor == 0public BigInteger remainder(BigInteger divisor)
BigInteger whose value is this % divisor.
Regarding signs this methods has the same behavior as the % operator on
int's, i.e. the sign of the remainder is the same as the sign of this.
divisor - value by which this is divided.
this % divisor.
NullPointerException - if divisor == null
ArithmeticException - if divisor == 0public BigInteger modInverse(BigInteger m)
BigInteger whose value is 1/this mod m.
The modulus m must be positive. The result is guaranteed to be in
the interval [0, m) (0 inclusive, m exclusive). If this
is not relatively prime to m, then an exception is thrown.
m - the modulus.
this mod m.
NullPointerException - if m == null
ArithmeticException - if m < 0 or if this is not relatively prime to m
public BigInteger modPow(BigInteger exponent,
BigInteger m)
BigInteger whose value is
this^exponent mod m. The modulus m must be positive. The
result is guaranteed to be in the interval [0, m) (0 inclusive, m
exclusive). If the exponent is negative, then
this.modInverse(m)^(-exponent) mod m) is computed. The inverse of
this only exists if this is relatively prime to m, otherwise an
exception is thrown.
exponent - the exponent.m - the modulus.
this^exponent mod val.
NullPointerException - if m == null or exponent == null
ArithmeticException - if m < 0 or if exponent<0 and this is not relatively prime
to mpublic BigInteger mod(BigInteger m)
BigInteger whose value is this mod m. The
modulus m must be positive. The result is guaranteed to be in the
interval [0, m) (0 inclusive, m exclusive). The behavior of this
function is not equivalent to the behavior of the % operator defined for
the built-in int's.
m - the modulus.
this mod m.
NullPointerException - if m == null
ArithmeticException - if m < 0public boolean isProbablePrime(int certainty)
BigInteger is probably prime. If true
is returned, then this is prime with a probability beyond
(1-1/2^certainty). If false is returned, then this is definitely
composite. If the argument certainty ≤ 0, then this method
returns true.
certainty - tolerated primality uncertainty.
ture, if this is probably prime, false
otherwise.public BigInteger nextProbablePrime()
this which is probably prime as
a BigInteger instance. The probability that the returned
BigInteger is prime is beyond (1-1/2^100).
this pwhich is robably prime.
ArithmeticException - if this < 0
public static BigInteger probablePrime(int bitLength,
Random rnd)
BigInteger instance in the range [0,
2^(bitLength)-1] which is probably prime. The probability that the
returned BigInteger is prime is beyond (1-1/2^100).
bitLength - lenght of the new BigInteger in bitsrnd - random generator used to generate the new BigInteger.
BigInteger instance
IllegalArgumentException - if bitLength < 2
static int multiplyByInt(int[] res,
int[] a,
int aSize,
int factor)
static int inplaceAdd(int[] a,
int aSize,
int addend)
final void cutOffLeadingZeroes()
numberLength if there are zero high elements.
boolean isOne()
this.abs() is equals to ONE
int getFirstNonzeroDigit()
BigInteger copy()
void unCache()
|
Build 1.0_r1(from source) | |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||