Struct bare_metal_modulo::ModNum
source · pub struct ModNum<N> { /* private fields */ }
Expand description
Represents an integer a (mod m)
Implementations§
source§impl<N: NumType + Signed> ModNum<N>
impl<N: NumType + Signed> ModNum<N>
sourcepub fn chinese_remainder(&self, other: ModNum<N>) -> ModNum<N>
pub fn chinese_remainder(&self, other: ModNum<N>) -> ModNum<N>
Solves a pair of modular equations using the Chinese Remainder Theorem.
This is my translation into Rust of Brent Yorgey’s Haskell implementation.
self
represents the modular equation x = a (mod m)other
represents the modular equation x = b (mod n)- It returns a
ModNum
corresponding to the equation x = c (mod mn) where c is congruent both to a (mod m) and b (mod n)
sourcepub fn chinese_remainder_system<I: Iterator<Item = ModNum<N>>>(
modnums: I
) -> Option<ModNum<N>>
pub fn chinese_remainder_system<I: Iterator<Item = ModNum<N>>>( modnums: I ) -> Option<ModNum<N>>
Solves a system of modular equations using ModMum::chinese_remainder()
.
Each equation in the system is an element of the modnums iterator parameter.
- Returns None if the iterator is empty.
- Returns Some(element) if the iterator has only one element.
- Returns Some(solution) if the iterator has two or more elements, where the solution is found by repeatedly calling ModNum::chinese_remainder().
Trait Implementations§
source§impl<N: NumType> AddAssign<ModNum<N>> for ModNum<N>
impl<N: NumType> AddAssign<ModNum<N>> for ModNum<N>
source§fn add_assign(&mut self, rhs: ModNum<N>)
fn add_assign(&mut self, rhs: ModNum<N>)
Performs the
+=
operation. Read moresource§impl<N: NumType> AddAssign<N> for ModNum<N>
impl<N: NumType> AddAssign<N> for ModNum<N>
source§fn add_assign(&mut self, rhs: N)
fn add_assign(&mut self, rhs: N)
Performs the
+=
operation. Read moresource§impl<N: NumType + Signed> DivAssign<ModNum<N>> for ModNum<N>
impl<N: NumType + Signed> DivAssign<ModNum<N>> for ModNum<N>
source§fn div_assign(&mut self, rhs: ModNum<N>)
fn div_assign(&mut self, rhs: ModNum<N>)
Performs the
/=
operation. Read moresource§impl<N: NumType + Signed> DivAssign<N> for ModNum<N>
impl<N: NumType + Signed> DivAssign<N> for ModNum<N>
source§fn div_assign(&mut self, rhs: N)
fn div_assign(&mut self, rhs: N)
Performs the
/=
operation. Read moresource§impl<N: NumType> MulAssign<ModNum<N>> for ModNum<N>
impl<N: NumType> MulAssign<ModNum<N>> for ModNum<N>
source§fn mul_assign(&mut self, rhs: ModNum<N>)
fn mul_assign(&mut self, rhs: ModNum<N>)
Performs the
*=
operation. Read moresource§impl<N: NumType> MulAssign<N> for ModNum<N>
impl<N: NumType> MulAssign<N> for ModNum<N>
source§fn mul_assign(&mut self, rhs: N)
fn mul_assign(&mut self, rhs: N)
Performs the
*=
operation. Read moresource§impl<N: Ord> Ord for ModNum<N>
impl<N: Ord> Ord for ModNum<N>
source§impl<N: PartialEq> PartialEq<ModNum<N>> for ModNum<N>
impl<N: PartialEq> PartialEq<ModNum<N>> for ModNum<N>
source§impl<N: NumType> PartialEq<N> for ModNum<N>
impl<N: NumType> PartialEq<N> for ModNum<N>
Returns true if other is congruent to self.a() (mod self.m())
source§impl<N: PartialOrd> PartialOrd<ModNum<N>> for ModNum<N>
impl<N: PartialOrd> PartialOrd<ModNum<N>> for ModNum<N>
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
This method tests less than or equal to (for
self
and other
) and is used by the <=
operator. Read moresource§impl<N: NumType> PartialOrd<N> for ModNum<N>
impl<N: NumType> PartialOrd<N> for ModNum<N>
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
This method tests less than or equal to (for
self
and other
) and is used by the <=
operator. Read moresource§impl<N: NumType> SaturatingAdd for ModNum<N>
impl<N: NumType> SaturatingAdd for ModNum<N>
source§fn saturating_add(&self, v: &Self) -> Self
fn saturating_add(&self, v: &Self) -> Self
Saturating addition. Computes
self + other
, saturating at the relevant high or low boundary of
the type.source§impl<N: NumType> SaturatingSub for ModNum<N>
impl<N: NumType> SaturatingSub for ModNum<N>
source§fn saturating_sub(&self, v: &Self) -> Self
fn saturating_sub(&self, v: &Self) -> Self
Saturating subtraction. Computes
self - other
, saturating at the relevant high or low boundary of
the type.source§impl<N: NumType> SubAssign<ModNum<N>> for ModNum<N>
impl<N: NumType> SubAssign<ModNum<N>> for ModNum<N>
source§fn sub_assign(&mut self, rhs: ModNum<N>)
fn sub_assign(&mut self, rhs: ModNum<N>)
Performs the
-=
operation. Read moresource§impl<N: NumType> SubAssign<N> for ModNum<N>
impl<N: NumType> SubAssign<N> for ModNum<N>
source§fn sub_assign(&mut self, rhs: N)
fn sub_assign(&mut self, rhs: N)
Performs the
-=
operation. Read more