private static int encodeNumericSmall(PositionedByteRange dst, BigDecimal val) {
    // TODO: this can be done faster?
    // assert 1.0 > abs(val) > 0.0
    BigDecimal abs = val.abs();
    assert BigDecimal.ZERO.compareTo(abs) < 0 && BigDecimal.ONE.compareTo(abs) > 0;
    byte[] a = dst.getBytes();
    boolean isNeg = val.signum() == -1;
    final int offset = dst.getOffset(), start = dst.getPosition();

    if (isNeg) { /* Small negative number: 0x14, -E, ~M */
      dst.put(NEG_SMALL);
    } else { /* Small positive number: 0x16, ~-E, M */
      dst.put(POS_SMALL);
    }

    // normalize abs(val) to determine E
    int zerosBeforeFirstNonZero = abs.scale() - abs.precision();
    int lengthToMoveRight =
      zerosBeforeFirstNonZero % 2 == 0 ? zerosBeforeFirstNonZero : zerosBeforeFirstNonZero - 1;
    int e = lengthToMoveRight / 2;
    abs = abs.movePointRight(lengthToMoveRight);

    putVaruint64(dst, e, !isNeg); // encode appropriate E value.

    // encode M by peeling off centimal digits, encoding x as 2x+1
    int startM = dst.getPosition();
    encodeToCentimal(dst, abs);
    // terminal digit should be 2x
    a[offset + dst.getPosition() - 1] = (byte) (a[offset + dst.getPosition() - 1] & 0xfe);
    if (isNeg) {
      // negative values encoded as ~M
      DESCENDING.apply(a, offset + startM, dst.getPosition() - startM);
    }
    return dst.getPosition() - start;
  }
<p>
Encode the small magnitude floating point number {@code val} using the key encoding. The caller
guarantees that 1.0 > abs(val) > 0.0.
</p>
<p>
A floating point value is encoded as an integer exponent {@code E} and a mantissa {@code M}.
The original value is equal to {@code (M * 100^E)}. {@code E} is set to the smallest value
possible without making {@code M} greater than or equal to 1.0.
</p>
<p>
For this routine, {@code E} will always be zero or negative, since the original value is less
than one. The encoding written by this routine is the ones-complement of the varint of the
negative of {@code E} followed by the mantissa:

<pre>
  Encoding:   ~-E  M
</pre>
</p>
@param dst The destination to which encoded digits are written.
@param val The value to encode.
@return the number of bytes written.
hbase-common/src/main/java/org/apache/hadoop/hbase/util/OrderedBytes.java