Second computes 2^31 * mantissa (0x80000000 comes from omitted 1 in mantissa).
-(e < 32) is -1 (or 0xFFFFFFFF) if exponent >=0 and 0 if exponent < 0.
So third line computes (2^31 * mantissa) >> (31 - exponent) = mantissa * 2^exponent if exponent >= 0 and zero otherwise.
For double it will be something like
uint64_t double_to_uint64(double x)
{
uint64_t y = *(uint64_t *)&x;
uint64_t e = 0x3FF + 63 - (y >> 52);
uint64_t m = 1 << 63 | y << 11;
return m >> e & -(e < 64);
}
Personally I prefer more black magic:
int32_t fast_round(float x)
{
x += 12582912;
return (*(int32_t *)&x ^ 0x4B000000) - 0x00400000;
}
but my tests show that simple (int)x will be fastest (at least under g++).













