org.znerd.math
Class DigitSet
java.lang.Object
|
+--java.lang.Number
|
+--org.znerd.math.RealNumber
|
+--org.znerd.math.RationalNumber
|
+--org.znerd.math.DigitSet
- Direct Known Subclasses:
- BasicDigitSet
- public abstract class DigitSet
- extends RationalNumber
A set of digits, having a radix and an exponent. Objects of this type are
used to implement rounding.
The value of a DigitSet number is the sum of:
digits[0] * radixexponent
digits[1] * radixexponent - 1
digits[2] * radixexponent - 2
...
digits[precision - 1] * radixexponent - (precision - 1)
- Version:
- $Revision: 1.11 $ $Date: 2002/08/16 21:54:40 $
- Author:
- Ernst de Haan (znerd@FreeBSD.org)
- See Also:
- Serialized Form
|
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,
pow,
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,
round,
shortValue,
toBigInteger,
toString |
DigitSet
protected DigitSet(IntegerNumber[] parts,
String asString)
throws IllegalArgumentException
- Creates a new
DigitSet instance.
- Parameters:
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.- Throws:
- IllegalArgumentException - if
asString == null.
getRadix
public abstract int getRadix()
- Returns the radix or base. The radix is for example 10 for a decimal
number and 16 for a hexadecimal number. A binary number has the smallest
radix, 2.
- Returns:
- the radix, always > 1.
getExponent
public abstract int getExponent()
- Returns the exponent.
- Returns:
- the exponent.
getDigits
public abstract int[] getDigits()
- Returns a new array containing all the digits. Every digit in the
returned array is an
int value between 0 (inclusive) and
the radix (exclusive).
- Returns:
- a new array containing all the digits;
r != null &&
r[i] >= 0 &&
r[i] < getRadix(),
where r is the return value and i is an
int between 0 and r.length.
getPrecision
public abstract int getPrecision()
- Returns the precision, the total number of digits.
- Returns:
- the precision, always >= 0.
toPrecision
public final DigitSet toPrecision(int precision)
throws IllegalArgumentException
- Returns a digit set with the specified precision. If the specified
precision is larger than or equal to the current precision, then this
digit set (
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.
- Parameters:
precision - the precision, >= 1.- Returns:
- a
DigitSet that is equal to this number, truncated to
the specified precision, never null. - Throws:
- IllegalArgumentException - if
precision < 1.
toPrecisionImpl
protected abstract DigitSet toPrecisionImpl(int precision)
- Returns a digit set with the specified precision, actual implementation.
This method is called from
toPrecision(int).
- Parameters:
precision - the precision, guaranteed to be >= 1 and <
getPrecision().- Returns:
- a
DigitSet that is equal to this number, truncated to
the specified precision.
See http://jump-math.sourceforge.net/.