Package org.goplanit.utils.math
Class Precision
- java.lang.Object
-
- org.goplanit.utils.math.Precision
-
public class Precision extends Object
Compare doubles with a certain precision- Author:
- markr
-
-
Field Summary
Fields Modifier and Type Field Description static DecimalFormatDEFAULT_DECIMAL_FORMATdefault decimal format used applies a maximum of 8 decimals and a minimum of 2static doubleEPSILON_0no tolerance, i.e., 0.0static doubleEPSILON_12static doubleEPSILON_15static doubleEPSILON_18static doubleEPSILON_3static doubleEPSILON_6the default Epsilon unless indicated otherwisestatic doubleEPSILON_9
-
Constructor Summary
Constructors Constructor Description Precision()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static booleanequal(double d1, double d2)Compare using a Precision.EPSILON_6static booleanequal(double d1, double d2, double epsilon)Compare using a custom precision epsilonstatic booleangreater(double d1, double d2)isGreater with Precision.EPSILON_6static booleangreater(double d1, double d2, double epsilon)isGreaterEqual with epsilonstatic booleangreaterEqual(double d1, double d2)isGreaterEqual with Precision.EPSILON_6static booleangreaterEqual(double d1, double d2, double epsilon)isGreaterEqual with epsilonstatic booleannegative(double d1)Verify if negative with Precision.EPSILON_6static booleannonZero(double d1)Verify if non-zero with Precision.EPSILON_6static booleannotEqual(double d1, double d2)Opposite ofequal(double, double)static booleannotEqual(double d1, double d2, double epsilon)Opposite ofequal(double, double, double)static booleanpositive(double d1)Verify if positive with Precision.EPSILON_6static booleanpositive(double d1, double epsilon)Verify if positive with Precision.EPSILON_6static booleansmaller(double d1, double d2)isSmaller with Precision.EPSILON_6static booleansmaller(double d1, double d2, double epsilon)isSmaller with epsilonstatic booleansmallerEqual(double d1, double d2)isSmallerEqual with Precision.EPSILON_6static booleansmallerEqual(double d1, double d2, double epsilon)isSmallerEqual with epsilon
-
-
-
Field Detail
-
EPSILON_0
public static final double EPSILON_0
no tolerance, i.e., 0.0- See Also:
- Constant Field Values
-
EPSILON_18
public static final double EPSILON_18
- See Also:
- Constant Field Values
-
EPSILON_15
public static final double EPSILON_15
- See Also:
- Constant Field Values
-
EPSILON_12
public static final double EPSILON_12
- See Also:
- Constant Field Values
-
EPSILON_9
public static final double EPSILON_9
- See Also:
- Constant Field Values
-
EPSILON_6
public static final double EPSILON_6
the default Epsilon unless indicated otherwise- See Also:
- Constant Field Values
-
EPSILON_3
public static final double EPSILON_3
- See Also:
- Constant Field Values
-
DEFAULT_DECIMAL_FORMAT
public static final DecimalFormat DEFAULT_DECIMAL_FORMAT
default decimal format used applies a maximum of 8 decimals and a minimum of 2
-
-
Method Detail
-
equal
public static boolean equal(double d1, double d2, double epsilon)Compare using a custom precision epsilon- Parameters:
d1- double1d2- double2epsilon- epsilon value- Returns:
- true when equal within epsilon, false otherwise
-
equal
public static boolean equal(double d1, double d2)Compare using a Precision.EPSILON_6- Parameters:
d1- double1d2- double2- Returns:
- true when equal within epsilon, false otherwise
-
smallerEqual
public static boolean smallerEqual(double d1, double d2, double epsilon)isSmallerEqual with epsilon- Parameters:
d1- double1d2- double2epsilon- epsilon value- Returns:
- true when
d1 <= (d2 + epsilon)
-
smaller
public static boolean smaller(double d1, double d2)isSmaller with Precision.EPSILON_6- Parameters:
d1- double1d2- double2- Returns:
- true when
(d1 + epsilon) < d2
-
smaller
public static boolean smaller(double d1, double d2, double epsilon)isSmaller with epsilon- Parameters:
d1- double1d2- double2epsilon- epsilon value- Returns:
- true when
(d1 +epsilon) < d2
-
smallerEqual
public static boolean smallerEqual(double d1, double d2)isSmallerEqual with Precision.EPSILON_6- Parameters:
d1- double1d2- double2- Returns:
- true when
d1 <= (d2 + epsilon)
-
greaterEqual
public static boolean greaterEqual(double d1, double d2, double epsilon)isGreaterEqual with epsilon- Parameters:
d1- double1d2- double2epsilon- epsilon value- Returns:
- true when
d1 >= (d2 - epsilon)
-
greaterEqual
public static boolean greaterEqual(double d1, double d2)isGreaterEqual with Precision.EPSILON_6- Parameters:
d1- double1d2- double2- Returns:
- true when
d1 >= (d2- epsilon)
-
greater
public static boolean greater(double d1, double d2, double epsilon)isGreaterEqual with epsilon- Parameters:
d1- double1d2- double2epsilon- epsilon value- Returns:
- true when
(d1 - epsilon) > d2
-
greater
public static boolean greater(double d1, double d2)isGreater with Precision.EPSILON_6- Parameters:
d1- double1d2- double2- Returns:
- true when
(d1 - epsilon) > d2
-
positive
public static boolean positive(double d1)
Verify if positive with Precision.EPSILON_6- Parameters:
d1- double 1- Returns:
- true when
d1 > EPSILON_6
-
positive
public static boolean positive(double d1, double epsilon)Verify if positive with Precision.EPSILON_6- Parameters:
d1- double 1epsilon- to consider- Returns:
- true when
d1 > epsilon
-
negative
public static boolean negative(double d1)
Verify if negative with Precision.EPSILON_6- Parameters:
d1- double 1- Returns:
- true when
d1 < -EPSILON_6
-
nonZero
public static boolean nonZero(double d1)
Verify if non-zero with Precision.EPSILON_6- Parameters:
d1- double 1- Returns:
- true when
d1 < -EPSILON_6 or d1 > EPSILON_6
-
notEqual
public static boolean notEqual(double d1, double d2)Opposite ofequal(double, double)- Parameters:
d1- to used2- to use- Returns:
- true when not equal, false otherwise
-
notEqual
public static boolean notEqual(double d1, double d2, double epsilon)Opposite ofequal(double, double, double)- Parameters:
d1- to used2- to useepsilon- to use- Returns:
- true when not equal, false otherwise
-
-