int nlz(unsigned k) { union { unsigned asInt[2]; double asDouble; }; asDouble = (double)k + 0.5; return 1054 - (asInt[LE] >> 20); }
20 + 32 == sizeof(double's mantissa)
1023 == exponent bias
1 (nlz == 31) = 00000000000000000000000000000001 = 1.0 * 2 ** 0 10000 (nlz == 18) = 00000000000000000010011100010000 = 1.220703125 * 2 ** 13
from Hacker's Delight
Linux kernel の IA64 むけのコードで実際つかわれてるらしい