public final class SmallIntegerNumber extends IntegerNumber
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.| Modifier and Type | Field and Description |
|---|---|
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.
|
MAXIMUM_RADIXROUND_CEILING, ROUND_DOWN, ROUND_FLOOR, ROUND_UP| Modifier and Type | Method and Description |
|---|---|
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.
|
java.math.BigInteger |
toBigInteger()
Converts the value of this number to a
BigInteger. |
byte[] |
toByteArray()
Returns the two's-complement representation of this integer number.
|
abs, absInteger, add, compareTo, compareToImpl, divide, fac, gcd, invert, isRelativePrime, multiply, negate, powImpl, subtract, subtract, toBigDecimal, toBigDecimal, toBigDecimal, truncadd, compareTo, compareToImpl, compareToImpl2, divide, getDenominator, getNumerator, multiply, pow, powImpl, subtractbyteValue, compareTo, compareTo, equals, fitsByte, fitsDouble, fitsFloat, fitsInt, fitsLong, fitsShort, floatValue, getSign, pow, shortValue, toStringpublic 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.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 java.lang.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.java.lang.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 java.lang.IllegalArgumentException
IntegerNumberadd in class IntegerNumbern - the number to add to this, not null.null.java.lang.IllegalArgumentException - if the argument is
null.public IntegerNumber multiply(IntegerNumber n) throws java.lang.IllegalArgumentException
IntegerNumbermultiply in class IntegerNumbern - the number to multiply this by, not null.null.java.lang.IllegalArgumentException - if n == null.public IntegerNumber dec()
IntegerNumberdec in class IntegerNumberpublic IntegerNumber inc()
IntegerNumberinc in class IntegerNumberpublic IntegerNumber integerDivide(IntegerNumber n) throws java.lang.ArithmeticException, java.lang.IllegalArgumentException
IntegerNumberintegerDivide in class IntegerNumbern - the number to divide this by.java.lang.ArithmeticException - if the value of the argument number is
zero.java.lang.IllegalArgumentException - if the argument is
null.public IntegerNumber remainder(IntegerNumber n) throws java.lang.ArithmeticException, java.lang.IllegalArgumentException
IntegerNumberremainder in class IntegerNumbern - the number to divide this by.java.lang.ArithmeticException - if the value of the argument number is
zero.java.lang.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 RationalNumberdouble.public byte[] toByteArray()
IntegerNumbertoByteArray in class IntegerNumberpublic java.math.BigInteger toBigInteger()
IntegerNumberBigInteger.toBigInteger in class IntegerNumberBigInteger with the value of this.