Package org.planit.utils.math
Class Precision
- java.lang.Object
-
- org.planit.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_3static doubleEPSILON_6the default Epsilon unless indicated otherwise
-
Constructor Summary
Constructors Constructor Description Precision()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static booleanisEqual(double d1, double d2)Compare using a Precision.EPSILON_6static booleanisEqual(double d1, double d2, double epsilon)Compare using a custom precision epsilonstatic booleanisGreater(double d1, double d2)isGreater with Precision.EPSILON_6static booleanisGreater(double d1, double d2, double epsilon)isGreaterEqual with epsilonstatic booleanisGreaterEqual(double d1, double d2)isGreaterEqual with Precision.EPSILON_6static booleanisGreaterEqual(double d1, double d2, double epsilon)isGreaterEqual with epsilonstatic booleanisSmaller(double d1, double d2)isSmaller with Precision.EPSILON_6static booleanisSmaller(double d1, double d2, double epsilon)isSmaller with epsilonstatic booleanisSmallerEqual(double d1, double d2)isSmallerEqual with Precision.EPSILON_6static booleanisSmallerEqual(double d1, double d2, double epsilon)isSmallerEqual with epsilon
-
-
-
Field Detail
-
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
-
isEqual
public static boolean isEqual(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
-
isEqual
public static boolean isEqual(double d1, double d2)Compare using a Precision.EPSILON_6- Parameters:
d1- double1d2- double2- Returns:
- true when equal within epsilon, false otherwise
-
isSmallerEqual
public static boolean isSmallerEqual(double d1, double d2, double epsilon)isSmallerEqual with epsilon- Parameters:
d1- double1d2- double2epsilon- epsilon value- Returns:
- true when
d1 <= (d2 + epsilon)
-
isSmaller
public static boolean isSmaller(double d1, double d2)isSmaller with Precision.EPSILON_6- Parameters:
d1- double1d2- double2- Returns:
- true when
(d1 + epsilon) < d2
-
isSmaller
public static boolean isSmaller(double d1, double d2, double epsilon)isSmaller with epsilon- Parameters:
d1- double1d2- double2epsilon- epsilon value- Returns:
- true when
d1 <= (d2 + epsilon)
-
isSmallerEqual
public static boolean isSmallerEqual(double d1, double d2)isSmallerEqual with Precision.EPSILON_6- Parameters:
d1- double1d2- double2- Returns:
- true when
(d1 + epsilon) <= d2
-
isGreaterEqual
public static boolean isGreaterEqual(double d1, double d2, double epsilon)isGreaterEqual with epsilon- Parameters:
d1- double1d2- double2epsilon- epsilon value- Returns:
- true when
d1 >= (d2 - epsilon)
-
isGreaterEqual
public static boolean isGreaterEqual(double d1, double d2)isGreaterEqual with Precision.EPSILON_6- Parameters:
d1- double1d2- double2- Returns:
- true when
(d1 - epsilon) >= d2
-
isGreater
public static boolean isGreater(double d1, double d2, double epsilon)isGreaterEqual with epsilon- Parameters:
d1- double1d2- double2epsilon- epsilon value- Returns:
- true when
d1 > (d2 - epsilon)
-
isGreater
public static boolean isGreater(double d1, double d2)isGreater with Precision.EPSILON_6- Parameters:
d1- double1d2- double2- Returns:
- true when
(d1 - epsilon) > d2
-
-