openethereum/src/math.rs
2015-11-28 17:08:38 +01:00

10 lines
146 B
Rust

/// log2
pub fn log2(x: usize) -> u32 {
if x <= 1 {
return 0;
}
let n = x.leading_zeros();
::std::mem::size_of::<usize>() as u32 * 8 - n
}