[−][src]Trait modular::Modular
Trait for modular operations on integers
Implementing this trait allows for conversion of integers to modular numbers, as well as determining congruence relations between integers.
Required methods
fn to_modulo(self, modulus: u32) -> Modulo
Returns the modular representation of an integer
This is the idiomatic way of creating a new modulo number. Alternatively, the modulo!
macro is provided, which provides the same functionality.
fn is_congruent(
self,
with: impl Into<i32>,
modulus: u32
) -> bool
self,
with: impl Into<i32>,
modulus: u32
) -> bool
Returns true if the two integers are congruent modulo n
Congruence is determined by the relation:
a === b (mod n) if a - b = kn where k is some integer.
Example
// Given some integers let a = 27; let b = 91; let c = -1; // Assert their congruence for different modulus values assert_eq!(a.is_congruent(b, 4), true); // True: 27 - 91 = -64 => n = 4, k = -16 assert_eq!(b.is_congruent(a, 5), false); // False: 91 - 27 = 64 => n = 5, k = 12.8 assert_eq!(a.is_congruent(c, 4), true); // True: 27 - -1 = 28 => n = 4, k = 7
Implementations on Foreign Types
impl Modular for i32
[src]
fn to_modulo(self, modulus: u32) -> Modulo
[src]
fn is_congruent(
self,
with: impl Into<i32>,
modulus: u32
) -> bool
[src]
self,
with: impl Into<i32>,
modulus: u32
) -> bool