jaitools.numeric
Class DoubleComparison

java.lang.Object
  extended by jaitools.numeric.DoubleComparison

public class DoubleComparison
extends Object

Provides static method to compare double values with either a default or specified tolerance.

Since:
1.0
Version:
$Id: DoubleComparison.java 1504 2011-03-05 10:56:10Z michael.bedward $
Author:
Michael Bedward

Field Summary
static double TOL
          Default tolerance for comparisons: 1.0e-8
 
Constructor Summary
DoubleComparison()
           
 
Method Summary
static int dcomp(double x1, double x2)
          Compares two values using the default tolerance.
static int dcomp(double x1, double x2, double tol)
          Compares two values using the user-specified tolerance
static boolean dequal(double x1, double x2)
          Tests if two double values are equal within the default tolerance.
static boolean dequal(double x1, double x2, double tol)
          Tests if two double values are equal within the specified tolerance.
static boolean dzero(double x)
          Tests if the given value is 0 within the default tolerance.
static boolean dzero(double x, double tol)
          Tests if the given value is 0 within the user-specified tolerance.
static int toInt(double x)
          Converts a double value to integer taking into account the default tolerance when checking if it is zero, ie.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

TOL

public static final double TOL
Default tolerance for comparisons: 1.0e-8

See Also:
Constant Field Values
Constructor Detail

DoubleComparison

public DoubleComparison()
Method Detail

dzero

public static boolean dzero(double x)
Tests if the given value is 0 within the default tolerance.

Parameters:
x - the value
Returns:
true if zero; false otherwise

dzero

public static boolean dzero(double x,
                            double tol)
Tests if the given value is 0 within the user-specified tolerance.

Parameters:
x - the value
tol - the user-specified tolerance (assumed to be positive)
Returns:
true if zero; false otherwise

dcomp

public static int dcomp(double x1,
                        double x2)
Compares two values using the default tolerance.

Parameters:
x1 - first value
x2 - second value
Returns:
a value less than 0 if x1 is less than x2; 0 if x1 is equal to x2; a value greater than 0 if x1 is greater than x2

dcomp

public static int dcomp(double x1,
                        double x2,
                        double tol)
Compares two values using the user-specified tolerance

Parameters:
x1 - first value
x2 - second value
tol - the tolerance
Returns:
a value less than 0 if x1 is less than x2; 0 if x1 is equal to x2; a value greater than 0 if x1 is greater than x2

dequal

public static boolean dequal(double x1,
                             double x2)
Tests if two double values are equal within the default tolerance. This is a short-cut for dzero(x1 - x2).

Parameters:
x1 - first value
x2 - second value
Returns:
true if equal; false otherwise

dequal

public static boolean dequal(double x1,
                             double x2,
                             double tol)
Tests if two double values are equal within the specified tolerance. This is a short-cut for dzero(x1 - x2, tol).

Parameters:
x1 - first value
x2 - second value
tol - the tolerance
Returns:
true if equal; false otherwise

toInt

public static int toInt(double x)
Converts a double value to integer taking into account the default tolerance when checking if it is zero, ie. values within TOL either side of 0 will produce a 0 return value

Parameters:
x - the value to convert
Returns:
the equivalent integer value


Copyright © 2009-2011. All Rights Reserved.