A Long encoded version of MaybeDouble, geared for unboxed speed. This
is significantly less accurate, but may provide good speed gains in common
cases.
The values approx and measure are both truncated floats with the full
8 bit exponent, but only 16 bit mantissa. Since the measure is always
positive, we only need 2 * (16 + 8) + 1 = 49 bits for these 2 numbers,
which leaves 15 bits for the index. These sizes were chosen so that
worst case relative error, ind * eps, has a value less than 1. In our
case, with worst case ind = -1 >>> 17, we have ind * eps =~ 0.5.
This was inspired by Erik Osheim's awesome FastComplex, which encodes the
imaginary and real parts as 2 Floats in the a single Long.
TODO: Perhaps, if we've only used + or *, we could store a higher precision
float instead, since we don't need measure. Use 1 bit to handle the
switching, taken from the index.
A
Long
encoded version ofMaybeDouble
, geared for unboxed speed. This is significantly less accurate, but may provide good speed gains in common cases.The values
approx
andmeasure
are both truncated floats with the full 8 bit exponent, but only 16 bit mantissa. Since themeasure
is always positive, we only need2 * (16 + 8) + 1 = 49
bits for these 2 numbers, which leaves 15 bits for theindex
. These sizes were chosen so that worst case relative error,ind * eps
, has a value less than 1. In our case, with worst caseind = -1 >>> 17
, we haveind * eps =~ 0.5
.This was inspired by Erik Osheim's awesome FastComplex, which encodes the imaginary and real parts as 2
Float
s in the a singleLong
.TODO: Perhaps, if we've only used + or *, we could store a higher precision float instead, since we don't need measure. Use 1 bit to handle the switching, taken from the index.