Update inv.rs

This commit is contained in:
goldenMetteyya 2019-01-10 12:26:53 +03:00 committed by GitHub
parent d668985fae
commit eb04676f43
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 12 additions and 0 deletions

View File

@ -45,3 +45,15 @@ impl<'a> Inv for &'a f64 {
1.0 / *self
}
}
/// Generic trait to implement modular inverse
pub trait ModInverse<R: Sized>: 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<Self>;
}