diff --git a/src/ops/inv.rs b/src/ops/inv.rs index 7087d09..7f4eda6 100644 --- a/src/ops/inv.rs +++ b/src/ops/inv.rs @@ -45,3 +45,15 @@ impl<'a> Inv for &'a f64 { 1.0 / *self } } + + +/// Generic trait to implement modular inverse +pub trait ModInverse: Sized { + /// Function to calculate the [modular multiplicative + /// inverse](https://en.wikipedia.org/wiki/Modular_multiplicative_inverse) of an integer *a* modulo *m*. + /// + /// TODO: references + /// Returns the modular inverse of `self`. + /// If none exists it returns `None`. + fn mod_inverse(self, m: R) -> Option; +}