org.znerd.math
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_RADIX
ROUND_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, trunc
add, compareTo, compareToImpl, compareToImpl2, divide, getDenominator, getNumerator, multiply, pow, powImpl, subtract
byteValue, compareTo, compareTo, equals, fitsByte, fitsDouble, fitsFloat, fitsInt, fitsLong, fitsShort, floatValue, getSign, pow, shortValue, toString
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.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
IntegerNumber
IntegerNumber.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 IntegerNumber
n
- 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
RealNumber
UnsupportedOperationException
is thrown. The implementation of
this method in class RealNumber
throws such an exception.round
in class RealNumber
radix
- 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()
IntegerNumber
IntegerNumber
.
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 IntegerNumber
null
.public IntegerNumber add(IntegerNumber n) throws java.lang.IllegalArgumentException
IntegerNumber
add
in class IntegerNumber
n
- 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
IntegerNumber
multiply
in class IntegerNumber
n
- the number to multiply this by, not null
.null
.java.lang.IllegalArgumentException
- if n == null
.public IntegerNumber dec()
IntegerNumber
dec
in class IntegerNumber
public IntegerNumber inc()
IntegerNumber
inc
in class IntegerNumber
public IntegerNumber integerDivide(IntegerNumber n) throws java.lang.ArithmeticException, java.lang.IllegalArgumentException
IntegerNumber
integerDivide
in class IntegerNumber
n
- 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
IntegerNumber
remainder
in class IntegerNumber
n
- 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()
RealNumber
long
. This may
involve rounding.longValue
in class RealNumber
long
.public int intValue()
RealNumber
int
. This may
involve rounding.intValue
in class RealNumber
int
.public double doubleValue()
RealNumber
double
. This may
involve rounding.doubleValue
in class RationalNumber
double
.public byte[] toByteArray()
IntegerNumber
toByteArray
in class IntegerNumber
public java.math.BigInteger toBigInteger()
IntegerNumber
BigInteger
.toBigInteger
in class IntegerNumber
BigInteger
with the value of this.