|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectedu.neu.ccs.XObject
edu.neu.ccs.XNumber
edu.neu.ccs.XBigInteger
XBigInteger is an object wrapper for the
arbitrary precision BigInteger class that
also provides
capabilities. Hence, unlike StringableBigInteger,
objects of this class are mutable.
The default wrapped value for this class is
the BigInteger representation of zero,
.BigInteger.ZERO
This class provides the operations of the class
BigInteger in two forms. Member methods
will mutate the object that is operated on but leave all
parameters unchanged and will return void.
Static methods will create new objects and change no
parameters. In all cases, if an argument to an operation
is null, it is treated as zero.
In addition to the usual string representation of a
big integer as a signed decimal, this class supports a
string bit representation that shows the bits in a
two's complement form that makes it easier to see what
is happening with the bit operations. See the method
toBits for more details.
| Field Summary | |
private static BigInteger |
MINUSONE
The minus-one BigInteger. |
private static String |
negative
The introductory string for the bit represention of negative numbers. |
private static char |
one
The one character for bit parsing. |
private static char |
period
The period character for bit parsing. |
private static String |
positive
The introductory string for the bit represention of positive numbers. |
static String |
standardMessage
The standard error message for fromStringData. |
private BigInteger |
value
The wrapped value of this object. |
private static char |
zero
The zero character for bit parsing. |
private static BigInteger |
ZERO
The zero BigInteger. |
| Fields inherited from class edu.neu.ccs.XObject |
changeAdapter, VALUE |
| Constructor Summary | |
XBigInteger()
Constructs a wrapper for the default BigInteger
value of BigInteger.ZERO. |
|
XBigInteger(BigInteger b)
Constructs a wrapper for the given BigInteger
value. |
|
XBigInteger(byte[] val)
Translates a byte array containing the two's-complement binary representation of a BigInteger into a
BigInteger that is stored internally. |
|
XBigInteger(long n)
Constructs a wrapper for the BigInteger value
corresponding to the given long data. |
|
XBigInteger(String s)
Constructs an XBigInteger using the information
contained in the given string data. |
|
XBigInteger(String s,
int radix)
Constructs an XBigInteger using the information
contained in the given string of digit data in the given radix
with a possible minus sign in front. |
|
XBigInteger(XBigInteger b)
Constructs an XBigInteger by copying the
internal value of the given XBigInteger. |
|
| Method Summary | |
void |
abs()
Sets this to abs(this). |
static XBigInteger |
abs(XBigInteger y)
Returns a new XBigInteger whose value is the absolute
value of the given y. |
void |
add(XBigInteger y)
Sets this to (this + y). |
static XBigInteger |
add(XBigInteger x,
XBigInteger y)
Returns a new XBigInteger whose value is
x + y. |
void |
and(XBigInteger y)
Sets this to (this & y). |
static XBigInteger |
and(XBigInteger x,
XBigInteger y)
Returns a new XBigInteger whose value is
x & y. |
void |
andNot(XBigInteger y)
Sets this to (this & ~y). |
static XBigInteger |
andNot(XBigInteger x,
XBigInteger y)
Returns a new XBigInteger whose value is
x & ~y. |
static XBigInteger |
binomial(int n,
int k)
Returns the binomial coefficient for n, k. |
int |
bitCount()
Returns the number of bits in the two's complement representation of this XBigInteger that differ from its sign bit. |
int |
bitLength()
Returns the number of bits in the minimal two's-complement representation of this XBigInteger, excluding a sign bit. |
byte |
byteValue()
Returns the value of this number as a byte value. |
void |
clearBit(int n)
Sets this to the equivalent value with the
n-th bit cleared. |
static XBigInteger |
clearBit(XBigInteger x,
int n)
Returns a new XBigInteger whose value
is equivalent to x with the
n-th bit cleared. |
int |
compareTo(Object o)
Compares this XBigInteger with the specified
Object o. |
int |
compareTo(XBigInteger y)
Compares this XBigInteger with the specified
XBigInteger y. |
int |
digits()
Returns the number of digits in toString()
excluding the sign if any. |
int |
digits(int radix)
Returns the number of digits in toString(radix)
excluding the sign if any. |
void |
divide(XBigInteger y)
Sets this to (this / y). |
static XBigInteger |
divide(XBigInteger x,
XBigInteger y)
Returns a new XBigInteger whose value is
x / y. |
static XBigInteger[] |
divideAndRemainder(XBigInteger x,
XBigInteger y)
Returns an array { quotient, remainder}
after division of x by y. |
double |
doubleValue()
Returns the value of this number as a double value. |
boolean |
equals(Object other)
Returns true if the given object is of type
XBigInteger and its BigInteger
value is equal to the BigInteger value of
this XBigInteger; returns false
otherwise. |
static XBigInteger |
factorial(int n)
Returns factorial(n), that is, the product of the numbers from 1 to n. |
void |
flipBit(int n)
Sets this to the equivalent value with the
n-th bit flipped. |
static XBigInteger |
flipBit(XBigInteger x,
int n)
Returns a new XBigInteger whose value
is equivalent to x with the
n-th bit flipped. |
float |
floatValue()
Returns the value of this number as a float value. |
private void |
fromBits(String bits)
Sets the state of this XBigInteger by reading
data in the format output by the method toBits. |
void |
fromStringData(String data)
Sets the state of this XBigInteger using the
information contained in the given string data. |
void |
gcd(XBigInteger y)
Sets this to gcd(this, y)
where "gcd" stands for "greatest common divisor". |
static XBigInteger |
gcd(XBigInteger x,
XBigInteger y)
Returns a new XBigInteger whose value is
gcd(x, y) where "gcd" stands for
"greatest common divisor". |
int |
getLowestSetBit()
Returns the index of the rightmost (lowest-order) one bit in this XBigInteger, that is, the number of zero bits to the
right of the rightmost one bit. |
BigInteger |
getValue()
Returns the BigInteger value wrapped
by this object. |
int |
hashCode()
Returns the int hash code
of the wrapped BigInteger value. |
int |
intValue()
Returns the value of this number as a int value. |
boolean |
isProbablePrime(int certainty)
Returns true if this XBigInteger is probably prime,
false if it's definitely composite. |
void |
lcm(XBigInteger y)
Sets this to lcm(this, y)
where "lcm" stands for "least common multiple". |
static XBigInteger |
lcm(XBigInteger x,
XBigInteger y)
Returns a new XBigInteger whose value is
lcm(x, y) where "lcm" stands for
"least common multiple". |
long |
longValue()
Returns the value of this number as a long value. |
void |
max(XBigInteger y)
Sets this to max(this, y). |
static XBigInteger |
max(XBigInteger x,
XBigInteger y)
Returns a new XBigInteger whose value is
the maximum of the given x and y values. |
void |
min(XBigInteger y)
Sets this to min(this, y). |
static XBigInteger |
min(XBigInteger x,
XBigInteger y)
Returns a new XBigInteger whose value is
the minimum of the given x and y values. |
void |
mod(XBigInteger y)
Sets this to (this mod y). |
static XBigInteger |
mod(XBigInteger x,
XBigInteger y)
Returns a new XBigInteger whose value is
x mod y. |
void |
modInverse(XBigInteger y)
Sets this to the inverse modulo y of
this. |
static XBigInteger |
modInverse(XBigInteger x,
XBigInteger y)
Returns a new XBigInteger whose value is
the inverse of x modulo y. |
void |
modPow(XBigInteger e,
XBigInteger y)
Sets this to the value of this
raised to the given exponent e modulo the given modulus y. |
static XBigInteger |
modPow(XBigInteger x,
XBigInteger e,
XBigInteger y)
Returns a new XBigInteger whose value is
the given base x raised to the given exponent e modulo the
given modulus y. |
void |
multiply(XBigInteger y)
Sets this to (this * y). |
static XBigInteger |
multiply(XBigInteger x,
XBigInteger y)
Returns a new XBigInteger whose value is
x * y. |
void |
negate()
Sets this to (-this). |
static XBigInteger |
negate(XBigInteger y)
Returns a new XBigInteger whose value is the negation
of the given y. |
void |
not()
Sets this to (~this),
which is the bitwise-not of the current value. |
static XBigInteger |
not(XBigInteger y)
Returns a new XBigInteger whose value is the
bitwise not of the given y. |
void |
or(XBigInteger y)
Sets this to (this | y). |
static XBigInteger |
or(XBigInteger x,
XBigInteger y)
Returns a new XBigInteger whose value is
x | y. |
void |
pow(int e)
Sets this to the value of this
raised to the given integer exponent e which must be a
non-negative integer. |
static XBigInteger |
pow(XBigInteger x,
int e)
Returns a new XBigInteger whose value is
the given base x raised to the given exponent e which must
be a non-negative integer. |
void |
remainder(XBigInteger y)
Sets this to (this % y). |
static XBigInteger |
remainder(XBigInteger x,
XBigInteger y)
Returns a new XBigInteger whose value is
x % y. |
void |
setBit(int n)
Sets this to the equivalent value with the
n-th bit set. |
static XBigInteger |
setBit(XBigInteger x,
int n)
Returns a new XBigInteger whose value
is equivalent to x with the
n-th bit set. |
void |
setValue(BigInteger b)
Sets the value wrapped by this object to the given BigInteger value. |
void |
setValue(byte[] val)
Translates a byte array containing the two's-complement binary representation of a BigInteger into a
BigInteger that is stored internally in this
XBigInteger. |
void |
setValue(long n)
Sets the value wrapped by this object to the BigInteger value corresponding
to the given long value. |
void |
setValue(String data)
Sets the state of this XBigInteger using the
information contained in the given string data. |
void |
setValue(String s,
int radix)
Sets the state of this XBigInteger using the
information contained in the given string of digit data in
the given radix with a possible minus sign in front. |
void |
setValue(XBigInteger b)
Sets the value wrapped by this object to the internal value of the given XBigInteger value. |
void |
shiftLeft(int n)
Sets this to (this << n);
the shift distance, n, may be negative, in which case this
method performs a right shift. |
static XBigInteger |
shiftLeft(XBigInteger x,
int n)
Returns a new XBigInteger whose value is
(x << n); the shift distance, n, may be
negative, in which case this method performs a right shift. |
void |
shiftRight(int n)
Sets this to (this >> n);
the shift distance, n, may be negative, in which case this
method performs a left shift. |
static XBigInteger |
shiftRight(XBigInteger x,
int n)
Returns a new XBigInteger whose value is
(x >> n); the shift distance, n, may be
negative, in which case this method performs a left shift. |
short |
shortValue()
Returns the value of this number as a short value. |
int |
signum()
Returns -1, 0 or 1 as the value of this XBigInteger
is negative, zero or positive. |
void |
subtract(XBigInteger y)
Sets this to (this - y). |
static XBigInteger |
subtract(XBigInteger x,
XBigInteger y)
Returns a new XBigInteger whose value is
x - y. |
boolean |
testBit(int n)
Returns true if and only if the designated bit is set. |
String |
toBits()
Returns a string representation of the wrapped BigInteger value in a
binary bit representation that is in unsigned
two's complement format. |
static BigInteger[] |
toPrimitiveArray(XBigInteger[] x)
Returns an array of BigInteger objects
initialized from the given array
of XBigInteger objects. |
String |
toString()
Returns the string representation of the wrapped BigInteger value. |
String |
toString(int radix)
Returns the string representation of the wrapped BigInteger value in the given radix. |
String |
toStringData()
Returns a string encapsulation of this XBigInteger
that contains the information needed to set the state of this
XBigInteger at a later time. |
static XBigInteger[] |
toXArray(BigInteger[] a)
Returns an array of XBigInteger objects
initialized from the given array
of BigInteger objects. |
void |
xor(XBigInteger y)
Sets this to (this ^ y). |
static XBigInteger |
xor(XBigInteger x,
XBigInteger y)
Returns a new XBigInteger whose value is
x ^ y. |
| Methods inherited from class edu.neu.ccs.XObject |
addPropertyChangeListener, addPropertyChangeListener, formatErrorMessage, removePropertyChangeListener, removePropertyChangeListener, toStringArray |
| Methods inherited from class java.lang.Object |
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
| Field Detail |
private static final BigInteger ZERO
private static final BigInteger MINUSONE
private static final char zero
private static final char one
private static final char period
private static final String positive
private static final String negative
public static final String standardMessage
private BigInteger value
| Constructor Detail |
public XBigInteger()
Constructs a wrapper for the default BigInteger
value of BigInteger.ZERO.
public XBigInteger(BigInteger b)
Constructs a wrapper for the given BigInteger
value.
If the given value is null, the wrapped value
is set to BigInteger.ZERO.
b - the value to be wrappedpublic XBigInteger(XBigInteger b)
Constructs an XBigInteger by copying the
internal value of the given XBigInteger.
If the given value is null, the wrapped
value is set to BigInteger.ZERO.
b - the value to be copiedpublic XBigInteger(long n)
Constructs a wrapper for the BigInteger value
corresponding to the given long data.
n - a long to encapsulate
public XBigInteger(String s)
throws ParseException
Constructs an XBigInteger using the information
contained in the given string data. Will parse and evaluate
simple big integer arithmetic expressions in decimal format and
will also read data in the special bit format output by the
method toBits.
Makes use of the parsing capabilities of the method
fromStringData(String).
s - a string representation of the desired value
ParseException - if the string is null
or malformed
public XBigInteger(String s,
int radix)
Constructs an XBigInteger using the information
contained in the given string of digit data in the given radix
with a possible minus sign in front.
This constructor makes use of the parsing capabilities of
the method setValue(String, int).
The character-to-digit mapping is provided by
Character.digit.
The string may not contain any extraneous characters (whitespace, for example).
Throws NumberFormatException if:
BigInteger in the specified radixCharacter.MIN_RADIX to
Character.MAX_RADIX, inclusive.
s - a string representation of the desired valueradix - radix to be used in interpreting s
NumberFormatException - as explained abovepublic XBigInteger(byte[] val)
Translates a byte array containing the two's-complement
binary representation of a BigInteger into a
BigInteger that is stored internally.
The input array is assumed to be in big-endian byte-order: the most significant byte is in the zero-th element.
Unlike the corresponding constructor for the Java class
BigInteger, this constructor will set the
internal value to BigInteger.ZERO, if the
given array is null or of length 0.
val - big-endian two's-complement binary representation
of the internal BigInteger| Method Detail |
public final void fromStringData(String data)
throws ParseException
Sets the state of this XBigInteger using the
information contained in the given string data. Will parse
and evaluate simple big integer arithmetic expressions in
decimal format and will also read data in the format output
by the method toBits.
Fires property change: VALUE.
fromStringData in interface StringablefromStringData in class XObjectdata - a string representation of the desired value
ParseException - if the data is null or malformedpublic final String toStringData()
Returns a string encapsulation of this XBigInteger
that contains the information needed to set the state of this
XBigInteger at a later time.
Identical to toString.
toStringData in interface StringabletoStringData in class XObjectpublic final String toString()
Returns the string representation of the wrapped
BigInteger value.
The digit-to-character mapping provided by
Character.forDigit is used,
and a minus sign is prepended if appropriate.
This representation is compatible with the (String) constructor.
public final String toString(int radix)
Returns the string representation of the
wrapped BigInteger value in the given radix.
If the radix is outside the range from
Character.MIN_RADIX to
Character.MAX_RADIX inclusive, it will default
to 10 (as is the case for Integer.toString).
The digit-to-character mapping provided by
Character.forDigit is used,
and a minus sign is prepended if appropriate.
This representation is compatible with the (String, int) constructor.
radix - radix of the string representationpublic String toBits()
Returns a string representation of the
wrapped BigInteger value in a
binary bit representation that is in unsigned
two's complement format.
This representation is quite different from
that returned by this.toString(2)
which is a signed representation with the bits
being those of the corresponding positive value.
Here, a positive value is represented as:
...0bbb
and a negative value is represented as:
...1bbb
where bbb stands for zero or more
binary digits 0,1.
The significance of ...0 is that
there are in principle infinitely many 0 bits to
the left in the bit representation of a positive
big integer.
The significance of ...1 is that
there are in principle infinitely many 1 bits to
the left in the bit representation of a negative
big integer.
The representations returned by this method are visually compatible with the bit operations in this class and therefore make these operations much easier to understand.
The method fromStringData can read
the representations output by this method.
private void fromBits(String bits)
throws ParseException
Sets the state of this XBigInteger by reading
data in the format output by the method toBits.
This is a private helper method for fromStringData.
bits - the string containing the state information in bits
ParseException - if bits is null or malformedpublic final int digits()
Returns the number of digits in toString()
excluding the sign if any.
public final int digits(int radix)
Returns the number of digits in toString(radix)
excluding the sign if any.
If the radix is outside the range from
Character.MIN_RADIX to
Character.MAX_RADIX inclusive, it will default
to 10.
radix - radix of the string representationpublic final boolean equals(Object other)
true if the given object is of type
XBigInteger and its BigInteger
value is equal to the BigInteger value of
this XBigInteger; returns false
otherwise.
other - the object to be comparedpublic final int hashCode()
int hash code
of the wrapped BigInteger value.
public final void setValue(BigInteger b)
Sets the value wrapped by this object to the given
BigInteger value.
If the given value is null, the internal
value is set to BigInteger.ZERO.
Fires property change: VALUE.
b - the value to be wrappedpublic final void setValue(XBigInteger b)
Sets the value wrapped by this object to the internal
value of the given XBigInteger value.
If the given input is null, the internal
value is set to BigInteger.ZERO.
Fires property change: VALUE.
b - the value to be copiedpublic final void setValue(long n)
Sets the value wrapped by this object to the
BigInteger value corresponding
to the given long value.
Uses the static method BigInteger.valueOf
to take advantages of optimizations built into Java.
Fires property change: VALUE.
n - a long to encapsulate
public final void setValue(String data)
throws ParseException
Sets the state of this XBigInteger using the
information contained in the given string data. Will parse
and evaluate simple big integer arithmetic expressions in
decimal format and will also read data in the format output
by the method toBits.
Makes use of the parsing capabilities of the method
fromStringData(String).
Fires property change: VALUE.
data - a string representation of the desired value
ParseException - if the data is null or malformed
public final void setValue(String s,
int radix)
Sets the state of this XBigInteger using the
information contained in the given string of digit data in
the given radix with a possible minus sign in front.
The character-to-digit mapping is provided by
Character.digit.
The string may not contain any extraneous characters (whitespace, for example).
Throws NumberFormatException if:
BigInteger in the specified radixCharacter.MIN_RADIX to
Character.MAX_RADIX, inclusive.
s - a string representation of the desired valueradix - radix to be used in interpreting s
NumberFormatException - as explained abovepublic final void setValue(byte[] val)
Translates a byte array containing the two's-complement
binary representation of a BigInteger into a
BigInteger that is stored internally in this
XBigInteger.
The input array is assumed to be in big-endian byte-order: the most significant byte is in the zero-th element.
This method will set the internal value to
BigInteger.ZERO, if the given array is
null or of length 0.
Fires property change: VALUE.
val - big-endian two's-complement binary representation
of the internal BigIntegerpublic final BigInteger getValue()
Returns the BigInteger value wrapped
by this object.
public final byte byteValue()
XNumberbyte value.
byteValue in class XNumberpublic final short shortValue()
XNumbershort value.
shortValue in class XNumberpublic final int intValue()
XNumberint value.
intValue in class XNumberpublic final long longValue()
XNumberlong value.
longValue in class XNumberpublic final float floatValue()
XNumberfloat value.
floatValue in class XNumberpublic final double doubleValue()
XNumberdouble value.
doubleValue in class XNumberpublic final int signum()
Returns -1, 0 or 1 as the value of this XBigInteger
is negative, zero or positive.
public final void abs()
Sets this to abs(this).
Fires property change: VALUE.
public static XBigInteger abs(XBigInteger y)
Returns a new XBigInteger whose value is the absolute
value of the given y.
y - the explicit argumentpublic final void negate()
Sets this to (-this).
Mathematically, (-this) equals
(~this)+1.
Fires property change: VALUE.
public static XBigInteger negate(XBigInteger y)
Returns a new XBigInteger whose value is the negation
of the given y.
Mathematically, (-y) equals
(~y)+1.
y - the explicit argumentpublic final void max(XBigInteger y)
Sets this to max(this, y).
Fires property change: VALUE.
y - the explicit argument
public static XBigInteger max(XBigInteger x,
XBigInteger y)
Returns a new XBigInteger whose value is
the maximum of the given x and y values.
x - the LHS argumenty - the RHS argumentpublic final void min(XBigInteger y)
Sets this to min(this, y).
Fires property change: VALUE.
y - the explicit argument
public static XBigInteger min(XBigInteger x,
XBigInteger y)
Returns a new XBigInteger whose value is
the minimum of the given x and y values.
x - the LHS argumenty - the RHS argumentpublic final void add(XBigInteger y)
Sets this to (this + y).
Fires property change: VALUE.
y - the explicit argument
public static XBigInteger add(XBigInteger x,
XBigInteger y)
Returns a new XBigInteger whose value is
x + y.
x - the LHS argumenty - the RHS argumentpublic final void subtract(XBigInteger y)
Sets this to (this - y).
Fires property change: VALUE.
y - the explicit argument
public static XBigInteger subtract(XBigInteger x,
XBigInteger y)
Returns a new XBigInteger whose value is
x - y.
x - the LHS argumenty - the RHS argumentpublic final void multiply(XBigInteger y)
Sets this to (this * y).
Fires property change: VALUE.
y - the explicit argument
public static XBigInteger multiply(XBigInteger x,
XBigInteger y)
Returns a new XBigInteger whose value is
x * y.
x - the LHS argumenty - the RHS argumentpublic final void divide(XBigInteger y)
Sets this to (this / y).
Fires property change: VALUE.
y - the explicit argument
ArithmeticException - on division by zero
public static XBigInteger divide(XBigInteger x,
XBigInteger y)
Returns a new XBigInteger whose value is
x / y.
x - the LHS argumenty - the RHS argument
ArithmeticException - on division by zeropublic final void remainder(XBigInteger y)
Sets this to (this % y).
Fires property change: VALUE.
y - the explicit argument
ArithmeticException - on division by zero
public static XBigInteger remainder(XBigInteger x,
XBigInteger y)
Returns a new XBigInteger whose value is
x % y.
x - the LHS argumenty - the RHS argument
ArithmeticException - on division by zero
public static XBigInteger[] divideAndRemainder(XBigInteger x,
XBigInteger y)
Returns an array {quotient, remainder}
after division of x by y.
x - the LHS argumenty - the RHS argument
ArithmeticException - on division by zeropublic final void mod(XBigInteger y)
Sets this to (this mod y).
This method differs from remainder in that it
always returns a non-negative XBigInteger.
Throws an ArithmeticException if y is
null or is less than or equal to zero.
Fires property change: VALUE.
y - the explicit argument
ArithmeticException - on division by zero
public static XBigInteger mod(XBigInteger x,
XBigInteger y)
Returns a new XBigInteger whose value is
x mod y.
This method differs from remainder in that it
always returns a non-negative XBigInteger.
Throws an ArithmeticException if y is
null or is less than or equal to zero.
x - the LHS argumenty - the RHS argument
ArithmeticException - on division by zeropublic final void modInverse(XBigInteger y)
Sets this to the inverse modulo y of
this.
Throws an ArithmeticException if y is
null or is less than or equal to zero
or if this number is not relatively prime to y.
Fires property change: VALUE.
y - the explicit argument
ArithmeticException - as explained above
public static XBigInteger modInverse(XBigInteger x,
XBigInteger y)
Returns a new XBigInteger whose value is
the inverse of x modulo y.
Throws an ArithmeticException if y is
null or is less than or equal to zero
or if x is null or is not relatively
prime to y.
x - the LHS argumenty - the RHS argument
ArithmeticException - as explained abovepublic final void pow(int e)
Sets this to the value of this
raised to the given integer exponent e which must be a
non-negative integer.
Throws an ArithmeticException if the given
integer exponent is negative.
Fires property change: VALUE.
e - the non-negative integer exponent
ArithmeticException - as explained above
public static XBigInteger pow(XBigInteger x,
int e)
Returns a new XBigInteger whose value is
the given base x raised to the given exponent e which must
be a non-negative integer.
Throws an ArithmeticException if the given
integer exponent is negative.
x - the basee - the non-negative integer exponent
ArithmeticException - as explained above
public final void modPow(XBigInteger e,
XBigInteger y)
Sets this to the value of this
raised to the given exponent e modulo the given modulus y.
Throws an ArithmeticException if:
this is not relatively prime to yFires property change: VALUE.
e - the exponenty - the modulus
ArithmeticException - as explained above
public static XBigInteger modPow(XBigInteger x,
XBigInteger e,
XBigInteger y)
Returns a new XBigInteger whose value is
the given base x raised to the given exponent e modulo the
given modulus y.
Throws an ArithmeticException if:
x is not relatively prime to y
x - the basee - the exponenty - the modulus
ArithmeticException - as explained abovepublic final void gcd(XBigInteger y)
Sets this to gcd(this, y)
where "gcd" stands for "greatest common divisor".
The "gcd" is always greater than or equal to zero
and is zero if and only if both this and
y are zero.
Fires property change: VALUE.
y - the explicit argument
public static XBigInteger gcd(XBigInteger x,
XBigInteger y)
Returns a new XBigInteger whose value is
gcd(x, y) where "gcd" stands for
"greatest common divisor".
The "gcd" is always greater than or equal to zero
and is zero if and only if both x and
y are zero.
x - the LHS argumenty - the RHS argumentpublic final void lcm(XBigInteger y)
Sets this to lcm(this, y)
where "lcm" stands for "least common multiple".
The "lcm" is always greater than or equal to zero
and is zero if and only if both this and
y are zero.
Fires property change: VALUE.
y - the explicit argument
public static XBigInteger lcm(XBigInteger x,
XBigInteger y)
Returns a new XBigInteger whose value is
lcm(x, y) where "lcm" stands for
"least common multiple".
The "lcm" is always greater than or equal to zero
and is zero if and only if both x and
y are zero.
x - the LHS argumenty - the RHS argumentpublic final void shiftLeft(int n)
Sets this to (this << n);
the shift distance, n, may be negative, in which case this
method performs a right shift.
Fires property change: VALUE.
n - the left shift in bits
public static XBigInteger shiftLeft(XBigInteger x,
int n)
Returns a new XBigInteger whose value is
(x << n); the shift distance, n, may be
negative, in which case this method performs a right shift.
x - the value to shiftn - the left shift in bitspublic final void shiftRight(int n)
Sets this to (this >> n);
the shift distance, n, may be negative, in which case this
method performs a left shift.
Fires property change: VALUE.
n - the right shift in bits
public static XBigInteger shiftRight(XBigInteger x,
int n)
Returns a new XBigInteger whose value is
(x >> n); the shift distance, n, may be
negative, in which case this method performs a left shift.
x - the value to shiftn - the right shift in bitspublic final void not()
Sets this to (~this),
which is the bitwise-not of the current value.
Mathematically, (~this) equals
-(this+1).
Fires property change: VALUE.
public static XBigInteger not(XBigInteger y)
Returns a new XBigInteger whose value is the
bitwise not of the given y.
Mathematically, (~y) equals
-(y+1).
y - the explicit argumentpublic final void and(XBigInteger y)
Sets this to (this & y).
The value set is negative if and only if
this and y are both negative.
Fires property change: VALUE.
y - the explicit argument
public static XBigInteger and(XBigInteger x,
XBigInteger y)
Returns a new XBigInteger whose value is
x & y.
The value returned is negative if and only if
x and y are both negative.
x - the LHS argumenty - the RHS argumentpublic final void or(XBigInteger y)
Sets this to (this | y).
The value set is negative if and only if at least one
of this and y is negative.
Fires property change: VALUE.
y - the explicit argument
public static XBigInteger or(XBigInteger x,
XBigInteger y)
Returns a new XBigInteger whose value is
x | y.
The value returned is negative if and only if at least
one of x and y is negative.
x - the LHS argumenty - the RHS argumentpublic final void xor(XBigInteger y)
Sets this to (this ^ y).
The value set is negative if and only if exactly one
of this and y is negative.
Fires property change: VALUE.
y - the explicit argument
public static XBigInteger xor(XBigInteger x,
XBigInteger y)
Returns a new XBigInteger whose value is
x ^ y.
The value returned is negative if and only if exactly
one of x and y is negative.
x - the LHS argumenty - the RHS argumentpublic final void andNot(XBigInteger y)
Sets this to (this & ~y).
The value set is negative if and only if
this is negative and
y is positive.
Fires property change: VALUE.
y - the explicit argument
public static XBigInteger andNot(XBigInteger x,
XBigInteger y)
Returns a new XBigInteger whose value is
x & ~y.
The value returned is negative if and only if
x is negative and
y is positive.
x - the LHS argumenty - the RHS argumentpublic final boolean testBit(int n)
Returns true if and only if the designated bit is set.
Computes ((this & (1<<n)) != 0).
Throws ArithmeticException if n is negative.
n - index of bit to test
ArithmeticException - if n is negativepublic final void setBit(int n)
Sets this to the equivalent value with the
n-th bit set.
In other words, sets this to
(this|(1<<n)).
Fires property change: VALUE.
Throws ArithmeticException if n is negative.
n - the bit to modify
public static XBigInteger setBit(XBigInteger x,
int n)
Returns a new XBigInteger whose value
is equivalent to x with the
n-th bit set.
In other words, returns
(x|(1<<n)).
Throws ArithmeticException if n is negative.
x - the initial valuen - the bit to modifypublic final void clearBit(int n)
Sets this to the equivalent value with the
n-th bit cleared.
In other words, sets this to
(this&~(1<<n)).
Fires property change: VALUE.
Throws ArithmeticException if n is negative.
n - the bit to modify
public static XBigInteger clearBit(XBigInteger x,
int n)
Returns a new XBigInteger whose value
is equivalent to x with the
n-th bit cleared.
In other words, returns
(x&~(1<<n)).
Throws ArithmeticException if n is negative.
x - the initial valuen - the bit to modifypublic final void flipBit(int n)
Sets this to the equivalent value with the
n-th bit flipped.
In other words, sets this to
(this^(1<<n)).
Fires property change: VALUE.
Throws ArithmeticException if n is negative.
n - the bit to modify
public static XBigInteger flipBit(XBigInteger x,
int n)
Returns a new XBigInteger whose value
is equivalent to x with the
n-th bit flipped.
In other words, returns
(x^(1<<n)).
Throws ArithmeticException if n is negative.
x - the initial valuen - the bit to modifypublic final int getLowestSetBit()
Returns the index of the rightmost (lowest-order) one bit in this
XBigInteger, that is, the number of zero bits to the
right of the rightmost one bit.
Returns -1 if this XBigInteger contains no one bits.
Computes ((this == 0) ? -1 : log2(this & -this)).
public final int bitLength()
Returns the number of bits in the minimal two's-complement
representation of this XBigInteger, excluding a sign bit.
For positive XBigInteger's, this is equivalent to the
number of bits in the ordinary binary representation.
Computes (ceil(log2(this < 0 ? -this : (this+1)))).
public final int bitCount()
Returns the number of bits in the two's complement representation
of this XBigInteger that differ from its sign bit. This
method is useful when implementing bit-vector style sets atop
XBigInteger's.
public final boolean isProbablePrime(int certainty)
Returns true if this XBigInteger is probably prime,
false if it's definitely composite.
If certainty <= 0, true is returned.
If the call returns true, the probability that this
XBigInteger is prime exceeds (1 - 1/n) where n equals
2 raised to the power certainty. The execution time of this method
is proportional to the value of this parameter.
certainty - a measure of the uncertainty that the caller is
willing to toleratepublic final int compareTo(XBigInteger y)
Compares this XBigInteger with the specified
XBigInteger y.
This method is provided in preference to individual methods for each of the six boolean comparison operators:
==, !=, <, <=, >, >=The suggested idiom for performing these comparisons is:
(x.compareTo(y) <op> 0)
where <op> is one of the six comparison
operators.
Throws NullPointerException if the given object
y is null. Since this method is not specified in
the interface Comparable, we throw the natural
exception rather than ClassCastException which
is required in the more generic compareTo(Object)
method.
y - the explicit argument
NullPointerException - if y is nullpublic final int compareTo(Object o)
Compares this XBigInteger with the specified
Object o.
This method is provided in preference to individual methods for each of the six boolean comparison operators:
==, !=, <, <=, >, >=The suggested idiom for performing these comparisons is:
(x.compareTo(y) <op> 0)
where <op> is one of the six comparison
operators.
Throws ClassCastException if the given object is
null or is not of type XBigInteger.
This is consistent with the specification of the interface
Comparable which this method implements.
compareTo in interface Comparableo - the Object to compare
ClassCastException - if o is null or not of
type XBigIntegerpublic static XBigInteger factorial(int n)
Returns factorial(n), that is, the product of the numbers from 1 to n.
This is equal to the number of permutations of a set of size n when n >= 0.
Returns 1 if n is 0 or 1 and returns 0 if n is negative.
n - the set size
public static XBigInteger binomial(int n,
int k)
Returns the binomial coefficient for n, k.
When n >= k >= 0, this is equal to the number of subsets of size k in a set of size n.
Returns 1 if k is 0 and 0 if k is negative.
Computes: (n*...*(n-k+1)) / (k*...*1).
For k >= 0, the binomial coefficient is a polynomial of degree k in the parameter n. This polynomial is characterized by two conditions.
In particular, this polynomial has well-defined values when n is negative. These values are positive if k is even and negative if k is odd as is easily seen from the formula given above.
n - the set sizek - the subset sizepublic static BigInteger[] toPrimitiveArray(XBigInteger[] x)
Returns an array of BigInteger objects
initialized from the given array
of XBigInteger objects.
x - an array of XBigIntegerspublic static XBigInteger[] toXArray(BigInteger[] a)
Returns an array of XBigInteger objects
initialized from the given array
of BigInteger objects.
a - an array of BigIntegers
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||