org.znerd.math
Class RoundingMode

java.lang.Object
  |
  +--org.znerd.math.RoundingMode

public abstract class RoundingMode
extends Object

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
protected RoundingMode(String name, boolean consistent)
          Constructs a new RoundingMode with the specified name.
 
Method Summary
 String getName()
          Returns a short, human-presentable, description of this rounding mode.
 boolean isConsistent()
          Indicates if this rounding mode is consistent.
 boolean round(RealNumber number, int radix, int digit)
          Rounds the specified digit for a number in the specified base.
protected abstract  boolean roundImpl(RealNumber number, int sign, int radix, int digit)
          Actually rounds the specified digit for a number in the specified base.
 String toString()
          Returns a textual presentation of this object.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

RoundingMode

protected RoundingMode(String name,
                       boolean consistent)
                throws IllegalArgumentException
Constructs a new RoundingMode with the specified name. The name will be returned by getName().
Parameters:
name - the name for the rounding mode, not null.
consistent - true if this rounding mode always rounds in the same direction when passed the same arguments.
Throws:
IllegalArgumentException - if name == null.
Method Detail

round

public final boolean round(RealNumber number,
                           int radix,
                           int digit)
                    throws IllegalArgumentException
Rounds the specified digit for a number in the specified base. If the number to be rounded is zero, then false is returned.
Parameters:
number - the number that is being rounded, not null.
radix - the radix (or base) for the digit, at least 2, at most RealNumber.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:
true if the concerned number should be rounded up, away from zero; false if it should be rounded down, towards zero.
Throws:
IllegalArgumentException - if number == null || radix < 2 || radix > RealNumber.MAXIMUM_RADIX || digit < 0 || digit >= radix.

roundImpl

protected abstract boolean roundImpl(RealNumber number,
                                     int sign,
                                     int radix,
                                     int digit)
Actually rounds the specified digit for a number in the specified base. This method is called from round(RealNumber,int,int).
Parameters:
number - the number that is being rounded, guaranteed not to be null and 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 most RealNumber.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:
true if the concerned number should be rounded up, away from zero; false if it should be rounded down, towards zero.

getName

public final String getName()
Returns a short, human-presentable, description of this rounding mode.
Returns:
the name, never null.

toString

public final String toString()
Returns a textual presentation of this object.
Overrides:
toString in class Object
Returns:
a textual presentation of this object, never null.

isConsistent

public final boolean isConsistent()
Indicates if this rounding mode is consistent.
Returns:
true if this rounding mode always rounds the same way when passed the same arguments.


See http://jump-math.sourceforge.net/.