public class EpsilonDoublePrecisionContext extends DoublePrecisionContext implements Serializable
DoublePrecisionContext subclass that uses an absolute epsilon value to
determine equality between doubles.
This class uses the Precision.compareTo(double, double, double) method to compare
numbers. Two values are considered equal if there is no floating point
value strictly between them or if their numerical difference is less than or equal
to the configured epsilon value.
Precision.compareTo(double, double, double),
Serialized Form| Constructor and Description |
|---|
EpsilonDoublePrecisionContext(double eps)
Simple constructor.
|
| Modifier and Type | Method and Description |
|---|---|
int |
compare(double a,
double b)
Compare two double values.
|
boolean |
equals(Object obj) |
double |
getEpsilon()
Get the epsilon value for the instance.
|
double |
getMaxZero()
Get the largest positive double value that is still considered equal
to zero by this instance.
|
int |
hashCode() |
String |
toString() |
compare, eq, eqZero, gt, gte, lt, lte, signclone, finalize, getClass, notify, notifyAll, wait, wait, waitcomparing, comparing, comparingDouble, comparingInt, comparingLong, naturalOrder, nullsFirst, nullsLast, reversed, reverseOrder, thenComparing, thenComparing, thenComparing, thenComparingDouble, thenComparingInt, thenComparingLongpublic EpsilonDoublePrecisionContext(double eps)
eps - Epsilon value. Numbers are considered equal if there is no
floating point value strictly between them or if their difference is less
than or equal to this value.IllegalArgumentException - if the given epsilon value is infinite, NaN, or negativepublic double getEpsilon()
public double getMaxZero()
getMaxZero in class DoublePrecisionContextgetEpsilon()public int compare(double a,
double b)
0 if the arguments are considered equal,
-1 if a < b,
+1 if a > b or if either value is NaN.
compare in class DoublePrecisionContexta - first valueb - second value0 if the values are considered equal, -1 if the
first is smaller than the second, 1 is the first is larger
than the second or either value is NaN.public boolean equals(Object obj)
equals in interface Comparator<Double>equals in class ObjectCopyright © 2016–2020 The Apache Software Foundation. All rights reserved.