strength_reduce

crate license documentation minimum rustc 1.26

Faster integer division and modulus operations.

strength_reduce uses arithmetic strength reduction to transform divisions into multiplications and shifts. This yields a 5x-10x speedup for integer division and modulo operations, with a small amortized setup cost.

Although this library can speed up any division or modulo operation, it's intended for hot loops like the example below, where a division is repeated hundreds of times in a loop, but the divisor remains unchanged.

See the API Documentation for more details.

Example

```rust use strength_reduce::StrengthReducedU64;

let mut my_array: Vec = (0..500).collect(); let divisor = 3; let modulo = 14;

// slow naive division and modulo for element in &mut my_array { element = (element / divisor) % modulo; }

// fast strength-reduced division and modulo let reduceddivisor = StrengthReducedU64::new(divisor); let reducedmodulo = StrengthReducedU64::new(modulo); for element in &mut myarray { *element = (*element / reduceddivisor) % reduced_modulo; } ```

Compatibility

The strength_reduce crate requires rustc 1.26 or greater.

License

Licensed under either of

at your option.