any number
the last power of two before val
assert(truncPow2(3) == 2); assert(truncPow2(4) == 4); assert(truncPow2(10) == 8); assert(truncPow2(4000) == 2048); assert(truncPow2(-5) == -4); assert(truncPow2(-20) == -16); assert(truncPow2(uint.max) == int.max + 1); assert(truncPow2(uint.min) == 0); assert(truncPow2(ulong.max) == long.max + 1); assert(truncPow2(ulong.min) == 0); assert(truncPow2(int.max) == (int.max / 2) + 1); version (LDC) { // this test relies on undefined behaviour, i.e. (1 << 63) == int.min // that fails for LDC with optimizations enabled } else { assert(truncPow2(int.min) == int.min); } assert(truncPow2(long.max) == (long.max / 2) + 1); assert(truncPow2(long.min) == long.min);
assert(truncPow2(2.1) == 2.0); assert(truncPow2(7.0) == 4.0); assert(truncPow2(-1.9) == -1.0); assert(truncPow2(0.24) == 0.125); assert(truncPow2(-7.0) == -4.0); assert(truncPow2(double.infinity) == double.infinity);
Gives the last power of two before val. $(T) can be any built-in numerical type.