pub trait ModPowerOf2Inverse {
    type Output;

    // Required method
    fn mod_power_of_2_inverse(self, pow: u64) -> Option<Self::Output>;
}
Expand description

Finds the multiplicative inverse of a number modulo $2^k$. The input must be already reduced modulo $2^k$.

Required Associated Types§

Required Methods§

Implementations on Foreign Types§

source§

impl ModPowerOf2Inverse for u8

source§

fn mod_power_of_2_inverse(self, pow: u64) -> Option<u8>

Computes the multiplicative inverse of a number modulo $2^k$. The input must be already reduced modulo $2^k$.

Returns None if $x$ is even.

$f(x, k) = y$, where $x, y < 2^k$, $x$ is odd, and $xy \equiv 1 \mod 2^k$.

§Worst-case complexity

$T(n) = O(n)$

$M(n) = O(1)$

where $T$ is time, $M$ is additional memory, and $n$ is pow.

§Panics

Panics if pow is greater than Self::WIDTH, if self is zero, or if self is greater than or equal to $2^k$.

§Examples

See here.

§

type Output = u8

source§

impl ModPowerOf2Inverse for u16

source§

fn mod_power_of_2_inverse(self, pow: u64) -> Option<u16>

Computes the multiplicative inverse of a number modulo $2^k$. The input must be already reduced modulo $2^k$.

Returns None if $x$ is even.

$f(x, k) = y$, where $x, y < 2^k$, $x$ is odd, and $xy \equiv 1 \mod 2^k$.

§Worst-case complexity

$T(n) = O(n)$

$M(n) = O(1)$

where $T$ is time, $M$ is additional memory, and $n$ is pow.

§Panics

Panics if pow is greater than Self::WIDTH, if self is zero, or if self is greater than or equal to $2^k$.

§Examples

See here.

§

type Output = u16

source§

impl ModPowerOf2Inverse for u32

source§

fn mod_power_of_2_inverse(self, pow: u64) -> Option<u32>

Computes the multiplicative inverse of a number modulo $2^k$. The input must be already reduced modulo $2^k$.

Returns None if $x$ is even.

$f(x, k) = y$, where $x, y < 2^k$, $x$ is odd, and $xy \equiv 1 \mod 2^k$.

§Worst-case complexity

$T(n) = O(n)$

$M(n) = O(1)$

where $T$ is time, $M$ is additional memory, and $n$ is pow.

§Panics

Panics if pow is greater than Self::WIDTH, if self is zero, or if self is greater than or equal to $2^k$.

§Examples

See here.

§

type Output = u32

source§

impl ModPowerOf2Inverse for u64

source§

fn mod_power_of_2_inverse(self, pow: u64) -> Option<u64>

Computes the multiplicative inverse of a number modulo $2^k$. The input must be already reduced modulo $2^k$.

Returns None if $x$ is even.

$f(x, k) = y$, where $x, y < 2^k$, $x$ is odd, and $xy \equiv 1 \mod 2^k$.

§Worst-case complexity

$T(n) = O(n)$

$M(n) = O(1)$

where $T$ is time, $M$ is additional memory, and $n$ is pow.

§Panics

Panics if pow is greater than Self::WIDTH, if self is zero, or if self is greater than or equal to $2^k$.

§Examples

See here.

§

type Output = u64

source§

impl ModPowerOf2Inverse for u128

source§

fn mod_power_of_2_inverse(self, pow: u64) -> Option<u128>

Computes the multiplicative inverse of a number modulo $2^k$. The input must be already reduced modulo $2^k$.

Returns None if $x$ is even.

$f(x, k) = y$, where $x, y < 2^k$, $x$ is odd, and $xy \equiv 1 \mod 2^k$.

§Worst-case complexity

$T(n) = O(n)$

$M(n) = O(1)$

where $T$ is time, $M$ is additional memory, and $n$ is pow.

§Panics

Panics if pow is greater than Self::WIDTH, if self is zero, or if self is greater than or equal to $2^k$.

§Examples

See here.

§

type Output = u128

source§

impl ModPowerOf2Inverse for usize

source§

fn mod_power_of_2_inverse(self, pow: u64) -> Option<usize>

Computes the multiplicative inverse of a number modulo $2^k$. The input must be already reduced modulo $2^k$.

Returns None if $x$ is even.

$f(x, k) = y$, where $x, y < 2^k$, $x$ is odd, and $xy \equiv 1 \mod 2^k$.

§Worst-case complexity

$T(n) = O(n)$

$M(n) = O(1)$

where $T$ is time, $M$ is additional memory, and $n$ is pow.

§Panics

Panics if pow is greater than Self::WIDTH, if self is zero, or if self is greater than or equal to $2^k$.

§Examples

See here.

§

type Output = usize

Implementors§