Simplification of BigNum::bit_length by swenson · Pull Request #92747 · rust-lang/rust (original) (raw)
(I'm new to this code, so let me know if I'm misunderstanding things. It took me a bit to figure out what was going on.)
I think this could be simplified further?
If I'm reading it right, I think this is something like
let digits = self.digits(); // Find the most significant non-zero digit let msd = digits.iter().rposition(|&x| x != 0); if let Some(msd) = msd { let digitbits = <$ty>::BITS as usize; msd * digitbits + digits[msd].log2() as usize } else { // There are no non-zero digits, i.e., the number is zero. return 0; }