org.znerd.math
Class SmallIntegerNumber

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

public final class SmallIntegerNumber
extends IntegerNumber

Implementation of an IntegerNumber based on a int value.

Instances must be obtained by using one of the createInstance() factory methods. Using this approach, instances can be transparently cached by this class.

Version:
$Revision: 1.14 $ $Date: 2002/06/25 20:12:33 $
Author:
Ernst de Haan (znerd@FreeBSD.org)
See Also:
Serialized Form

Field Summary
 int _value
          The int this IntegerNumber implementation is based on.
static SmallIntegerNumber MAXIMUM_VALUE
          The maximum IntegerNumber that can be represented by this class.
static SmallIntegerNumber MINIMUM_VALUE
          The minimum IntegerNumber that can be represented by this class.
static SmallIntegerNumber MINUS_ONE
          Cached instance that represents the number minus one, -1.
static SmallIntegerNumber MINUS_TWO
          Cached instance that represents the number minus two, -2.
static SmallIntegerNumber ONE
          Cached instance that represents the number one, 1.
static SmallIntegerNumber TWO
          Cached instance that represents the number two, 2.
static SmallIntegerNumber ZERO
          Cached instance that represents the number zero, 0.
 
Fields inherited from class org.znerd.math.RealNumber
MAXIMUM_RADIX
 
Method Summary
 IntegerNumber add(IntegerNumber n)
          Computes this + n, where n is an integer number.
protected  int compareToImpl(IntegerNumber n)
           
static SmallIntegerNumber createInstance(int n)
          Returns an instance of a SmallIntegerNumber based on a int value.
 IntegerNumber dec()
          Computes this-1.
 double doubleValue()
          Returns the value of this number as a double.
 IntegerNumber inc()
          Computes this+1.
 IntegerNumber integerDivide(IntegerNumber n)
          Computes the integer result of this/n, where n is an integer number.
 int intValue()
          Returns the value of this number as an int.
 long longValue()
          Returns the value of this number as a long.
 IntegerNumber multiply(IntegerNumber n)
          Computes this * n, where n is an integer number.
 IntegerNumber negateInteger()
           
 IntegerNumber remainder(IntegerNumber n)
          Computes the remainder of 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, divide, fac, gcd, invert, isRelativePrime, multiply, negate, pow, 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, shortValue, toString
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

MINIMUM_VALUE

public static final SmallIntegerNumber MINIMUM_VALUE
The minimum IntegerNumber that can be represented by this class.

MAXIMUM_VALUE

public static final SmallIntegerNumber MAXIMUM_VALUE
The maximum IntegerNumber that can be represented by this class.

MINUS_TWO

public static final SmallIntegerNumber MINUS_TWO
Cached instance that represents the number minus two, -2.

MINUS_ONE

public static final SmallIntegerNumber MINUS_ONE
Cached instance that represents the number minus one, -1.

ZERO

public static final SmallIntegerNumber ZERO
Cached instance that represents the number zero, 0.

ONE

public static final SmallIntegerNumber ONE
Cached instance that represents the number one, 1.

TWO

public static final SmallIntegerNumber TWO
Cached instance that represents the number two, 2.

_value

public final int _value
The int this IntegerNumber implementation is based on.
Method Detail

createInstance

public static SmallIntegerNumber createInstance(int n)
Returns an instance of a SmallIntegerNumber based on a int value.
Parameters:
n - the int to construct a SmallIntegerNumber from.
Returns:
the (possibly newly constructed) SmallIntegerNumber.

compareToImpl

protected int compareToImpl(IntegerNumber n)
                     throws CanNotCompareException
Overrides:
compareToImpl in class IntegerNumber

round

public DigitSet round(int radix,
                      int precision,
                      RoundingMode roundingMode)
               throws IllegalArgumentException
Rounds to the specified radix, using the specified precision and rounding mode.
Overrides:
round in 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.

negateInteger

public IntegerNumber negateInteger()
Overrides:
negateInteger in class IntegerNumber

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.

dec

public IntegerNumber dec()
Description copied from class: IntegerNumber
Computes this-1.
Overrides:
dec in class IntegerNumber
Tags copied from class: IntegerNumber
Returns:
this decreased by 1.

inc

public IntegerNumber inc()
Description copied from class: IntegerNumber
Computes this+1.
Overrides:
inc in class IntegerNumber
Tags copied from class: IntegerNumber
Returns:
this increased by 1.

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.

remainder

public IntegerNumber remainder(IntegerNumber n)
                        throws ArithmeticException,
                               IllegalArgumentException
Description copied from class: IntegerNumber
Computes the remainder of this/n, where n is an integer number.
Overrides:
remainder in class IntegerNumber
Tags copied from class: IntegerNumber
Parameters:
n - the number to divide this by.
Returns:
the remainder.
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.

intValue

public int intValue()
Description copied from class: RealNumber
Returns the value of this number as an int. This may involve rounding.
Overrides:
intValue in class RealNumber
Tags copied from class: RealNumber
Returns:
the numeric value represented by this object after conversion to type int.

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/.