uk.ac.leeds.ccg.andyt.generic.math
Class Generic_BigInteger

java.lang.Object
  extended by uk.ac.leeds.ccg.andyt.generic.math.Generic_Number
      extended by uk.ac.leeds.ccg.andyt.generic.math.Generic_BigInteger
All Implemented Interfaces:
java.io.Serializable

public class Generic_BigInteger
extends Generic_Number
implements java.io.Serializable

See Also:
Serialized Form

Field Summary
 java.util.TreeMap<java.lang.Integer,java.math.BigInteger> _Factorial_TreeMap
           
 java.util.TreeMap<java.lang.Integer,java.math.BigInteger> _PowersOfTwo_TreeMap
           
static java.math.BigInteger Hundred
           
static java.math.BigInteger Integer_MAX_VALUE
           
static java.math.BigInteger Integer_MIN_VALUE
           
static java.math.BigInteger Long_MAX_VALUE
           
static java.math.BigInteger Long_MIN_VALUE
           
static java.math.BigInteger Three
           
static java.math.BigInteger Two
           
 
Fields inherited from class uk.ac.leeds.ccg.andyt.generic.math.Generic_Number
_RandomArray
 
Constructor Summary
Generic_BigInteger()
          Creates a new instance of Generic_BigDecimal
Generic_BigInteger(Generic_BigInteger _Generic_BigInteger)
          Creates a new instance of Generic_BigDecimal
 
Method Summary
protected  java.math.BigInteger addPowerOfTwo()
          Adds and returns a power of 2 to _PowersOfTwo_TreeMap
static java.math.BigInteger ceiling(java.math.BigDecimal x)
           
protected static java.math.BigDecimal exp(java.math.BigInteger y, Generic_BigDecimal a_Generic_BigDecimal, int decimalPlaces, java.math.RoundingMode a_RoundingMode)
          e^y = 1 + y/1! + y^2/2! + y^3/3! +...
 java.math.BigInteger factorial(java.lang.Integer x)
          Adds values to _Factorial_TreeMap if they do not already exist.
static java.math.BigInteger floor(java.math.BigDecimal x)
           
 java.util.TreeMap<java.lang.Integer,java.math.BigInteger> get_PowersOfTwo_TreeMap()
           
 java.util.TreeMap<java.lang.Integer,java.math.BigInteger> getPowersOfTwo(java.math.BigInteger x)
           
 java.util.TreeMap<java.lang.Integer,java.lang.Integer> getPowersOfTwoDecomposition(java.math.BigInteger x)
          The result provides the binary encoding for x
 java.math.BigInteger getRandom(java.math.BigInteger upperLimit)
          There are methods to get large random numbers.
 java.math.BigInteger getRandom(java.util.Random a_Random, java.math.BigInteger upperLimit)
           
protected  void init_Factorial_TreeMap()
          Initialises _Factorial_TreeMap
protected  void init_PowersOfTwo_TreeMap()
          Initialises _Factorial_TreeMap
static boolean isEven(java.math.BigInteger x)
          Implementation tests the remainder when divided by 2.
static void main(java.lang.String[] args)
           
static java.math.BigInteger max(java.math.BigInteger x, java.math.BigInteger y)
           
static java.math.BigInteger min(java.math.BigInteger x, java.math.BigInteger y)
           
static java.math.BigDecimal power(java.math.BigInteger x, int y, int decimalPlaces, java.math.RoundingMode a_RoundingMode)
           
static java.math.BigDecimal power(java.math.BigInteger x, long y, int decimalPlaces, java.math.RoundingMode a_RoundingMode)
           
 java.math.BigInteger powerOfTwo(java.lang.Integer x)
          Adds values to _PowersOfTwo_TreeMap if they do not already exist.
static java.math.BigDecimal reciprocal(java.math.BigInteger x, int decimalPlaces, java.math.RoundingMode a_RoundingMode)
           
 
Methods inherited from class uk.ac.leeds.ccg.andyt.generic.math.Generic_Number
get_RandomArray, get_RandomArray, get_RandomArrayMinLength, init_RandomArrayMinLength, timeReport
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

Two

public static final java.math.BigInteger Two

Three

public static final java.math.BigInteger Three

Hundred

public static final java.math.BigInteger Hundred

Integer_MIN_VALUE

public static final java.math.BigInteger Integer_MIN_VALUE

Integer_MAX_VALUE

public static final java.math.BigInteger Integer_MAX_VALUE

Long_MIN_VALUE

public static final java.math.BigInteger Long_MIN_VALUE

Long_MAX_VALUE

public static final java.math.BigInteger Long_MAX_VALUE

_Factorial_TreeMap

public transient java.util.TreeMap<java.lang.Integer,java.math.BigInteger> _Factorial_TreeMap

_PowersOfTwo_TreeMap

public transient java.util.TreeMap<java.lang.Integer,java.math.BigInteger> _PowersOfTwo_TreeMap
Constructor Detail

Generic_BigInteger

public Generic_BigInteger()
Creates a new instance of Generic_BigDecimal


Generic_BigInteger

public Generic_BigInteger(Generic_BigInteger _Generic_BigInteger)
Creates a new instance of Generic_BigDecimal

Method Detail

main

public static void main(java.lang.String[] args)
Parameters:
args - the command line arguments

init_Factorial_TreeMap

protected void init_Factorial_TreeMap()
Initialises _Factorial_TreeMap


init_PowersOfTwo_TreeMap

protected void init_PowersOfTwo_TreeMap()
Initialises _Factorial_TreeMap


ceiling

public static java.math.BigInteger ceiling(java.math.BigDecimal x)
Parameters:
x -
Returns:
If x is an integer then return a BigInteger value of x. Otherwise return the next integer further away from zero;

floor

public static java.math.BigInteger floor(java.math.BigDecimal x)
Parameters:
x -
Returns:
If x is an integer then return a BigInteger value of x. Otherwise return the next integer closer to zero;

max

public static java.math.BigInteger max(java.math.BigInteger x,
                                       java.math.BigInteger y)
Parameters:
x -
y -
Returns:
the larger (closer to positive infinity) of either x or y

min

public static java.math.BigInteger min(java.math.BigInteger x,
                                       java.math.BigInteger y)
Parameters:
x -
y -
Returns:
the larger (closer to negative infinity) of either x or y

factorial

public java.math.BigInteger factorial(java.lang.Integer x)
Adds values to _Factorial_TreeMap if they do not already exist.

Parameters:
x -
Returns:
x! as a BigInteger

powerOfTwo

public java.math.BigInteger powerOfTwo(java.lang.Integer x)
Adds values to _PowersOfTwo_TreeMap if they do not already exist.

Parameters:
x -
Returns:
2^^x as a BigInteger

addPowerOfTwo

protected java.math.BigInteger addPowerOfTwo()
Adds and returns a power of 2 to _PowersOfTwo_TreeMap


get_PowersOfTwo_TreeMap

public java.util.TreeMap<java.lang.Integer,java.math.BigInteger> get_PowersOfTwo_TreeMap()

getPowersOfTwo

public java.util.TreeMap<java.lang.Integer,java.math.BigInteger> getPowersOfTwo(java.math.BigInteger x)
Parameters:
x -
Returns:
all the powers of two less than or equal to x

getPowersOfTwoDecomposition

public java.util.TreeMap<java.lang.Integer,java.lang.Integer> getPowersOfTwoDecomposition(java.math.BigInteger x)
The result provides the binary encoding for x

Parameters:
x -
Returns:

power

public static java.math.BigDecimal power(java.math.BigInteger x,
                                         int y,
                                         int decimalPlaces,
                                         java.math.RoundingMode a_RoundingMode)
Parameters:
x -
y -
Returns:
x^y

power

public static java.math.BigDecimal power(java.math.BigInteger x,
                                         long y,
                                         int decimalPlaces,
                                         java.math.RoundingMode a_RoundingMode)
Parameters:
x -
y -
Returns:
x^y

reciprocal

public static java.math.BigDecimal reciprocal(java.math.BigInteger x,
                                              int decimalPlaces,
                                              java.math.RoundingMode a_RoundingMode)
Parameters:
x -
decimalPlaces -
a_RoundingMode -
Returns:
1/x Accurate to decimalPlace number of decimal places. If x = 0 then an IllegalArgumentException is thrown

exp

protected static java.math.BigDecimal exp(java.math.BigInteger y,
                                          Generic_BigDecimal a_Generic_BigDecimal,
                                          int decimalPlaces,
                                          java.math.RoundingMode a_RoundingMode)
e^y = 1 + y/1! + y^2/2! + y^3/3! +...

Parameters:
y -
decimalPlaces -
Returns:
e^y where e is the Euler constant to a sufficient precision to return the result accurate to the requested precision.

getRandom

public java.math.BigInteger getRandom(java.math.BigInteger upperLimit)
There are methods to get large random numbers. This method would only give un-bias results for upperLimit being a number made of only 9's such as 99999. The problem with any other number is that there is an uneven distribution of decimal digits skewed towards 1. There are many more 1's in the numbers 0 to 1234567 than there are any other number, second most common is 2 and so on. For any range of numbers this distribution is different. There is a constructor method for BigDecimal that supports this, but only for uniform distributions over a binary power range.

Parameters:
a_Random -
upperLimit -
Returns:
a random integer as a BigInteger between 0 and upperLimit inclusive

getRandom

public java.math.BigInteger getRandom(java.util.Random a_Random,
                                      java.math.BigInteger upperLimit)

isEven

public static boolean isEven(java.math.BigInteger x)
Implementation tests the remainder when divided by 2.

Parameters:
x -
Returns:
true iff x is even (ends in 0,2,4,6,8)