dashu_int/modular/mod.rs
1//! Modular arithmetic.
2//!
3//! Modular arithmetic is performed on [Reduced] values attached to a [ConstDivisor][crate::div_const::ConstDivisor].
4//!
5//! Trying to mix different [ConstDivisor][crate::fast_div::ConstDivisor] instances (even with the same modulus!) will cause a panic.
6//!
7//! # Examples
8//!
9//! ```
10//! use dashu_int::{fast_div::ConstDivisor, UBig};
11//!
12//! let ring = ConstDivisor::new(UBig::from(10000u32));
13//! let x = ring.reduce(12345);
14//! let y = ring.reduce(55443);
15//! assert_eq!(format!("{}", x - y), "6902 (mod 10000)");
16//! ```
17
18pub use convert::IntoRing;
19pub use repr::Reduced;
20
21mod add;
22pub(crate) mod convert;
23mod div;
24mod fmt;
25mod mul;
26mod pow;
27mod reducer;
28pub(crate) mod repr;
29
30// TODO: Also support Montgomery form reductions, use relaxed form described
31// in https://cetinkayakoc.net/docs/j56.pdf and https://eprint.iacr.org/2011/239.pdf