|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectjava.lang.Number
org.znerd.math.RealNumber
org.znerd.math.RationalNumber
org.znerd.math.IntegerNumber
org.znerd.math.SmallIntegerNumber
Implementation of an IntegerNumber based on a
int value.
createInstance() factory methods. Using this approach,
instances can be transparently cached by this class.
| 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 |
| Fields inherited from interface org.znerd.math.RoundingModes |
ROUND_CEILING, ROUND_DOWN, ROUND_FLOOR, ROUND_UP |
| Method Summary | |
IntegerNumber |
add(IntegerNumber n)
Computes this + n, where n is an integer number. |
protected int |
compareToImpl(IntegerNumber n)
Compares this number with the specified integer number, second level. |
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()
Computes -this and returns an IntegerNumber. |
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, powImpl, 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, pow, shortValue, toString |
| Methods inherited from class java.lang.Object |
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Field Detail |
public static final SmallIntegerNumber MINIMUM_VALUE
IntegerNumber that can be represented by this
class.
public static final SmallIntegerNumber MAXIMUM_VALUE
IntegerNumber that can be represented by this
class.
public static final SmallIntegerNumber MINUS_TWO
public static final SmallIntegerNumber MINUS_ONE
public static final SmallIntegerNumber ZERO
public static final SmallIntegerNumber ONE
public static final SmallIntegerNumber TWO
public final int _value
int this IntegerNumber implementation
is based on.
| Method Detail |
public static SmallIntegerNumber createInstance(int n)
SmallIntegerNumber based on a
int value.
n - the int to construct a SmallIntegerNumber from.
SmallIntegerNumber.
protected int compareToImpl(IntegerNumber n)
throws CanNotCompareException
IntegerNumberIntegerNumber.compareTo(IntegerNumber). The
implementation of this method in class IntegerNumber just throws
a CanNotCompareException to indicate it does not provide an
optimized algorithm for comparing this integer number with the argument
integer number. Subclasses are encouraged to override this method.
compareToImpl in class IntegerNumbern - the number to compare to, guaranteed to be not null.
CanNotCompareException - if the comparison failed.
public DigitSet round(int radix,
int precision,
RoundingMode roundingMode)
throws IllegalArgumentException
RealNumberUnsupportedOperationException is thrown. The implementation of
this method in class RealNumber throws such an exception.
round in class RealNumberradix - the radix, always >= 2 and <= RealNumber.MAXIMUM_RADIX.precision - the precision, always >= 1.roundingMode - the rounding mode, never null.
null.
IllegalArgumentException - if radix < 2
|| radix > RealNumber.MAXIMUM_RADIX
|| precision < 1
|| roundingMode == null.public IntegerNumber negateInteger()
IntegerNumberIntegerNumber.
The only difference between this method and IntegerNumber.negate() is
that this method is explicitly defined to return an
IntegerNumber. In fact IntegerNumber.negate() calls this method.
negateInteger in class IntegerNumbernull.
public IntegerNumber add(IntegerNumber n)
throws IllegalArgumentException
IntegerNumber
add in class IntegerNumbern - the number to add to this, not null.
null.
IllegalArgumentException - if the argument is
null.
public IntegerNumber multiply(IntegerNumber n)
throws IllegalArgumentException
IntegerNumber
multiply in class IntegerNumbern - the number to multiply this by, not null.
null.
IllegalArgumentException - if n == null.public IntegerNumber dec()
IntegerNumber
dec in class IntegerNumberpublic IntegerNumber inc()
IntegerNumber
inc in class IntegerNumber
public IntegerNumber integerDivide(IntegerNumber n)
throws ArithmeticException,
IllegalArgumentException
IntegerNumber
integerDivide in class IntegerNumbern - the number to divide this by.
ArithmeticException - if the value of the argument number is
zero.
IllegalArgumentException - if the argument is
null.
public IntegerNumber remainder(IntegerNumber n)
throws ArithmeticException,
IllegalArgumentException
IntegerNumber
remainder in class IntegerNumbern - the number to divide this by.
ArithmeticException - if the value of the argument number is
zero.
IllegalArgumentException - if the argument is
null.public long longValue()
RealNumberlong. This may
involve rounding.
longValue in class RealNumberlong.public int intValue()
RealNumberint. This may
involve rounding.
intValue in class RealNumberint.public double doubleValue()
RealNumberdouble. This may
involve rounding.
doubleValue in class RationalNumberpublic byte[] toByteArray()
IntegerNumber
toByteArray in class IntegerNumberpublic BigInteger toBigInteger()
IntegerNumberBigInteger.
toBigInteger in class IntegerNumberBigInteger with the value of this.
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||