On Saturday, 2 July 2016 at 20:17:59 UTC, Andrei Alexandrescu
wrote:
So what's the fastest way to figure that an integral is
convertible to a floating point value precisely (i.e. no other
integral converts to the same floating point value)? Thanks! --
Andrei
If it is within what the mantissa can represent then it is easy.
But you also have to consider the cases where the mantissa is
shifted.
So the real answer is:
n is an unsigned 64 bit integer
mbits = representation bits for mantissa +1
tz = trailing_zero_bits(n)
lz = leading_zero_bits(n)
assert(mbits >= (64 - tz - lz))