Be a little bit more careful about what items we do and don't include, start adding modular math into the system.
This commit is contained in:
16
src/unsigned/modmul.rs
Normal file
16
src/unsigned/modmul.rs
Normal file
@@ -0,0 +1,16 @@
|
||||
pub trait ModMul<T> {
|
||||
fn modmul(&self, x: &Self, m: &T) -> Self;
|
||||
}
|
||||
|
||||
macro_rules! modmul_impls {
|
||||
($name: ident, $dbl: ident) => {
|
||||
impl ModMul<$name> for $name {
|
||||
fn modmul(&self, x: &$name, m: &$name) -> $name {
|
||||
let mulres = (self as &$name) * x;
|
||||
let bigm = $dbl::from(m);
|
||||
let (_, bigres) = mulres.divmod(&bigm);
|
||||
$name::from(bigres)
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user