org.znerd.math
Class BigIntegerNumber

java.lang.Object
  extended byjava.lang.Number
      extended byorg.znerd.math.RealNumber
          extended byorg.znerd.math.RationalNumber
              extended byorg.znerd.math.IntegerNumber
                  extended byorg.znerd.math.BigIntegerNumber
All Implemented Interfaces:
Comparable, RoundingModes, Serializable

public final class BigIntegerNumber
extends IntegerNumber

Basic implementation of an integer number. This implementation is based on a java.math.BigInteger. It can hold all values from -2**32 to (2**32 - 1).

Instances must be obtained by using the createInstance() factory method.

Version:
$Revision: 1.8 $ $Date: 2002/10/01 18:46:31 $
Author:
Ernst de Haan (znerd@FreeBSD.org)
See Also:
BigInteger, Serialized Form

Field Summary
 
Fields inherited from class org.znerd.math.RealNumber
MAXIMUM_RADIX
 
Fields inherited from interface org.znerd.math.RoundingModes
ROUND_CEILING, ROUND_DOWN, ROUND_FLOOR, ROUND_UP
 
Constructor Summary
protected BigIntegerNumber(BigInteger n)
          Constructs a BigIntegerNumber from a BigInteger.
 
Method Summary
 IntegerNumber add(IntegerNumber n)
          Computes this + n, where n is an integer number.
static BigIntegerNumber createInstance(BigInteger n)
          Returns an instance of a BigIntegerNumber based on a java.math.BigInteger.
 double doubleValue()
          Returns the value of this number as a double.
 int hashCode()
           
 IntegerNumber integerDivide(IntegerNumber n)
          Computes the integer result of this/n, where n is an integer number.
 long longValue()
          Returns the value of this number as a long.
 IntegerNumber multiply(IntegerNumber n)
          Computes this * n, where n is an integer number.
protected  RationalNumber powImpl(int exponent)
           
 BigInteger toBigInteger()
          Converts the value of this number to a BigInteger.
 byte[] toByteArray()
          Returns the two's-complement representation of this integer number.
 
Methods inherited from class org.znerd.math.IntegerNumber
abs, absInteger, add, compareTo, compareToImpl, compareToImpl, dec, divide, fac, gcd, inc, invert, isRelativePrime, multiply, negate, negateInteger, powImpl, remainder, subtract, subtract, toBigDecimal, toBigDecimal, toBigDecimal, trunc
 
Methods inherited from class org.znerd.math.RationalNumber
add, compareTo, compareToImpl, compareToImpl2, divide, getDenominator, getNumerator, multiply, pow, powImpl, subtract
 
Methods inherited from class org.znerd.math.RealNumber
byteValue, compareTo, compareTo, equals, fitsByte, fitsDouble, fitsFloat, fitsInt, fitsLong, fitsShort, floatValue, getSign, intValue, pow, round, shortValue, toString
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

BigIntegerNumber

protected BigIntegerNumber(BigInteger n)
                    throws IllegalArgumentException
Constructs a BigIntegerNumber from a BigInteger.

Parameters:
n - the value for the new number, not null.
Throws:
IllegalArgumentException - if n == null.
Method Detail

createInstance

public static BigIntegerNumber createInstance(BigInteger n)
                                       throws IllegalArgumentException
Returns an instance of a BigIntegerNumber based on a java.math.BigInteger.

Parameters:
n - the BigInteger to construct a BigIntegerNumber from.
Returns:
the (possibly newly constructed) BigIntegerNumber instance.
Throws:
IllegalArgumentException - if n == null.

hashCode

public int hashCode()

add

public IntegerNumber add(IntegerNumber n)
                  throws IllegalArgumentException
Description copied from class: IntegerNumber
Computes this + n, where n is an integer number.

Specified by:
add in class IntegerNumber
Parameters:
n - the number to add to this, not null.
Returns:
the sum of this and n, never null.
Throws:
IllegalArgumentException - if the argument is null.

multiply

public IntegerNumber multiply(IntegerNumber n)
                       throws IllegalArgumentException
Description copied from class: IntegerNumber
Computes this * n, where n is an integer number.

Specified by:
multiply in class IntegerNumber
Parameters:
n - the number to multiply this by, not null.
Returns:
the product of this and n, not null.
Throws:
IllegalArgumentException - if n == null.

integerDivide

public IntegerNumber integerDivide(IntegerNumber n)
                            throws ArithmeticException,
                                   IllegalArgumentException
Description copied from class: IntegerNumber
Computes the integer result of this/n, where n is an integer number.

Specified by:
integerDivide in class IntegerNumber
Parameters:
n - the number to divide this by.
Returns:
the integer result of this divided by n.
Throws:
IllegalArgumentException - if the argument is null.
ArithmeticException - if the value of the argument number is zero.

powImpl

protected RationalNumber powImpl(int exponent)

longValue

public long longValue()
Description copied from class: RealNumber
Returns the value of this number as a long. This may involve rounding.

Overrides:
longValue in class RealNumber
Returns:
the numeric value represented by this object after conversion to type long.

doubleValue

public double doubleValue()
Description copied from class: RealNumber
Returns the value of this number as a double. This may involve rounding.

Overrides:
doubleValue in class RationalNumber

toByteArray

public byte[] toByteArray()
Description copied from class: IntegerNumber
Returns the two's-complement representation of this integer number. The array is big-endian (i.e., the most significant byte is in the [0] position). The array contains the minimum number of bytes required to represent the number.

Specified by:
toByteArray in class IntegerNumber
Returns:
a byte array containing the bits of this integer number.

toBigInteger

public BigInteger toBigInteger()
Description copied from class: IntegerNumber
Converts the value of this number to a BigInteger.

Overrides:
toBigInteger in class IntegerNumber
Returns:
a BigInteger with the value of this.


See http://jump-math.sourceforge.net/.