Function modulo_n_tools::add_mod [−][src]
pub fn add_mod<T>(a: &T, b: &T, modulo: &T) -> T where
T: Ord + for<'x> AddAssign<&'x T> + for<'x> SubAssign<&'x T>,
for<'x> &'x T: Add<Output = T> + Neg<Output = T>,
Expand description
$a + b \bmod n
$
Input: $-\text{modulo} \leq a,\, b \leq \text{modulo}
$
Output: $-\text{modulo} \leq x \leq \text{modulo}
$
use modulo_n_tools::add_mod; assert_eq!(add_mod(&3, &4, &5), 2); assert_eq!(add_mod(&2, &5, &6), 1); assert_eq!(add_mod(&-3, &-2, &4), -1); assert_eq!(add_mod(&2, &3, &5), 0);