lexical_util::div128

Function pow2_u128_divrem

Source
pub const fn pow2_u128_divrem(n: u128, mask: u64, shr: u32) -> (u128, u64)
Expand description

Calculate a div/remainder algorithm optimized for power-of-two radixes.

This is trivial: the number of digits we process is 64 / log2(radix). Therefore, the shr is log2(radix) * digits, and the mask is just the lower shr bits of the digits.