Maven module :un.api : api-math :
Class : un.impl.number.LargeInteger
Extends/Implements : un.api.Orderable un.impl.number.un.api.number.Number
Subclasses : -

LargeInteger is an immutable arbitrary length integer.
author  Bertrand COTE


Variables : ZERO, ONE, TWO
Functions : LargeInteger, LargeInteger, LargeInteger, LargeInteger, LargeInteger, LargeInteger, LargeInteger, LargeInteger, LargeInteger, toHexString, toString, getSign, getMagnitude, getByteLength, getBitLength, getBit, equals, hashCode, order, add, subtract, mult, divide, zero, isZero, one, isOne, pow, not, and, andNot, or, xor, shiftRight, shiftLeft, toInteger, toLong, toFloat, toDouble, divideAndRemainder, mod, negate, abs, pow, modPow, modPowFast, modInverse, floorSqrt, extendedEuclid, gcd, simplify




public LargeInteger ZERO

public LargeInteger ONE

public LargeInteger TWO



Default constructor. (Constructs ZERO element.)
public void LargeInteger ()


Copy constructor.
param  other any LargeInteger.
public void LargeInteger (LargeInteger other)


Constructor from a signed 64bits integer (long).
param  n a signed 64bits integer (long).
public void LargeInteger (long n)


param  sign 1 for positive, 0 for zero and -1 for negative.
param  magnitude a long array (LSB at index 0 and MSB at last index).
public void LargeInteger (int sign, long[] magnitude)


param  sign 1 for positive, 0 for zero and -1 for negative.
param  magnitudeBytes a byte array (LSB at index 0 and MSB at last index).
public void LargeInteger (int sign, byte[] magnitudeBytes)


Converts the given char array to its LargeInteger value in the given radix.
param  cArray
param  radix the base in which the value in cArray is given (E.g.: 16 for hexadecimal, 10 for decimal or 8 for octal).
public void LargeInteger (char[] cArray, int radix)


Converts the given char array to its LargeIneger value.
By default, radix is set to 10. If cArray begins with "0x", then radix is set
to 16 (hexadecimal); and if cArray only begins with "0", then the radix is set
to 8 (octal).


Examples:


@param cArray
public void LargeInteger (char[] cArray)

public void LargeInteger (String s, int radix)

public void LargeInteger (String s)



public String toHexString ()

public String toString ()



@return the sign of this.
public int getSign ()


return  a copy of the magnitude.
public long[] getMagnitude ()


Computes the number of bytes needed to encode this's magnitude.

@return the number of bytes needed to encode this's magnitude.
public int getByteLength ()


Computes the number of bits needed to encode this's magnitude.

@return the number of bits needed to encode this's magnitude.
public int getBitLength ()


Returns the state of the bit at index bitIndex.
param  bitIndex
return
public boolean getBit (int bitIndex)



public boolean equals (Object otherObject)

public int hashCode ()

public int order (Object otherObject)


{@link un.science.math.Arithmetic#add Arithmetic.add}.

@param otherArithmetic a LargeInteger.
@return this + otherArithmetic.
public LargeInteger add (Arithmetic otherArithmetic)


{@link un.science.math.Arithmetic#subtract Arithmetic.subtract}.

@param otherArithmetic a LargeInteger.
@return this - otherArithmetic.
public LargeInteger subtract (Arithmetic otherArithmetic)


{@link un.science.math.Arithmetic#mult Arithmetic.mult}.

@param otherArithmetic a LargeInteger.
@return this * otherArithmetic.
public LargeInteger mult (Arithmetic otherArithmetic)


{@link un.science.math.Arithmetic#divide Arithmetic.divide}.

@param otherArithmetic a LargeInteger (different from ZERO).
@return this / otherArithmetic.
public LargeInteger divide (Arithmetic otherArithmetic)


{@link un.science.math.Arithmetic#zero Arithmetic.zero}.
@return
public LargeInteger zero ()


{@link un.science.math.Arithmetic#isZero Arithmetic.isZero}.
@return
public boolean isZero ()


{@link un.science.math.Arithmetic#one Arithmetic.one}.
@return
public LargeInteger one ()


{@link un.science.math.Arithmetic#isOne Arithmetic.isOne}.
@return
public boolean isOne ()


{@link un.science.math.Arithmetic#pow Arithmetic.pow}.
@param n
@return
public LargeInteger pow (int n)


@return ~this.
public LargeInteger not ()


param  other
return  this and other.
public LargeInteger and (LargeInteger other)


@param other
@return this and ~other.
public LargeInteger andNot (LargeInteger other)


param  other
return  this | other.
public LargeInteger or (LargeInteger other)


param  other
return  this ^^other.
public LargeInteger xor (LargeInteger other)


Right shift of bitShift bits (equivalent of this >> bitShift).
param  bitShift
return  this >> bitShift.
public LargeInteger shiftRight (int bitShift)


Left shift of bitShift bits (equivalent of this << bitShift).
param  bitShift
return  this << bitShift.
public LargeInteger shiftLeft (int bitShift)



public int toInteger ()


Convert this to it's long value.
return  (long)this.
public long toLong ()


Convert this to it's float value.
return  (float)this.
public float toFloat ()


Convert this to it's float value.
return  (double)this.
public double toDouble ()


Divides this by other and returns the quotient and the remainder.


@param other
@return { quotient, remainder }
public LargeInteger[] divideAndRemainder (LargeInteger other)


Computes this modulus other.
param  other
return  this % other.
public LargeInteger mod (LargeInteger other)


Negates this.
return  -this.
public LargeInteger negate ()

public LargeInteger abs ()


Computes and returns this raised to the power exponent.
param  exponent
return  this^n
public LargeInteger pow (LargeInteger exponent)


Computes and returns this raised to the power exponent, modulo modulus.
param  exponent
param  modulus
return  this^n modulo modulus
public LargeInteger modPow (LargeInteger exponent, LargeInteger modulus)


Perform fast modular exponentiation using Montgomery reduction.
source: https://en.wikipedia.org/wiki/Montgomery_modular_multiplication
param  exponent
param  modulus
return  this^exponent % modulus
public LargeInteger modPowFast (LargeInteger exponent, LargeInteger modulus)


Computes n such that this*n == 1 mod modulus. If n doesn't exists, returns null.
@param modulus
@return n such that this*n == 1 mod modulus. If n doesn't exists, returns null.
public LargeInteger modInverse (LargeInteger modulus)


Computes floor( sqrt( this ) ) using the Babylonian method.
https://en.wikipedia.org/wiki/Methods_of_computing_square_roots#Babylonian_method
return  floor( sqrt( this ) )
public LargeInteger floorSqrt ()


Computes a, b and gcd(this,other) such that
a*max(this,other) + b*min(this,other) = gcd(this,other)
using extended Euclid algorithm.
this and other must be positive LargeIntegers.
param  other a positive LargeIntegers.
return  { a, b, gcd(this, other) } such that a*max(this,other) + b*min(x,other) = gcd(this,other).
public LargeInteger[] extendedEuclid (LargeInteger other)


The gcd of this and other is the largest positive integer that
divides those numbers without remainder.


https://en.wikipedia.org/wiki/Greatest_common_divisor

@param other a positive LargeIntegers.
@return the largest positive integer that divides this and other without a remainder.
public LargeInteger gcd (LargeInteger other)


Computes n such that n is the higher integer such that this can be
written as LargeInteger*2.pow(n).(n is the count of 0 bits beginning mag)

(Used in simplifications in LargeDecimal)

@return n the count of 0 bits beginning the magnitude.
public int simplify ()