|
||||||||||
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.DigitSet
A set of digits, having a radix and an exponent. Objects of this type are used to implement rounding.
The value of aDigitSet
number is the sum of:
digits[0] * radixexponent
digits[1] * radixexponent - 1
digits[2] * radixexponent - 2
...
digits[precision - 1] * radixexponent - (precision - 1)
Field Summary |
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 |
Constructor Summary | |
protected |
DigitSet(IntegerNumber[] parts,
String asString)
Creates a new DigitSet instance. |
Method Summary | |
abstract int[] |
getDigits()
Returns a new array containing all the digits. |
abstract int |
getExponent()
Returns the exponent. |
abstract int |
getPrecision()
Returns the precision, the total number of digits. |
abstract int |
getRadix()
Returns the radix or base. |
DigitSet |
toPrecision(int precision)
Returns a digit set with the specified precision. |
protected abstract DigitSet |
toPrecisionImpl(int precision)
Returns a digit set with the specified precision, actual implementation. |
Methods inherited from class org.znerd.math.RationalNumber |
add, add, compareTo, compareToImpl, compareToImpl, compareToImpl2, divide, divide, doubleValue, getDenominator, getNumerator, invert, multiply, multiply, negate, pow, powImpl, powImpl, subtract, subtract, toBigDecimal, toBigDecimal, trunc |
Methods inherited from class org.znerd.math.RealNumber |
abs, byteValue, compareTo, compareTo, equals, fitsByte, fitsDouble, fitsFloat, fitsInt, fitsLong, fitsShort, floatValue, getSign, intValue, longValue, pow, round, shortValue, toBigInteger, toString |
Methods inherited from class java.lang.Object |
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
protected DigitSet(IntegerNumber[] parts, String asString) throws IllegalArgumentException
DigitSet
instance.
parts
- an array containing the numerator and denonimator, not
null
, having at least 2 elements and not having a
null
at index 0 or 1.asString
- textual presentation of this number, not null
.
IllegalArgumentException
- if asString == null
.Method Detail |
public abstract int getRadix()
public abstract int getExponent()
public abstract int[] getDigits()
int
value between 0 (inclusive) and
the radix (exclusive).
r != null &&
r[i] >= 0 &&
r[i] < getRadix()
,
where r is the return value and i is an
int
between 0 and r.length
.public abstract int getPrecision()
public final DigitSet toPrecision(int precision) throws IllegalArgumentException
this
) will be returned.
No rounding will be performed, only truncation. If the specified
precision is smaller than the precision of this DigitSet
,
then some of the digits will just be removed.
This method calls toPrecisionImpl(int)
after checking the
preconditions. If that method returns an invalid value, then an
InternalError
is thrown.
precision
- the precision, >= 1.
DigitSet
that is equal to this number, truncated to
the specified precision, never null
.
IllegalArgumentException
- if precision < 1
.protected abstract DigitSet toPrecisionImpl(int precision)
toPrecision(int)
.
precision
- the precision, guaranteed to be >= 1 and <
getPrecision()
.
DigitSet
that is equal to this number, truncated to
the specified precision.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |