Package io.deephaven.base
Class CompareUtils
java.lang.Object
io.deephaven.base.CompareUtils
-
Field Summary
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic int
compare
(double a, double b) static int
compare
(long a, long b) static int
static int
compareUnsigned
(long a, long b) static int
doubleCompare
(double d1, double d2) static boolean
doubleEquals
(double x, double y) static boolean
doubleEquals
(double x, double y, double tolerance) You can't do double1 == double2 because floating point numbers are not exact values.static boolean
doubleEquals2
(double x, double y) static boolean
doubleEquals2
(double x, double y, double tolerance) static boolean
doubleEqualsZero
(double x) static boolean
doubleEqualsZero
(double x, double tolerance) static boolean
doubleGreater
(double x, double y) static boolean
doubleGreater
(double x, double y, double tolerance) static boolean
doubleGreaterEqual
(double x, double y) static boolean
doubleGreaterEqual
(double x, double y, double tolerance) static boolean
doubleLess
(double x, double y) static boolean
doubleLess
(double x, double y, double tolerance) You can't do double1 < double2 because floating point numbers are not exact values.static boolean
doubleLessEqual
(double x, double y) static boolean
doubleLessEqual
(double x, double y, double tolerance) static boolean
doubleNotEquals
(double x, double y) static boolean
doubleNotEquals
(double x, double y, double tolerance) static boolean
doubleNotEquals2
(double x, double y) static boolean
doubleNotEquals2
(double x, double y, double tolerance) static boolean
EQ
(double x, double y) You can't do double1 == double2 because floating point numbers are not exact values.static boolean
EQ2
(double x, double y) static boolean
static boolean
GE
(double x, double y) static boolean
GT
(double x, double y) You can't do double1 > double2 because floating point numbers are not exact values.static boolean
LE
(double x, double y) static boolean
LT
(double x, double y) static boolean
NE
(double x, double y) Since logical comparison of double values considering error is effectively a three-value logic, you can't really do !equals when you mean notEquals.static boolean
NE2
(double x, double y) static boolean
nullSafeEquals
(Object left, Object right) Returns true if the given objects are both null, or equal by the first object'sequals(java.lang.Object, java.lang.Object)
method.
-
Field Details
-
ERROR
public static final double ERROR- See Also:
-
-
Constructor Details
-
CompareUtils
public CompareUtils()
-
-
Method Details
-
compare
-
compare
public static int compare(long a, long b) -
compareUnsigned
public static int compareUnsigned(long a, long b) -
compare
public static int compare(double a, double b) -
equals
-
nullSafeEquals
Returns true if the given objects are both null, or equal by the first object'sequals(java.lang.Object, java.lang.Object)
method. -
EQ
public static boolean EQ(double x, double y) You can't do double1 == double2 because floating point numbers are not exact values. Just make sure that x-y is less than some allowable error factor.- Parameters:
x
-y
-- Returns:
- True if the two doubles are equal to each other (or so close that we don't care that they are different).
-
doubleEquals
public static boolean doubleEquals(double x, double y) -
doubleEqualsZero
public static boolean doubleEqualsZero(double x) -
doubleEquals
public static boolean doubleEquals(double x, double y, double tolerance) You can't do double1 == double2 because floating point numbers are not exact values. Just make sure that x-y is less than some allowable error factor.- Parameters:
x
-y
-- Returns:
- True if the two doubles are equal to each other (or so close that we don't care that they are different). Also true if both are NaN.
-
doubleEqualsZero
public static boolean doubleEqualsZero(double x, double tolerance) -
EQ2
public static boolean EQ2(double x, double y) -
doubleEquals2
public static boolean doubleEquals2(double x, double y) -
doubleEquals2
public static boolean doubleEquals2(double x, double y, double tolerance) -
NE
public static boolean NE(double x, double y) Since logical comparison of double values considering error is effectively a three-value logic, you can't really do !equals when you mean notEquals.- Parameters:
x
-y
-- Returns:
- True if two doubles are apart from each other enough that we consider them different. False if both of them are NaN
-
doubleNotEquals
public static boolean doubleNotEquals(double x, double y) -
doubleNotEquals
public static boolean doubleNotEquals(double x, double y, double tolerance) -
NE2
public static boolean NE2(double x, double y) -
doubleNotEquals2
public static boolean doubleNotEquals2(double x, double y) -
doubleNotEquals2
public static boolean doubleNotEquals2(double x, double y, double tolerance) -
GT
public static boolean GT(double x, double y) You can't do double1 > double2 because floating point numbers are not exact values. Just make sure that x-y is greater than some allowable error factor for equality- Parameters:
x
-y
-- Returns:
- True if x is greater than y (including error factor for equality).
-
doubleGreater
public static boolean doubleGreater(double x, double y) -
doubleGreater
public static boolean doubleGreater(double x, double y, double tolerance) -
GE
public static boolean GE(double x, double y) -
doubleGreaterEqual
public static boolean doubleGreaterEqual(double x, double y) -
doubleGreaterEqual
public static boolean doubleGreaterEqual(double x, double y, double tolerance) -
doubleLess
public static boolean doubleLess(double x, double y, double tolerance) You can't do double1 < double2 because floating point numbers are not exact values. Just make sure that y - x is greater than some allowable error factor for equality- Parameters:
x
-y
-- Returns:
- True if x is less than y (including error factor for equality)
-
LT
public static boolean LT(double x, double y) -
doubleLess
public static boolean doubleLess(double x, double y) -
doubleLessEqual
public static boolean doubleLessEqual(double x, double y, double tolerance) -
LE
public static boolean LE(double x, double y) -
doubleLessEqual
public static boolean doubleLessEqual(double x, double y) -
doubleCompare
public static int doubleCompare(double d1, double d2)
-