MutableBigInteger

Undocumented in source.
class MutableBigInteger {}

Constructors

this
this()

The default constructor. An empty MutableBigInteger is created with a one word capacity.

this
this(int val)

Construct a new MutableBigInteger with a magnitude specified by the int val.

this
this(int[] val)

Construct a new MutableBigInteger with the specified value array up to the length of the array supplied.

this
this(BigInteger b)

Construct a new MutableBigInteger with a magnitude equal to the specified BigInteger.

this
this(MutableBigInteger val)

Construct a new MutableBigInteger with a magnitude equal to the specified MutableBigInteger.

Members

Functions

add
void add(MutableBigInteger addend)

Adds the contents of two MutableBigInteger objects.The result is placed within this MutableBigInteger. The contents of the addend are not changed.

addDisjoint
void addDisjoint(MutableBigInteger addend, int n)

Like {@link #addShifted(MutableBigInteger, int)} but {@code this.intLen} must not be greater than {@code n}. In other words, concatenates {@code this} and {@code addend}.

addLower
void addLower(MutableBigInteger addend, int n)

Adds the low {@code n} ints of {@code addend}.

addShifted
void addShifted(MutableBigInteger addend, int n)

Adds the value of {@code addend} shifted {@code n} ints to the left. Has the same effect as {@code addend.leftShift(32*ints); add(addend);} but doesn't change the value of {@code addend}.

bitLength
long bitLength()

@see BigInteger#bitLength()

clear
void clear()

Clear out a MutableBigInteger for reuse.

cloneValue
int[] cloneValue()
Undocumented in source. Be warned that the author may not have intended to support it.
compare
int compare(MutableBigInteger b)

Compare the magnitude of two MutableBigIntegers. Returns -1, 0 or 1 as this MutableBigInteger is numerically less than, equal to, or greater than {@code b}.

compareHalf
int compareHalf(MutableBigInteger b)

Compare this against half of a MutableBigInteger object (Needed for remainder tests). Assumes no leading unnecessary zeros, which holds for results from divide().

copyValue
void copyValue(MutableBigInteger src)

Sets this MutableBigInteger's value array to a copy of the specified array. The intLen is set to the length of the new array.

copyValue
void copyValue(int[] val)

Sets this MutableBigInteger's value array to a copy of the specified array. The intLen is set to the length of the specified array.

divide
MutableBigInteger divide(MutableBigInteger b, MutableBigInteger quotient)

Calculates the quotient of this div b and places the quotient in the provided MutableBigInteger objects and the remainder object is returned.

divide
MutableBigInteger divide(MutableBigInteger b, MutableBigInteger quotient, bool needRemainder)
Undocumented in source. Be warned that the author may not have intended to support it.
divide
long divide(long v, MutableBigInteger quotient)

Internally used to calculate the quotient of this div v and places the quotient in the provided MutableBigInteger object and the remainder is returned.

divideAndRemainderBurnikelZiegler
MutableBigInteger divideAndRemainderBurnikelZiegler(MutableBigInteger b, MutableBigInteger quotient)

Computes {@code this/b} and {@code this%b} using the <a href="http://cr.yp.to/bib/1998/burnikel.ps"> Burnikel-Ziegler algorithm</a>. This method implements algorithm 3 from pg. 9 of the Burnikel-Ziegler paper. The parameter beta was chosen to b 2<sup>32</sup> so almost all shifts are multiples of 32 bits.<br/> {@code this} and {@code b} must be nonnegative. @param b the divisor @param quotient output parameter for {@code this/b} @return the remainder

divideKnuth
MutableBigInteger divideKnuth(MutableBigInteger b, MutableBigInteger quotient)

@see #divideKnuth(MutableBigInteger, MutableBigInteger, bool)

divideKnuth
MutableBigInteger divideKnuth(MutableBigInteger b, MutableBigInteger quotient, bool needRemainder)

Calculates the quotient of this div b and places the quotient in the provided MutableBigInteger objects and the remainder object is returned.

divideOneWord
int divideOneWord(int divisor, MutableBigInteger quotient)

This method is used for division of an n word dividend by a one word divisor. The quotient is placed into quotient. The one word divisor is specified by divisor.

euclidModInverse
MutableBigInteger euclidModInverse(int k)

Uses the extended Euclidean algorithm to compute the modInverse of base mod a modulus that is a power of 2. The modulus is 2^k.

hybridGCD
MutableBigInteger hybridGCD(MutableBigInteger b)

Calculate GCD of this and b. This and b are changed by the computation.

isEven
bool isEven()

Returns true iff this MutableBigInteger is even.

isNormal
bool isNormal()

Returns true iff this MutableBigInteger is in normal form. A MutableBigInteger is in normal form if it has no leading zeros after the offset, and intLen + offset <= cast(int)value.length.

isOdd
bool isOdd()

Returns true iff this MutableBigInteger is odd.

isOne
bool isOne()

Returns true iff this MutableBigInteger has a value of one.

isZero
bool isZero()

Returns true iff this MutableBigInteger has a value of zero.

leftShift
void leftShift(int n)

Left shift this MutableBigInteger n bits.

modInverseMP2
MutableBigInteger modInverseMP2(int k)
Undocumented in source. Be warned that the author may not have intended to support it.
mul
void mul(int y, MutableBigInteger z)

Multiply the contents of this MutableBigInteger by the word y. The result is placed into z.

multiply
void multiply(MutableBigInteger y, MutableBigInteger z)

Multiply the contents of two MutableBigInteger objects. The result is placed into MutableBigInteger z. The contents of y are not changed.

mutableModInverse
MutableBigInteger mutableModInverse(MutableBigInteger p)

Returns the modInverse of this mod p. This and p are not affected by the operation.

normalize
void normalize()

Ensure that the MutableBigInteger is in normal form, specifically making sure that there are no leading zeros, and that if the magnitude is zero, then intLen is zero.

reset
void reset()

Set a MutableBigInteger to zero, removing its offset.

rightShift
void rightShift(int n)

Right shift this MutableBigInteger n bits. The MutableBigInteger is left in normal form.

safeLeftShift
void safeLeftShift(int n)

Like {@link #leftShift(int)} but {@code n} can be zero.

safeRightShift
void safeRightShift(int n)

Like {@link #rightShift(int)} but {@code n} can be greater than the length of the number.

setInt
void setInt(int index, int val)

Sets the int at index+offset in this MutableBigInteger to val. This does not get inlined on all platforms so it is not used as often as originally intended.

setValue
void setValue(int[] val, int length)

Sets this MutableBigInteger's value array to the specified array. The intLen is set to the specified length.

sqrt
MutableBigInteger sqrt()

Calculate the integer square root {@code floor(sqrt(this))} where {@code sqrt(.)} denotes the mathematical square root. The contents of {@code this} are <b>not</b> changed. The value of {@code this} is assumed to be non-negative.

subtract
int subtract(MutableBigInteger b)

Subtracts the smaller of this and b from the larger and places the result into this MutableBigInteger.

toBigInteger
BigInteger toBigInteger(int sign)

Convert this MutableBigInteger to a BigInteger object.

toBigInteger
BigInteger toBigInteger()

Converts this number to a nonnegative {@code BigInteger}.

toCompactValue
long toCompactValue(int sign)

This is for internal use in converting from a MutableBigInteger object into a long value given a specified sign. returns INFLATED if value is not fit into long

toIntArray
int[] toIntArray()

Convert this MutableBigInteger into an int array with no leading zeros, of a length that is equal to this MutableBigInteger's intLen.

toString
string toString()

Returns a string representation of this MutableBigInteger in radix 10.

Static functions

binaryGcd
int binaryGcd(int a, int b)

Calculate GCD of a and b interpreted as unsigned integers.

divWord
long divWord(long n, int d)

This method divides a long quantity by an int to estimate qhat for two multi precision numbers. It is used when the signed value of n is less than zero. Returns long value where high 32 bits contain remainder value and low 32 bits contain quotient value.

fixup
MutableBigInteger fixup(MutableBigInteger c, MutableBigInteger p, int k)

The Fixup Algorithm Calculates X such that X = C * 2^(-k) (mod P) Assumes C<P and P is odd.

inverseMod32
int inverseMod32(int val)

Returns the multiplicative inverse of val mod 2^32. Assumes val is odd.

inverseMod64
long inverseMod64(long val)

Returns the multiplicative inverse of val mod 2^64. Assumes val is odd.

modInverseBP2
MutableBigInteger modInverseBP2(MutableBigInteger mod, int k)

Calculate the multiplicative inverse of 2^k mod mod, where mod is odd.

Static variables

ONE
MutableBigInteger ONE;

MutableBigInteger with one element value array with the value 1. Used by BigDecimal divideAndRound to increment the quotient. Use this constant only when the method is not going to modify this object.

Variables

KNUTH_POW2_THRESH_LEN
enum int KNUTH_POW2_THRESH_LEN;

The minimum {@code intLen} for cancelling powers of two before dividing. If the number of ints is less than this threshold, {@code divideKnuth} does not eliminate common powers of two from the dividend and divisor.

KNUTH_POW2_THRESH_ZEROS
enum int KNUTH_POW2_THRESH_ZEROS;

The minimum number of trailing zero ints for cancelling powers of two before dividing. If the dividend and divisor don't share at least this many zero ints at the end, {@code divideKnuth} does not eliminate common powers of two from the dividend and divisor.

intLen
int intLen;

The number of ints of the value array that are currently used to hold the magnitude of this MutableBigInteger. The magnitude starts at an offset and offset + intLen may be less than value.length.

offset
int offset;

The offset into the value array where the magnitude of this MutableBigInteger begins.

value
int[] value;

Holds the magnitude of this MutableBigInteger in big endian order. The magnitude may start at an offset into the value array, and it may end before the length of the value array.

Meta