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 DecimalFormat
DEFAULT_DECIMAL_FORMAT
default decimal format used applies a maximum of 8 decimals and a minimum of 2static double
EPSILON_12
static double
EPSILON_15
static double
EPSILON_18
static double
EPSILON_3
static double
EPSILON_6
the default Epsilon unless indicated otherwisestatic double
EPSILON_9
-
Constructor Summary
Constructors Constructor Description Precision()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static boolean
isEqual(double d1, double d2)
Compare using a Precision.EPSILON_6static boolean
isEqual(double d1, double d2, double epsilon)
Compare using a custom precision epsilonstatic boolean
isGreater(double d1, double d2)
isGreater with Precision.EPSILON_6static boolean
isGreater(double d1, double d2, double epsilon)
isGreaterEqual with epsilonstatic boolean
isGreaterEqual(double d1, double d2)
isGreaterEqual with Precision.EPSILON_6static boolean
isGreaterEqual(double d1, double d2, double epsilon)
isGreaterEqual with epsilonstatic boolean
isNotEqual(double d1, double d2)
Opposite ofisEqual(double, double)
static boolean
isPositive(double d1)
Verify if positive with Precision.EPSILON_6static boolean
isSmaller(double d1, double d2)
isSmaller with Precision.EPSILON_6static boolean
isSmaller(double d1, double d2, double epsilon)
isSmaller with epsilonstatic boolean
isSmallerEqual(double d1, double d2)
isSmallerEqual with Precision.EPSILON_6static boolean
isSmallerEqual(double d1, double d2, double epsilon)
isSmallerEqual with epsilon
-
-
-
Field Detail
-
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
-
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 +epsilon) < d2
-
isSmallerEqual
public static boolean isSmallerEqual(double d1, double d2)
isSmallerEqual with Precision.EPSILON_6- Parameters:
d1
- double1d2
- double2- Returns:
- true when
d1 <= (d2 + epsilon)
-
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 >= (d2- epsilon)
-
isGreater
public static boolean isGreater(double d1, double d2, double epsilon)
isGreaterEqual with epsilon- Parameters:
d1
- double1d2
- double2epsilon
- epsilon value- Returns:
- true when
(d1 - epsilon) > d2
-
isGreater
public static boolean isGreater(double d1, double d2)
isGreater with Precision.EPSILON_6- Parameters:
d1
- double1d2
- double2- Returns:
- true when
(d1 - epsilon) > d2
-
isPositive
public static boolean isPositive(double d1)
Verify if positive with Precision.EPSILON_6- Parameters:
d1
- double 1- Returns:
- true when
d1 > EPSILON_6
-
isNotEqual
public static boolean isNotEqual(double d1, double d2)
Opposite ofisEqual(double, double)
- Parameters:
d1
- to used2
- to use- Returns:
- true when not equal, false otherwise
-
-