Java Utililty Methods Double to Long

List of utility methods to do Double to Long

Description

The list of methods to do Double to Long are organized into topic(s).

Method

ObjectdoubleToLong(Double aVal)
if the double can safely be converted to a Long then do it.
if (Double.compare(aVal, Math.ceil(aVal)) == 0) {
    return aVal.longValue();
} else
    return aVal;
LongdoubleToLong(double d)
double To Long
if (d >= Long.MIN_VALUE && d <= Long.MAX_VALUE) {
    return (long) d;
return null;
long[]doubleToLong(double[] values)
double To Long
if (values == null) {
    return null;
long[] results = new long[values.length];
for (int i = 0; i < values.length; i++) {
    results[i] = (long) values[i];
return results;
...
longdoubleToLong(final double d)
double To Long
if (d > Long.MAX_VALUE || d < Long.MIN_VALUE)
    throw new IllegalArgumentException("floating point value is too large to be converted to a Long.");
double x = ((Double) d).longValue();
if (x != d && d < 0.0)
    --x;
return (long) x;
longDoubleToLong_With_Little_Endian(double dd)
Double To Lon Wit Littl Endian
return Long.reverseBytes(Double.doubleToLongBits(dd));
long[]doubleToLongArray(final double value)
double To Long Array
final double d = (value == 0.0) ? 0.0 : value; 
final long[] array = { Double.doubleToLongBits(d) }; 
return array;
longdoubleToLongBits(double val)
double To Long Bits
String dbl = String.valueOf(val);
int decimpoints = dbl.indexOf(".") > -1 ? dbl.split("\\.")[1].length() : 1;
long factor = (long) Math.pow(10, decimpoints);
val = val * factor;
return Math.round(val);
longdoubleToLongBits(double value)
double To Long Bits
return Double.doubleToLongBits(value);
longdoubleToLongBits(final double d)
Returns the representation of the specified floating-point value according to the IEEE 754 floating-point "double format" bit layout, after first mapping -0.0 to 0.0.
return ((d == 0.0d) ? 0l : Double.doubleToLongBits(d));
longdoubleToLongBits(final double v)
double To Long Bits
if (Double.isNaN(v)) {
    return 0x0FFFL << 51;
long sign = (v < 0 ? 0x1L << 63 : 0);
long exponent = 0;
double absV = Math.abs(v);
if (Double.isInfinite(v)) {
    exponent = 0x07FFL << 52;
...