Class RoundingMode
java.lang.Object
org.znerd.math.RoundingMode
Rounding mode. This is an abstract base class for actual rounding mode
implementations.
Concrete subclasses must implement
roundImpl(RealNumber,int,int,int).- Version:
- $Revision: 1.11 $ $Date: 2002/08/16 21:54:40 $
- Author:
- Ernst de Haan (znerd@FreeBSD.org)
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedRoundingMode(String name, boolean consistent) Constructs a newRoundingModewith the specified name. -
Method Summary
Modifier and TypeMethodDescriptionfinal StringgetName()Returns a short, human-presentable, description of this rounding mode.final booleanIndicates if this rounding mode is consistent.final booleanround(RealNumber number, int radix, int digit) Rounds the specified digit for a number in the specified base.protected abstract booleanroundImpl(RealNumber number, int sign, int radix, int digit) Actually rounds the specified digit for a number in the specified base.final StringtoString()Returns a textual presentation of this object.
-
Constructor Details
-
RoundingMode
Constructs a newRoundingModewith the specified name. The name will be returned bygetName().- Parameters:
name- the name for the rounding mode, notnull.consistent-trueif this rounding mode always rounds in the same direction when passed the same arguments.- Throws:
IllegalArgumentException- ifname == null.
-
-
Method Details
-
round
Rounds the specified digit for a number in the specified base. If the number to be rounded is zero, thenfalseis returned.- Parameters:
number- the number that is being rounded, notnull.radix- the radix (or base) for the digit, at least 2, at mostRealNumber.MAXIMUM_RADIX.digit- the digit of which should be determined whether it should be rounded up or down, it should be at least 0, and less than the radix.- Returns:
trueif the concerned number should be rounded up, away from zero;falseif it should be rounded down, towards zero.- Throws:
IllegalArgumentException- ifnumber == null || radix < 2 || radix >.RealNumber.MAXIMUM_RADIX|| digit < 0 || digit >= radix
-
roundImpl
Actually rounds the specified digit for a number in the specified base. This method is called fromround(RealNumber,int,int).- Parameters:
number- the number that is being rounded, guaranteed not to benulland not to be zero.sign- the sign, either -1 or 1.radix- the radix (or base) for the digit, guaranteed to be at least 2 and at mostRealNumber.MAXIMUM_RADIX.digit- the digit of which should be determined whether it should be rounded up or down, guaranteed to be at least 0, and less than the radix.- Returns:
trueif the concerned number should be rounded up, away from zero;falseif it should be rounded down, towards zero.
-
getName
Returns a short, human-presentable, description of this rounding mode.- Returns:
- the name, never
null.
-
toString
-
isConsistent
public final boolean isConsistent()Indicates if this rounding mode is consistent.- Returns:
trueif this rounding mode always rounds the same way when passed the same arguments.
-