pub struct Modulus32 { /* private fields */ }Implementations§
Source§impl Modulus32
impl Modulus32
Sourcepub const fn new(n: u32) -> Self
pub const fn new(n: u32) -> Self
Creates new instance with the given modulus.
§Panics
- modulus
nshould be an odd integer. - modulus
nshould be no more than2_654_435_769, which is the floor of2^32 / GOLDEN_RATIO.
§Example
use lib_modulo::Modulus32;
// odd integer less than or equal to 2_654_435_769 is allowed.
let modulus = Modulus32::new(Modulus32::MAX);
let modulus = Modulus32::new(3);
// modulus should be an odd integer!
assert!(std::panic::catch_unwind(|| { Modulus32::new(2); }).is_err())Sourcepub const fn residue(&self, x: u32) -> Residue32<'_>
pub const fn residue(&self, x: u32) -> Residue32<'_>
Calculates the residue of x modulo self.
§Example
use lib_modulo::Modulus32;
let modulus = Modulus32::new(5);
assert_eq!(modulus.residue(8).get(), 3)Sourcepub const fn can_divide(&self, x: u32) -> bool
pub const fn can_divide(&self, x: u32) -> bool
Checks whether x is divisible by self.
§Example
use lib_modulo::Modulus32;
let modulus = Modulus32::new(9);
assert!(modulus.can_divide(18));
assert!(!modulus.can_divide(19));Trait Implementations§
impl Eq for Modulus32
Auto Trait Implementations§
impl Freeze for Modulus32
impl RefUnwindSafe for Modulus32
impl Send for Modulus32
impl Sync for Modulus32
impl Unpin for Modulus32
impl UnsafeUnpin for Modulus32
impl UnwindSafe for Modulus32
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more