ch.javasoft.util.numeric
Class Zero

java.lang.Object
  extended by ch.javasoft.util.numeric.Zero

public class Zero
extends Object

Zero is a helper class treating values close to zero as zero. A tolerance or precision can be defined when constructing an instance of Zero.


Field Summary
static int DEFAULT_PRECISION
          default precision 10, meaning 10 decimal places
static double DEFAULT_TOLERANCE
          default precision 10-10, meaning 10 decimal places
static double EPS_TOLERANCE
          normal machine precision for doubles, that is 2-52
 int mPrecision
           
 double mZeroNeg
           
 double mZeroPos
           
 
Constructor Summary
Zero()
          Constructor using DEFAULT_PRECISION
Zero(double tolerance)
          Constructor using the specified tolerance
Zero(int precision)
          Constructor using the specified precision
 
Method Summary
 boolean isNegative(double value)
           
 boolean isNegPos(double valueA, double valueB)
           
 boolean isNonZero(double value)
           
 boolean isPositive(double value)
           
 boolean isZero(double value)
           
 boolean isZeroNeg(double value)
           
 boolean isZeroPos(double value)
           
 double roundZero(double value)
          If the given value is within the zero tolerance, zero is returned, and the given value otherwise.
 int sgn(double value)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_PRECISION

public static final int DEFAULT_PRECISION
default precision 10, meaning 10 decimal places

See Also:
Constant Field Values

DEFAULT_TOLERANCE

public static final double DEFAULT_TOLERANCE
default precision 10-10, meaning 10 decimal places

See Also:
Constant Field Values

EPS_TOLERANCE

public static final double EPS_TOLERANCE
normal machine precision for doubles, that is 2-52


mPrecision

public final int mPrecision

mZeroPos

public final double mZeroPos

mZeroNeg

public final double mZeroNeg
Constructor Detail

Zero

public Zero()
Constructor using DEFAULT_PRECISION


Zero

public Zero(double tolerance)
Constructor using the specified tolerance

Parameters:
tolerance - a number close to zero, absolute values larger than the absolute value of tolerance are treated non-zero, other values as zero

Zero

public Zero(int precision)
Constructor using the specified precision

Parameters:
precision - the precision in decimal places, absolute values larger than 10-abs(precision) are treated non-zero, other values as zero
Method Detail

sgn

public int sgn(double value)

isZero

public boolean isZero(double value)

isNonZero

public boolean isNonZero(double value)

isZeroNeg

public boolean isZeroNeg(double value)

isZeroPos

public boolean isZeroPos(double value)

isNegative

public boolean isNegative(double value)

isPositive

public boolean isPositive(double value)

isNegPos

public boolean isNegPos(double valueA,
                        double valueB)

roundZero

public double roundZero(double value)
If the given value is within the zero tolerance, zero is returned, and the given value otherwise.