Optimize and fix encoding of similarity values

The previous code was a bit unclear as it extracted the LSB of the
exponent as part of the mantissa. This did actually work because
exponent and mantissa were stored next to each other like in the IEEE
format. For the same reason, the code can be optimized to use a single
shift and mask operation. The actual encoding does not change.

More importantly, this commit fixes a bug where, due to a missing range
check, values smaller than 2^-31 were encoded as 255 and subsequently
decoded as approximately 2^31. Such small values are probably rare but
this could cause significant errors when calculating similarities.
3 files changed