Class PrecisionUtils
- java.lang.Object
-
- org.eclipse.gef.geometry.internal.utils.PrecisionUtils
-
public class PrecisionUtils extends java.lang.ObjectA 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
All Methods Static Methods Concrete Methods Modifier and Type Method Description static doublecalculateFraction(int shift)Computes the smallest double that is yet recognizable (by comparison) when shifting the default scale up by the given amount.static booleanequal(double d1, double d2)static booleanequal(double d1, double d2, int shift)Tests whether the two values are regarded to be equal w.r.t. the given shift.static booleangreater(double d1, double d2)static booleangreater(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 booleangreaterEqual(double d1, double d2)static booleangreaterEqual(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 booleansmaller(double d1, double d2)static booleansmaller(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 booleansmallerEqual(double d1, double d2)static booleansmallerEqual(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 Detail
-
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(double, double, int)
-
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:
truein 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,falseotherwise
-
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(double, double, int)
-
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:
truein case the first value is greater than the second value by an amount recognizable by the shifted delta,falseotherwise
-
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(double, double, int)
-
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:
truein 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,falseotherwise
-
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(double, double, int)
-
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:
truein case the first value is smaller than the second value by an amount recognizable by the shifted delta,falseotherwise
-
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(double, double, int)
-
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:
truein 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,falseotherwise
-
-