From eb04676f43499e02c0280cd7ad668033dfeb23dd Mon Sep 17 00:00:00 2001 From: goldenMetteyya Date: Thu, 10 Jan 2019 12:26:53 +0300 Subject: [PATCH 1/2] 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 7087d09d..7f4eda6c 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; +} From 96a4a5f7cc219aedf14cff8e63da5a3f737182ac Mon Sep 17 00:00:00 2001 From: goldenMetteyya Date: Thu, 10 Jan 2019 12:27:27 +0300 Subject: [PATCH 2/2] Update lib.rs --- src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index 5a25bab4..02856912 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -36,7 +36,7 @@ pub use int::PrimInt; pub use ops::checked::{ CheckedAdd, CheckedDiv, CheckedMul, CheckedNeg, CheckedRem, CheckedShl, CheckedShr, CheckedSub, }; -pub use ops::inv::Inv; +pub use ops::inv::{Inv, ModInverse}; pub use ops::mul_add::{MulAdd, MulAddAssign}; pub use ops::saturating::Saturating; pub use ops::wrapping::{WrappingAdd, WrappingMul, WrappingShl, WrappingShr, WrappingSub};