calyx_utils/
math.rs

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