public static int encodeNumeric(PositionedByteRange dst, BigDecimal val, Order ord) {
    final int len, offset = dst.getOffset(), start = dst.getPosition();
    if (null == val) {
      return encodeNull(dst, ord);
    } else if (BigDecimal.ZERO.compareTo(val) == 0) {
      dst.put(ord.apply(ZERO));
      return 1;
    }
    BigDecimal abs = val.abs();
    if (BigDecimal.ONE.compareTo(abs) <= 0) { // abs(v) >= 1.0
      len = encodeNumericLarge(dst, normalize(val));
    } else { // 1.0 > abs(v) >= 0.0
      len = encodeNumericSmall(dst, normalize(val));
    }
    ord.apply(dst.getBytes(), offset + start, len);
    return len;
  }
Encode a numerical value using the variable-length encoding. If the number of significant
digits of the value exceeds the {@link OrderedBytes#MAX_PRECISION}, the exceeding part will be
lost.
@param dst The destination to which encoded digits are written.
@param val The value to encode.
@param ord The {@link Order} to respect while encoding {@code val}.
@return the number of bytes written.
hbase-common/src/main/java/org/apache/hadoop/hbase/util/OrderedBytes.java