NumericUtils
Helper APIs to encode numeric values as sortable bytes and vice-versa.
To also index floating point numbers, this class supplies two methods to convert them to integer values by changing their bit layout: .doubleToSortableLong, .floatToSortableInt. You will have no precision loss by converting floating point numbers to integers and back (only that the integer form is not usable). Other data types like dates can easily converted to longs or ints (e.g. date to long: java.util.Date.getTime).
Functions
Encodes a BigInteger value such that unsigned byte order comparison is consistent with BigInteger.compareTo. This also sign-extends the value to bigIntSize bytes if necessary: useful to create a fixed-width size.
Converts a double value to a sortable signed long. The value is converted by getting their IEEE 754 floating-point "double format" bit layout and then some bits are swapped, to be able to compare the result as long. By this the precision is not reduced, but the value can easily used as a long. The sort order (including ) is defined by Double.compareTo; NaN is greater than positive infinity.
Converts a float value to a sortable signed int. The value is converted by getting their IEEE 754 floating-point "float format" bit layout and then some bits are swapped, to be able to compare the result as int. By this the precision is not reduced, but the value can easily be used as an int. The sort order (including ) is defined by Float.compareTo; NaN is greater than positive infinity.
Encodes an integer value such that unsigned byte order comparison is consistent with Integer.compare
Encodes an long value such that unsigned byte order comparison is consistent with Long.compare
Decodes a BigInteger value previously written with .bigIntToSortableBytes
Decodes an integer value previously written with .intToSortableBytes
Decodes a long value previously written with .longToSortableBytes
Converts IEEE 754 representation of a double to sortable order (or back to the original)
Converts IEEE 754 representation of a float to sortable order (or back to the original)
Converts a sortable int back to a float.
Converts a sortable long back to a double.