Class PrecisionUtils
java.lang.Object
org.eclipse.gef.geometry.internal.utils.PrecisionUtils
A utility class for floating point calculations and comparisons that should
guarantee a precision of a given scale, and ignore differences beyond this
scale.
-
Method Summary
Modifier and TypeMethodDescriptionstatic final double
calculateFraction
(int shift) Computes the smallest double that is yet recognizable (by comparison) when shifting the default scale up by the given amount.static final boolean
equal
(double d1, double d2) static final boolean
equal
(double d1, double d2, int shift) Tests whether the two values are regarded to be equal w.r.t. the given shift.static final boolean
greater
(double d1, double d2) static final boolean
greater
(double d1, double d2, int shift) Tests whether the first given value is regarded to be greater than the second value w.r.t. the given shift.static final boolean
greaterEqual
(double d1, double d2) static final boolean
greaterEqual
(double d1, double d2, int shift) Tests whether the first given value is regarded to be greater or equal than the second value w.r.t. the given shift.static final boolean
smaller
(double d1, double d2) static final boolean
smaller
(double d1, double d2, int shift) Tests whether the first given value is regarded to be smaller than the second value w.r.t. the given shift.static final boolean
smallerEqual
(double d1, double d2) static final boolean
smallerEqual
(double d1, double d2, int shift) Tests whether the first given value is regarded to be smaller or equal than the second value w.r.t. the given shift.
-
Method Details
-
calculateFraction
public static final double calculateFraction(int shift) Computes the smallest double that is yet recognizable (by comparison) when shifting the default scale up by the given amount.- Parameters:
shift
- the number of digits to shift precision up (may be negative number)- Returns:
- the smallest double that will yet be recognizable by the methods of this class during comparison, when using the default scale shifted by the given amount.
-
equal
public static final boolean equal(double d1, double d2) - Parameters:
d1
- The first operand.d2
- The second operand.- Returns:
- result of the comparison
- See Also:
-
equal
public static final boolean equal(double d1, double d2, int shift) Tests whether the two values are regarded to be equal w.r.t. the given shift.- Parameters:
d1
- the first value to testd2
- the second value to testshift
- the delta shift used for this test- Returns:
true
in case the given two values are identical or differ from each other by an amount that is smaller than what is recognizable by the shifted delta,false
otherwise
-
greater
public static final boolean greater(double d1, double d2) - Parameters:
d1
- The first operand.d2
- The second operand.- Returns:
- result of the comparison
- See Also:
-
greater
public static final boolean greater(double d1, double d2, int shift) Tests whether the first given value is regarded to be greater than the second value w.r.t. the given shift.- Parameters:
d1
- the first value to testd2
- the second value to testshift
- the delta shift used for this test- Returns:
true
in case the first value is greater than the second value by an amount recognizable by the shifted delta,false
otherwise
-
greaterEqual
public static final boolean greaterEqual(double d1, double d2) - Parameters:
d1
- The first operand.d2
- The second operand.- Returns:
- result of the comparison
- See Also:
-
greaterEqual
public static final boolean greaterEqual(double d1, double d2, int shift) Tests whether the first given value is regarded to be greater or equal than the second value w.r.t. the given shift.- Parameters:
d1
- the first value to testd2
- the second value to testshift
- the delta shift used for this test- Returns:
true
in case the first value is greater than the second value by an amount recognizable by the given scale or differs from it by an amount not recognizable by the shifted delta,false
otherwise
-
smaller
public static final boolean smaller(double d1, double d2) - Parameters:
d1
- The first operand.d2
- The second operand.- Returns:
- result of the comparison
- See Also:
-
smaller
public static final boolean smaller(double d1, double d2, int shift) Tests whether the first given value is regarded to be smaller than the second value w.r.t. the given shift.- Parameters:
d1
- the first value to testd2
- the second value to testshift
- the delta shift used for this test- Returns:
true
in case the first value is smaller than the second value by an amount recognizable by the shifted delta,false
otherwise
-
smallerEqual
public static final boolean smallerEqual(double d1, double d2) - Parameters:
d1
- The first operand.d2
- The second operand.- Returns:
- result of the comparison
- See Also:
-
smallerEqual
public static final boolean smallerEqual(double d1, double d2, int shift) Tests whether the first given value is regarded to be smaller or equal than the second value w.r.t. the given shift.- Parameters:
d1
- the first value to testd2
- the second value to testshift
- the delta shift used for this test- Returns:
true
in case the first value is smaller than the second value by an amount recognizable by the given scale or differs from it by an amount not recognizable by the shifted delta,false
otherwise
-