Package org.apache.commons.numbers.core
Interface Precision.DoubleEquivalence
-
- Enclosing class:
- Precision
public static interface Precision.DoubleEquivalence
Interface containing comparison operations for doubles that allow values to be considered equal even if they are not exactly equal. It is intended for comparing outputs of a computation where floating point errors may have occurred.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description intcompare(double a, double b)Compares two values.default booleaneq(double a, double b)Indicates whether given values are considered equal to each other.default booleaneqZero(double a)Indicates whether the given value is considered equal to zero.default booleangt(double a, double b)Indicates whether the first argument is strictly greater than the second.default booleangte(double a, double b)Indicates whether the first argument is greater than or considered equal to the second.default booleanlt(double a, double b)Indicates whether the first argument is strictly smaller than the second.default booleanlte(double a, double b)Indicates whether the first argument is smaller or considered equal to the second.default doublesignum(double a)Returns thesignof the argument.
-
-
-
Method Detail
-
eq
default boolean eq(double a, double b)
Indicates whether given values are considered equal to each other.- Parameters:
a- Value.b- Value.- Returns:
- true if the given values are considered equal.
-
eqZero
default boolean eqZero(double a)
Indicates whether the given value is considered equal to zero. It is a shortcut foreq(a, 0.0).- Parameters:
a- Value.- Returns:
- true if the argument is considered equal to zero.
-
lt
default boolean lt(double a, double b)
Indicates whether the first argument is strictly smaller than the second.- Parameters:
a- Value.b- Value.- Returns:
- true if
a < b
-
lte
default boolean lte(double a, double b)
Indicates whether the first argument is smaller or considered equal to the second.- Parameters:
a- Value.b- Value.- Returns:
- true if
a <= b
-
gt
default boolean gt(double a, double b)
Indicates whether the first argument is strictly greater than the second.- Parameters:
a- Value.b- Value.- Returns:
- true if
a > b
-
gte
default boolean gte(double a, double b)
Indicates whether the first argument is greater than or considered equal to the second.- Parameters:
a- Value.b- Value.- Returns:
- true if
a >= b
-
signum
default double signum(double a)
Returns thesignof the argument. The returned value is-0.0ifais considered equal to zero and negatively signed,+0.0ifais considered equal to zero and positively signed,-1.0ifais considered less than zero,+1.0ifais considered greater than zero.
The equality with zero uses the
eqZeromethod.- Parameters:
a- Value.- Returns:
- the sign (or
aifa == 0orais NaN). - See Also:
eqZero(double)
-
compare
int compare(double a, double b)
Compares two values. The returned value is0if the arguments are considered equal,-1ifa < b,+1ifa > bor if either value is NaN.
- Parameters:
a- Value.b- Value.- Returns:
0if the values are considered equal,-1if the first is smaller than the second,1is the first is larger than the second or either value is NaN.
-
-