Class Doubles
- Since:
- 2.0.0
-
Field Summary
Modifier and TypeFieldDescriptionstatic final double
Epsilon that is used for comparison operations in this class. -
Method Summary
Modifier and TypeMethodDescriptionstatic int
compare
(double left, double right) Gets an integer, that indicates the result of the comparison.static double
confined
(double low, double x, double high) Returns a double that is the confined value ofx
for two bounds.static boolean
equals
(double v1, double v2) Returnstrue
, if the values are equal.static boolean
lessThan
(double left, double right) Returnstrue
, is left comparand is less or equal to right comparand.static boolean
moreThan
(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.EPSILON
is 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;false
otherwise- 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
lessThan
with 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
, ifleft
is more than or equalsright
;false
otherwise- 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
moreThan
with 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
, ifleft
is less than or equalsright
;false
otherwise- 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
left
is 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 ofx
for two bounds.If
x
is less thanlow
, thenlow
is returned.If
x
is more thanhigh
, thenhigh
is returned.Otherwise
x
is returned.- Parameters:
low
- lower boundx
- target double to confinehigh
- upper bound- Returns:
- confined double
- Since:
- 2.0.0
-