Here you can find the source of doubleToSortableLong(double val)
double
value to a sortable signed long
.
public static long doubleToSortableLong(double val)
//package com.java2s; // Licensed under the Apache License, Version 2.0 (the "License"); public class Main { /**/*from w w w.ja va 2s. c o m*/ * Converts a <code>double</code> value to a sortable signed <code>long</code>. * 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 {@link Double#NaN}) is defined by * {@link Double#compareTo}; {@code NaN} is greater than positive infinity. * @see #sortableLongToDouble */ public static long doubleToSortableLong(double val) { return sortableDoubleBits(Double.doubleToLongBits(val)); } /** Converts IEEE 754 representation of a double to sortable order (or back to the original) */ public static long sortableDoubleBits(long bits) { return bits ^ (bits >> 63) & 0x7fffffffffffffffL; } }