Package io.deephaven.util.compare
Class DoubleComparisons
java.lang.Object
io.deephaven.util.compare.DoubleComparisons
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic intcompare(double lhs, double rhs) Compares two doubles according to the following rules:QueryConstants.NULL_DOUBLEis less than all otherdoublevalues (includingDouble.NEGATIVE_INFINITY)0.0and-0.0are equalDouble.NaN(and all otherdoubleNaNrepresentations) is equal toDouble.NaNand greater than all otherdoublevalues (includingDouble.POSITIVE_INFINITY) Otherwise, normaldoublecomparison logic is usedstatic booleaneq(double lhs, double rhs) Compare two doubles for equality consistent withcompare(double, double); that iscompare(lhs, rhs) == 0 ⇒ eq(lhs, rhs)andcompare(lhs, rhs) != 0 ⇒ !eq(lhs, rhs).static booleangeq(double lhs, double rhs) Logically equivalent tocompare(lhs, rhs) >= 0.static booleangt(double lhs, double rhs) Logically equivalent tocompare(lhs, rhs) > 0.static inthashCode(double x) Returns a hash code for adoublevalue consistent witheq(double, double); that is,eq(x, y) ⇒ hashCode(x) == hashCode(y).static booleanleq(double lhs, double rhs) Logically equivalent tocompare(lhs, rhs) <= 0.static booleanlt(double lhs, double rhs) Logically equivalent tocompare(lhs, rhs) < 0.
-
Constructor Details
-
DoubleComparisons
public DoubleComparisons()
-
-
Method Details
-
compare
public static int compare(double lhs, double rhs) Compares two doubles according to the following rules:QueryConstants.NULL_DOUBLEis less than all otherdoublevalues (includingDouble.NEGATIVE_INFINITY)0.0and-0.0are equalDouble.NaN(and all otherdoubleNaNrepresentations) is equal toDouble.NaNand greater than all otherdoublevalues (includingDouble.POSITIVE_INFINITY)- Otherwise, normal
doublecomparison logic is used
Note: this differs from the Java language numerical comparison operators
<, <=, ==, >=, >andDouble.compare(double, double).- Parameters:
lhs- the first valuerhs- the second value- Returns:
- the value
0iflhsis equal torhs; a value less than0iflhsis less thanrhs; and a value greater than0iflhsis greater thanrhs
-
eq
public static boolean eq(double lhs, double rhs) Compare two doubles for equality consistent withcompare(double, double); that iscompare(lhs, rhs) == 0 ⇒ eq(lhs, rhs)andcompare(lhs, rhs) != 0 ⇒ !eq(lhs, rhs).Logically equivalent to
compare(lhs, rhs) == 0.- Parameters:
lhs- the first valuerhs- the second value- Returns:
trueif the values are equal,falseotherwise
-
hashCode
public static int hashCode(double x) Returns a hash code for adoublevalue consistent witheq(double, double); that is,eq(x, y) ⇒ hashCode(x) == hashCode(y).- Parameters:
x- the value to hash- Returns:
- a hash code value for a
doublevalue
-
gt
public static boolean gt(double lhs, double rhs) Logically equivalent tocompare(lhs, rhs) > 0.- Parameters:
lhs- the first valuerhs- the second value- Returns:
trueifflhsis greater thanrhs
-
lt
public static boolean lt(double lhs, double rhs) Logically equivalent tocompare(lhs, rhs) < 0.- Parameters:
lhs- the first valuerhs- the second value- Returns:
trueifflhsis less thanrhs
-
geq
public static boolean geq(double lhs, double rhs) Logically equivalent tocompare(lhs, rhs) >= 0.- Parameters:
lhs- the first valuerhs- the second value- Returns:
trueifflhsis greater than or equal torhs
-
leq
public static boolean leq(double lhs, double rhs) Logically equivalent tocompare(lhs, rhs) <= 0.- Parameters:
lhs- the first valuerhs- the second value- Returns:
trueifflhsis less than or equal torhs
-