openethereum/util/src/math.rs

12 lines
183 B
Rust
Raw Normal View History

2016-02-01 15:22:42 +01:00
//! Common math functions.
/// Returns 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
}