1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
//! Schoolbook modular arithmetic with reference-based parameters
//! throughout — `Clone`, never `Copy`, so heap-allocated bigints
//! qualify.
//!
//! Uses `OverflowingAdd` / `OverflowingSub` rather than
//! `WrappingAdd` / `WrappingSub`, the strictest bound profile in the
//! toolbox. Suitable for backends that don't wrap on overflow —
//! arbitrary-precision types have no modulus-2^k to wrap at, but can
//! report overflow against a fixed working width.
//!
//! See [`modmath::basic`](crate::basic) (`Copy`-bound, simplest) and
//! [`modmath::constrained`](crate::constrained) (`Clone`-bound, mixed
//! value/reference) for less strict surfaces.
//!
//! ## Pre-reduced variants
//!
//! [`pre_reduced`] re-exports `add` / `sub` / `mul` / `exp` siblings that
//! assume inputs are already in `[0, m)` and skip the `% m` reduction
//! step. Works for backends without `core::ops::Rem` and is the right
//! entry point inside loops where reduction is handled separately.
//! Note: `inv` has no pre-reduced sibling — modular inverse via the
//! extended Euclidean algorithm inside `inv` performs its own
//! magnitude-dependent loop, with no useful "pre-reduced" shortcut.
pub use cratestrict_mod_add as add;
pub use cratestrict_mod_exp as exp;
pub use cratestrict_mod_inv as inv;
pub use cratestrict_mod_mul as mul;
pub use cratestrict_mod_sub as sub;
/// Pre-reduced variants. Caller guarantees inputs are in `[0, m)`;
/// no `Rem`-family bound.
/// Non-zero-modulus variants. See [`basic::nonzero`](crate::basic::nonzero).