Struct modular_math::ModMath
source · pub struct ModMath { /* private fields */ }Expand description
ModMath is a struct that provides modular arithmetic operations.
It operates on unsigned 256-bit integers (U256) and performs operations under a given modulus.
The modulus is provided when creating a new ModMath instance and cannot be zero.
Implementations§
source§impl ModMath
impl ModMath
pub fn modulus(&self, a: U256) -> U256
sourcepub fn sub(&self, a: U256, b: U256) -> U256
pub fn sub(&self, a: U256, b: U256) -> U256
Subtracts the second U256 number from the first one under the modulus.
sourcepub fn exp(&self, base: U256, exponent: U256) -> U256
pub fn exp(&self, base: U256, exponent: U256) -> U256
Raises the base to the power of the exponent under the modulus.
sourcepub fn inv(&self, a: U256) -> Option<U256>
pub fn inv(&self, a: U256) -> Option<U256>
Calculates the modular multiplicative inverse of a U256 number under the modulus.
Returns None if the inverse does not exist.
sourcepub fn div(&self, a: U256, b: U256) -> U256
pub fn div(&self, a: U256, b: U256) -> U256
Divides the first U256 number by the second one under the modulus.
§Panics
Panics if the second number is zero or if its inverse does not exist under the modulus.
sourcepub fn eq(&self, a: U256, b: U256) -> bool
pub fn eq(&self, a: U256, b: U256) -> bool
Checks if two U256 numbers are equivalent under the modulus.
pub fn sqrt(&self, a: U256) -> U256
Auto Trait Implementations§
impl Freeze for ModMath
impl RefUnwindSafe for ModMath
impl Send for ModMath
impl Sync for ModMath
impl Unpin for ModMath
impl UnwindSafe for ModMath
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