Class Doubles
- Since:
- 2.0.0
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final doubleEpsilon that is used for comparison operations in this class. -
Method Summary
Modifier and TypeMethodDescriptionstatic intcompare(double left, double right) Gets an integer, that indicates the result of the comparison.static doubleconfined(double low, double x, double high) Returns a double that is the confined value ofxfor two bounds.static booleanequals(double v1, double v2) Returnstrue, if the values are equal.static booleanlessThan(double left, double right) Returnstrue, is left comparand is less or equal to right comparand.static booleanmoreThan(double left, double right) Returnstrue, is left comparand is more or equal to right comparand.
-
Field Details
-
EPSILON
public static final double EPSILONEpsilon that is used for comparison operations in this class.EPSILONis almost equal to zero, so all functions try to get zero and compare it to the epsilon.- Since:
- 2.0.0
- See Also:
-
-
Method Details
-
equals
public static boolean equals(double v1, double v2) Returnstrue, if the values are equal.Uses epsilon for the comparison.
- Parameters:
v1- first doublev2- second double- Returns:
true, if the values are equal;falseotherwise- Since:
- 2.0.0
-
moreThan
public static boolean moreThan(double left, double right) Returnstrue, is left comparand is more or equal to right comparand.Uses epsilon for the comparison. Because of that, comparison is non-strict.
Should give the same result as
lessThanwith swapped comparands, if they are not equal. If they are equal, both functions should returntrue.- Parameters:
left- double to be comparedright- double it is compared to- Returns:
true, ifleftis more than or equalsright;falseotherwise- Since:
- 2.0.0
- See Also:
-
lessThan
public static boolean lessThan(double left, double right) Returnstrue, is left comparand is less or equal to right comparand.Uses epsilon for the comparison. Because of that, comparison is non-strict.
Should give the same result as
moreThanwith swapped comparands, if they are not equal. If they are equal, both functions should returntrue.- Parameters:
left- double to be comparedright- double it is compared to- Returns:
true, ifleftis less than or equalsright;falseotherwise- Since:
- 2.0.0
- See Also:
-
compare
public static int compare(double left, double right) Gets an integer, that indicates the result of the comparison.If both values are equal, then 0 is returned.
If
leftis more thanright, then 1 is returned.Otherwise, -1 is returned.
It does not function as shorthand syntax for
lessThan(double, double)andmoreThan(double, double), because they are non-strict comparisons.- Parameters:
left- double to be comparedright- double it is compared to- Returns:
- 0, 1 or -1
- Since:
- 2.0.0
- See Also:
-
confined
public static double confined(double low, double x, double high) Returns a double that is the confined value ofxfor two bounds.If
xis less thanlow, thenlowis returned.If
xis more thanhigh, thenhighis returned.Otherwise
xis returned.- Parameters:
low- lower boundx- target double to confinehigh- upper bound- Returns:
- confined double
- Since:
- 2.0.0
-