public static int encodeFloat64(PositionedByteRange dst, double val, Order ord) {
    final int offset = dst.getOffset(), start = dst.getPosition();
    long lng = Double.doubleToLongBits(val);
    lng ^= ((lng >> (Long.SIZE - 1)) | Long.MIN_VALUE);
    dst.put(FIXED_FLOAT64).put((byte) (lng >> 56)).put((byte) (lng >> 48)).put((byte) (lng >> 40))
      .put((byte) (lng >> 32)).put((byte) (lng >> 24)).put((byte) (lng >> 16))
      .put((byte) (lng >> 8)).put((byte) lng);
    ord.apply(dst.getBytes(), offset + start, 9);
    return 9;
  }
Encode a 64-bit floating point value using the fixed-length encoding.
<p>
This format ensures the following total ordering of floating point values:
Double.NEGATIVE_INFINITY &lt; -Double.MAX_VALUE &lt; ... &lt; -Double.MIN_VALUE &lt; -0.0 &lt;
+0.0; &lt; Double.MIN_VALUE &lt; ... &lt; Double.MAX_VALUE &lt; Double.POSITIVE_INFINITY &lt;
Double.NaN
</p>
<p>
Floating point numbers are encoded as specified in IEEE 754. A 64-bit double precision float
consists of a sign bit, 11-bit unsigned exponent encoded in offset-1023 notation, and a 52-bit
significand. The format is described further in the
<a href="http://en.wikipedia.org/wiki/Double_precision"> Double Precision Floating Point
Wikipedia page</a>
</p>
<p>
The value of a normal float is -1 <sup>sign bit</sup> &times; 2<sup>exponent - 1023</sup>
&times; 1.significand
</p>
<p>
The IEE754 floating point format already preserves sort ordering for positive floating point
numbers when the raw bytes are compared in most significant byte order. This is discussed
further at
<a href= "http://www.cygnus-software.com/papers/comparingfloats/comparingfloats.htm" >
http://www.cygnus-software.com/papers/comparingfloats/comparingfloats. htm</a>
</p>
<p>
Thus, we need only ensure that negative numbers sort in the the exact opposite order as
positive numbers (so that say, negative infinity is less than negative 1), and that all
negative numbers compare less than any positive number. To accomplish this, we invert the sign
bit of all floating point numbers, and we also invert the exponent and significand bits if the
floating point number was negative.
</p>
<p>
More specifically, we first store the floating point bits into a 64-bit long {@code l} using
{@link Double#doubleToLongBits}. This method collapses all NaNs into a single, canonical NaN
value but otherwise leaves the bits unchanged. We then compute
</p>

<pre>
l &circ;= (l &gt;&gt; (Long.SIZE - 1)) | Long.MIN_SIZE
</pre>
<p>
which inverts the sign bit and XOR's all other bits with the sign bit itself. Comparing the raw
bytes of {@code l} in most significant byte order is equivalent to performing a double
precision floating point comparison on the underlying bits (ignoring NaN comparisons, as NaNs
don't compare equal to anything when performing floating point comparisons).
</p>
<p>
The resulting long integer is then converted into a byte array by serializing the long one byte
at a time in most significant byte order. The serialized integer is prefixed by a single header
byte. All serialized values are 9 bytes in length.
</p>
<p>
This encoding format, and much of this highly detailed documentation string, is based on
Orderly's {@code DoubleWritableRowKey}.
</p>
@return the number of bytes written.
@see #decodeFloat64(PositionedByteRange)
hbase-common/src/main/java/org/apache/hadoop/hbase/util/OrderedBytes.java