lexical_util::div128

Function u128_divrem

Source
pub fn u128_divrem(n: u128, radix: u32) -> (u128, u64)
Expand description

Calculate the div/remainder of a value based on the radix.

This uses the largest divisor possible for the given size, and uses various fast-path approximations for different types.

  1. Powers-of-two can be cleanly split into 2 64-bit products.
  2. Division that can be simulated as if by multiplication by a constant.
  3. Cases of 2. with a power-of-two divisor.
  4. Fallback cases.

This returns the quotient and the remainder. For the number of digits processed, see min_step.