org.znerd.math
Class BigIntegerNumber

java.lang.Object
  |
  +--java.lang.Number
        |
        +--org.znerd.math.RealNumber
              |
              +--org.znerd.math.RationalNumber
                    |
                    +--org.znerd.math.IntegerNumber
                          |
                          +--org.znerd.math.BigIntegerNumber

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.2 $ $Date: 2002/06/24 18:13:52 $
Author:
Ernst de Haan (znerd@FreeBSD.org)
See Also:
BigInteger, Serialized Form

Fields inherited from class org.znerd.math.RealNumber
MAXIMUM_RADIX
 
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.
 DigitSet round(int radix, int precision, RoundingMode roundingMode)
          Rounds to the specified radix, using the specified precision and rounding mode.
 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, pow, remainder, subtract, subtract, toBigDecimal, toBigDecimal, toBigDecimal, trunc
 
Methods inherited from class org.znerd.math.RationalNumber
add, compareTo, compareToImpl, compareToImpl2, divide, getDenominator, getNumerator, multiply, pow, subtract
 
Methods inherited from class org.znerd.math.RealNumber
byteValue, compareTo, compareTo, equals, fitsByte, fitsDouble, fitsFloat, fitsInt, fitsLong, fitsShort, floatValue, getSign, intValue, 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.
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()
Overrides:
hashCode in class Object

round

public DigitSet round(int radix,
                      int precision,
                      RoundingMode roundingMode)
               throws IllegalArgumentException
Description copied from class: IntegerNumber
Rounds to the specified radix, using the specified precision and rounding mode.
Overrides:
round in class IntegerNumber
Tags copied from class: IntegerNumber
Parameters:
radix - the radix, always >= 2 and <= RealNumber.MAXIMUM_RADIX.
precision - the precision, always >= 1.
roundingMode - the rounding mode, never null.
Throws:
IllegalArgumentException - if radix < 2 || radix > RealNumber.MAXIMUM_RADIX || precision < 1 || roundingMode == null.

add

public IntegerNumber add(IntegerNumber n)
                  throws IllegalArgumentException
Description copied from class: IntegerNumber
Computes this + n, where n is an integer number.
Overrides:
add in class IntegerNumber
Tags copied from 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.
Overrides:
multiply in class IntegerNumber
Tags copied from 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.
Overrides:
integerDivide in class IntegerNumber
Tags copied from class: IntegerNumber
Parameters:
n - the number to divide this by.
Returns:
the integer result of this divided by n.
Throws:
ArithmeticException - if the value of the argument number is zero.
IllegalArgumentException - if the argument is null.

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
Tags copied from 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
Tags copied from class: RealNumber
Returns:
the numeric value represented by this object after conversion to type double.

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.
Overrides:
toByteArray in class IntegerNumber
Tags copied from 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
Tags copied from class: IntegerNumber
Returns:
a BigInteger with the value of this.


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