Expand description

This crate performs fast division by a runtime constant divisor, by precomputing a division factor that can be used repeatedly.


use fastdiv::FastDiv;

let d: u32 = 3;
let m = d.precompute_div();

let n1 = 4;
let n2 = 9;

assert_eq!(n1 / d, n1.fast_div(m));
assert_eq!(n2 / d, n2.fast_div(m));

assert_eq!(n1 % d, n1.fast_mod(m, d));
assert_eq!(n2 % d, n2.fast_mod(m, d));

assert_eq!(n1 % d == 0, n1.is_multiple_of(m));
assert_eq!(n2 % d == 0, n2.is_multiple_of(m));



Allows precomputing the division factor for fast division, modulo, and divisibility checks.