pub fn log2(n: usize) -> u32
Expand description
Returns base 2 logarithm of n
, where n
is a power of two.
Panics if n
is not a power of two.
assert_eq!(log2(1), 0);
assert_eq!(log2(16), 4);
assert_eq!(log2(1 << 20), 20);
assert_eq!(log2(2usize.pow(20)), 20);