From eb04676f43499e02c0280cd7ad668033dfeb23dd Mon Sep 17 00:00:00 2001 From: goldenMetteyya Date: Thu, 10 Jan 2019 12:26:53 +0300 Subject: [PATCH] Update inv.rs --- src/ops/inv.rs | 12 ++++++++++++ 1 file changed, 12 insertions(+) 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; +}