calyx_utils/
math.rs

1use std::cmp;
2
3fn bits_helper(n: u64, i: u64) -> u64 {
4    if n == 0 { i } else { bits_helper(n / 2, i + 1) }
5}
6
7/// Number of bits needed to represent a number.
8pub fn bits_needed_for(n: u64) -> u64 {
9    cmp::max(bits_helper(n - 1, 0), 1)
10}