pub trait ModularUnaryOps<Modulus = Self> {
    type Output;

    // Required methods
    fn negm(self, m: Modulus) -> Self::Output;
    fn invm(self, m: Modulus) -> Option<Self::Output>;
    fn dblm(self, m: Modulus) -> Self::Output;
    fn sqm(self, m: Modulus) -> Self::Output;
}
Expand description

Core unary modular arithmetics

Note that all functions will panic if the modulus is zero.

Required Associated Types§

Required Methods§

source

fn negm(self, m: Modulus) -> Self::Output

Return (-self) % m and make sure the result is normalized in range [0,m)

source

fn invm(self, m: Modulus) -> Option<Self::Output>

Calculate modular inverse (x such that self*x = 1 mod m).

This operation is only available for integer that is coprime to m. If not, the result will be None.

source

fn dblm(self, m: Modulus) -> Self::Output

Calculate modular double ( x+x mod m)

source

fn sqm(self, m: Modulus) -> Self::Output

Calculate modular square ( x*x mod m )

Implementations on Foreign Types§

source§

impl ModularUnaryOps<&u32> for u32

§

type Output = u32

source§

fn negm(self, m: &u32) -> u32

source§

fn invm(self, m: &u32) -> Option<u32>

source§

fn dblm(self, m: &u32) -> u32

source§

fn sqm(self, m: &u32) -> u32

source§

impl ModularUnaryOps<&u64> for u64

§

type Output = u64

source§

fn negm(self, m: &u64) -> u64

source§

fn invm(self, m: &u64) -> Option<u64>

source§

fn dblm(self, m: &u64) -> u64

source§

fn sqm(self, m: &u64) -> u64

source§

impl ModularUnaryOps<&u8> for u8

§

type Output = u8

source§

fn negm(self, m: &u8) -> u8

source§

fn invm(self, m: &u8) -> Option<u8>

source§

fn dblm(self, m: &u8) -> u8

source§

fn sqm(self, m: &u8) -> u8

source§

impl ModularUnaryOps<&u128> for &u128

§

type Output = u128

source§

fn negm(self, m: &u128) -> u128

source§

fn invm(self, m: &u128) -> Option<u128>

source§

fn dblm(self, m: &u128) -> u128

source§

fn sqm(self, m: &u128) -> u128

source§

impl ModularUnaryOps<&u128> for u128

§

type Output = u128

source§

fn negm(self, m: &u128) -> u128

source§

fn invm(self, m: &u128) -> Option<u128>

source§

fn dblm(self, m: &u128) -> u128

source§

fn sqm(self, m: &u128) -> u128

source§

impl ModularUnaryOps<&u64> for &u64

§

type Output = u64

source§

fn negm(self, m: &u64) -> u64

source§

fn invm(self, m: &u64) -> Option<u64>

source§

fn dblm(self, m: &u64) -> u64

source§

fn sqm(self, m: &u64) -> u64

source§

impl ModularUnaryOps<&u16> for u16

§

type Output = u16

source§

fn negm(self, m: &u16) -> u16

source§

fn invm(self, m: &u16) -> Option<u16>

source§

fn dblm(self, m: &u16) -> u16

source§

fn sqm(self, m: &u16) -> u16

source§

impl ModularUnaryOps<&u32> for &u32

§

type Output = u32

source§

fn negm(self, m: &u32) -> u32

source§

fn invm(self, m: &u32) -> Option<u32>

source§

fn dblm(self, m: &u32) -> u32

source§

fn sqm(self, m: &u32) -> u32

source§

impl ModularUnaryOps<&u8> for &u8

§

type Output = u8

source§

fn negm(self, m: &u8) -> u8

source§

fn invm(self, m: &u8) -> Option<u8>

source§

fn dblm(self, m: &u8) -> u8

source§

fn sqm(self, m: &u8) -> u8

source§

impl ModularUnaryOps<&usize> for &usize

§

type Output = usize

source§

fn negm(self, m: &usize) -> usize

source§

fn invm(self, m: &usize) -> Option<usize>

source§

fn dblm(self, m: &usize) -> usize

source§

fn sqm(self, m: &usize) -> usize

source§

impl ModularUnaryOps<&u16> for &u16

§

type Output = u16

source§

fn negm(self, m: &u16) -> u16

source§

fn invm(self, m: &u16) -> Option<u16>

source§

fn dblm(self, m: &u16) -> u16

source§

fn sqm(self, m: &u16) -> u16

source§

impl ModularUnaryOps<&BigUint> for BigUint

§

type Output = BigUint

source§

fn negm(self, m: &BigUint) -> BigUint

source§

fn invm(self, m: &BigUint) -> Option<BigUint>

source§

fn dblm(self, m: &BigUint) -> BigUint

source§

fn sqm(self, m: &BigUint) -> BigUint

source§

impl ModularUnaryOps<&usize> for usize

§

type Output = usize

source§

fn negm(self, m: &usize) -> usize

source§

fn invm(self, m: &usize) -> Option<usize>

source§

fn dblm(self, m: &usize) -> usize

source§

fn sqm(self, m: &usize) -> usize

source§

impl ModularUnaryOps<&BigUint> for &BigUint

§

type Output = BigUint

source§

fn negm(self, m: &BigUint) -> BigUint

source§

fn invm(self, m: &BigUint) -> Option<Self::Output>

source§

fn dblm(self, m: &BigUint) -> BigUint

source§

fn sqm(self, m: &BigUint) -> BigUint

Implementors§