public final class NumberComparisonHelper extends Object

A utility class for comparing numbers.

Constant Summary

double LONG_EXCLUSIVE_UPPER_BOUND_AS_DOUBLE
double LONG_INCLUSIVE_LOWER_BOUND_AS_DOUBLE
long MAX_SAFE_LONG The maximum value in the main range of integers representable as both long and double.
long MIN_SAFE_LONG The minimum value in the main range of integers representable as both long and double.

Public Method Summary

static int
compareLongs(long leftLong, long rightLong)
Compares longs.
static int
firestoreCompareDoubleWithLong(double doubleValue, long longValue)
Compares a double and a with Firestore query semantics: NaN precedes all other numbers and equals itself, all zeroes are equal.
static int
firestoreCompareDoubles(double leftDouble, double rightDouble)
Compares doubles with Firestore query semantics: NaN precedes all other numbers and equals itself, all zeroes are equal.

Inherited Method Summary

Constants

public static final double LONG_EXCLUSIVE_UPPER_BOUND_AS_DOUBLE

Constant Value: 9.223372036854776E18

public static final double LONG_INCLUSIVE_LOWER_BOUND_AS_DOUBLE

Constant Value: -9.223372036854776E18

public static final long MAX_SAFE_LONG

The maximum value in the main range of integers representable as both long and double.

Constant Value: 9007199254740992

public static final long MIN_SAFE_LONG

The minimum value in the main range of integers representable as both long and double.

Constant Value: -9007199254740992

Public Methods

public static int compareLongs (long leftLong, long rightLong)

Compares longs. Note that we can't use Long.compare because it's only available after Android 19.

Parameters
leftLong
rightLong

public static int firestoreCompareDoubleWithLong (double doubleValue, long longValue)

Compares a double and a with Firestore query semantics: NaN precedes all other numbers and equals itself, all zeroes are equal.

Parameters
doubleValue
longValue

public static int firestoreCompareDoubles (double leftDouble, double rightDouble)

Compares doubles with Firestore query semantics: NaN precedes all other numbers and equals itself, all zeroes are equal.

Parameters
leftDouble
rightDouble
Returns
  • a negative integer, zero, or a positive integer as the first argument is less than, equal to, or greater than the second.