|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.jaitools.numeric.CompareOp
public class CompareOp
Provides static methods to compare floating point values, taking into account
an absolute or proportional tolerance. There are methods for both float and
double values.
The acompare and aequal methods use absolute tolerance while
the pcompare and pequal methods use proportional tolerance.
For the proportional tolerance methods, a corresponding absolute tolerance is calculated as:
atol = |ptol| * MAX(|x1|,|x2|)
Note: this class does not give any special consideration to the Float
and Double constants NEGATIVE_INFINITY, POSITIVE_INFINITY
and NaN over that provided by Java itself.
| Field Summary | |
|---|---|
static double |
DTOL
Default tolerance for double comparisons: 1.0e-8 |
static float |
FTOL
Default tolerance for float comparisons: 1.0e-4 |
| Constructor Summary | |
|---|---|
CompareOp()
|
|
| Method Summary | |
|---|---|
static int |
acompare(double x1,
double x2)
Compares two double values using the default tolerance. |
static int |
acompare(double x1,
double x2,
double tol)
Compares two double values using the specified tolerance. |
static int |
acompare(float x1,
float x2)
Compares two float values using the default tolerance. |
static int |
acompare(float x1,
float x2,
float tol)
Compares two float values using the specified tolerance. |
static boolean |
aequal(double x1,
double x2)
Tests if two double values are equal within the default tolerance. |
static boolean |
aequal(double x1,
double x2,
double tol)
Tests if two double values are equal within the specified tolerance. |
static boolean |
aequal(float x1,
float x2)
Tests if two float values are equal within the default tolerance. |
static boolean |
aequal(float x1,
float x2,
float tol)
Tests if two float values are equal within the specified tolerance. |
static boolean |
isZero(double x)
Tests if the given double value is within the default tolerance
of zero. |
static boolean |
isZero(double x,
double tol)
Tests if the given double value is within the specified tolerance
of zero. |
static boolean |
isZero(float x)
Tests if the given float value is within the default tolerance
of zero. |
static boolean |
isZero(float x,
float tol)
Tests if the given float value is within the specified tolerance
of zero. |
static int |
pcompare(double x1,
double x2,
double propTol)
Compares two double values using the specified proportional
tolerance. |
static int |
pcompare(float x1,
float x2,
float propTol)
Compares two float values using the specified proportional
tolerance. |
static boolean |
pequal(double x1,
double x2,
double propTol)
Tests if two double values are equal within the specified
proportional tolerance. |
static boolean |
pequal(float x1,
float x2,
float propTol)
Tests if two float values are equal within the specified
proportional tolerance. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
public static final double DTOL
public static final float FTOL
| Constructor Detail |
|---|
public CompareOp()
| Method Detail |
|---|
public static boolean isZero(double x)
double value is within the default tolerance
of zero.
x - the value
true if zero; false otherwisepublic static boolean isZero(float x)
float value is within the default tolerance
of zero.
x - the value
true if zero; false otherwise
public static boolean isZero(double x,
double tol)
double value is within the specified tolerance
of zero. Note that performance reasons, tol is assumed
to be positive, ie. this is not checked.
x - the valuetol - the tolerance
true if zero; false otherwise
public static boolean isZero(float x,
float tol)
float value is within the specified tolerance
of zero. Note that performance reasons, tol is assumed
to be positive, ie. this is not checked.
x - the valuetol - the tolerance
true if zero; false otherwise
public static int acompare(double x1,
double x2)
double values using the default tolerance.
x1 - first valuex2 - second value
public static int acompare(float x1,
float x2)
float values using the default tolerance.
x1 - first valuex2 - second value
public static int acompare(double x1,
double x2,
double tol)
double values using the specified tolerance.
Note that performance reasons, tol is assumed
to be positive, ie. this is not checked.
x1 - first valuex2 - second valuetol - comparison tolerance
public static int acompare(float x1,
float x2,
float tol)
float values using the specified tolerance.
Note that performance reasons, tol is assumed
to be positive, ie. this is not checked.
x1 - first valuex2 - second valuetol - comparison tolerance
public static int pcompare(double x1,
double x2,
double propTol)
double values using the specified proportional
tolerance. This is equivalent to:
double absoluteTol = Math.abs(propTol) * Math.max(Math.abs(x1), Math.abs(x2));
int comp = acompare(x1, x2, absTol);
x1 - first valuex2 - second valuepropTol - proportional tolerance between 0 and 1
public static int pcompare(float x1,
float x2,
float propTol)
float values using the specified proportional
tolerance. This is equivalent to:
float absoluteTol = Math.abs(propTol) * Math.max(Math.abs(x1), Math.abs(x2));
int comp = acompare(x1, x2, absTol);
x1 - first valuex2 - second valuepropTol - proportional tolerance between 0 and 1
public static boolean aequal(double x1,
double x2)
double values are equal within the default tolerance.
This is equivalent to dzero(x1 - x2).
x1 - first valuex2 - second value
true if equal; false otherwise
public static boolean aequal(float x1,
float x2)
float values are equal within the default tolerance.
This is equivalent to dzero(x1 - x2).
x1 - first valuex2 - second value
true if equal; false otherwise
public static boolean aequal(double x1,
double x2,
double tol)
double values are equal within the specified tolerance.
This is equivalent to dzero(x1 - x2, tol).
Note that performance reasons, tol is assumed
to be positive, ie. this is not checked.
x1 - first valuex2 - second valuetol - comparison tolerance
true if equal; false otherwise
public static boolean aequal(float x1,
float x2,
float tol)
float values are equal within the specified tolerance.
This is equivalent to dzero(x1 - x2, tol).
Note that performance reasons, tol is assumed
to be positive, ie. this is not checked.
x1 - first valuex2 - second valuetol - comparison tolerance
true if equal; false otherwise
public static boolean pequal(double x1,
double x2,
double propTol)
double values are equal within the specified
proportional tolerance. This is equivalent to:
double absoluteTol = Math.abs(propTol) * Math.max(Math.abs(x1), Math.abs(x2));
boolean b = aequal(x1, x2, absTol);
x1 - first valuex2 - second valuepropTol - proportional tolerance between 0 and 1
true if equal; false otherwise
public static boolean pequal(float x1,
float x2,
float propTol)
float values are equal within the specified
proportional tolerance. This is equivalent to:
float absoluteTol = Math.abs(propTol) * Math.max(Math.abs(x1), Math.abs(x2));
boolean b = aequal(x1, x2, absTol);
x1 - first valuex2 - second valuepropTol - proportional tolerance between 0 and 1
true if equal; false otherwise
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||