public final class NumericUtils extends Object
Modifier and Type | Method and Description |
---|---|
static long |
doubleToSortableLong(double val)
Converts a
double value to a sortable signed long . |
static int |
floatToSortableInt(float val)
Converts a
float value to a sortable signed int . |
static long |
sortableDoubleBits(long bits)
Converts IEEE 754 representation of a double to sortable order (or back to the original)
|
static int |
sortableFloatBits(int bits)
Converts IEEE 754 representation of a float to sortable order (or back to the original)
|
static float |
sortableIntToFloat(int val)
Converts a sortable
int back to a float . |
static double |
sortableLongToDouble(long val)
Converts a sortable
long back to a double . |
public static long doubleToSortableLong(double val)
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 Double.NaN
) is defined by
Double.compareTo(java.lang.Double)
; NaN
is greater than positive infinity.sortableLongToDouble(long)
public static double sortableLongToDouble(long val)
long
back to a double
.doubleToSortableLong(double)
public static int floatToSortableInt(float val)
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 used as an int.
The sort order (including Float.NaN
) is defined by
Float.compareTo(java.lang.Float)
; NaN
is greater than positive infinity.sortableIntToFloat(int)
public static float sortableIntToFloat(int val)
int
back to a float
.floatToSortableInt(float)
public static long sortableDoubleBits(long bits)
public static int sortableFloatBits(int bits)
Copyright © 2012–2024. All rights reserved.