Skip to main content

ModPowerOf2

Trait ModPowerOf2 

Source
pub trait ModPowerOf2 {
    type Output;

    // Required method
    fn mod_power_of_2(self, other: u64) -> Self::Output;
}
Expand description

Divides a number by $2^k$, returning just the remainder. The remainder is non-negative.

If the quotient were computed, the quotient and remainder would satisfy $x = q2^k + r$ and $0 \leq r < 2^k$.

Required Associated Types§

Required Methods§

Source

fn mod_power_of_2(self, other: u64) -> Self::Output

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementations on Foreign Types§

Source§

impl ModPowerOf2 for i8

Source§

fn mod_power_of_2(self, pow: u64) -> u8

Divides a number by $2^k$, returning just the remainder. The remainder is non-negative.

If the quotient were computed, the quotient and remainder would satisfy $x = q2^k + r$ and $0 \leq r < 2^k$.

$$ f(x, k) = x - 2^k\left \lfloor \frac{x}{2^k} \right \rfloor. $$

§Worst-case complexity

Constant time and additional memory.

§Panics

Panics if self is negative and pow is greater than Self::WIDTH.

§Examples

See here.

Source§

type Output = u8

Source§

impl ModPowerOf2 for i16

Source§

fn mod_power_of_2(self, pow: u64) -> u16

Divides a number by $2^k$, returning just the remainder. The remainder is non-negative.

If the quotient were computed, the quotient and remainder would satisfy $x = q2^k + r$ and $0 \leq r < 2^k$.

$$ f(x, k) = x - 2^k\left \lfloor \frac{x}{2^k} \right \rfloor. $$

§Worst-case complexity

Constant time and additional memory.

§Panics

Panics if self is negative and pow is greater than Self::WIDTH.

§Examples

See here.

Source§

type Output = u16

Source§

impl ModPowerOf2 for i32

Source§

fn mod_power_of_2(self, pow: u64) -> u32

Divides a number by $2^k$, returning just the remainder. The remainder is non-negative.

If the quotient were computed, the quotient and remainder would satisfy $x = q2^k + r$ and $0 \leq r < 2^k$.

$$ f(x, k) = x - 2^k\left \lfloor \frac{x}{2^k} \right \rfloor. $$

§Worst-case complexity

Constant time and additional memory.

§Panics

Panics if self is negative and pow is greater than Self::WIDTH.

§Examples

See here.

Source§

type Output = u32

Source§

impl ModPowerOf2 for i64

Source§

fn mod_power_of_2(self, pow: u64) -> u64

Divides a number by $2^k$, returning just the remainder. The remainder is non-negative.

If the quotient were computed, the quotient and remainder would satisfy $x = q2^k + r$ and $0 \leq r < 2^k$.

$$ f(x, k) = x - 2^k\left \lfloor \frac{x}{2^k} \right \rfloor. $$

§Worst-case complexity

Constant time and additional memory.

§Panics

Panics if self is negative and pow is greater than Self::WIDTH.

§Examples

See here.

Source§

type Output = u64

Source§

impl ModPowerOf2 for i128

Source§

fn mod_power_of_2(self, pow: u64) -> u128

Divides a number by $2^k$, returning just the remainder. The remainder is non-negative.

If the quotient were computed, the quotient and remainder would satisfy $x = q2^k + r$ and $0 \leq r < 2^k$.

$$ f(x, k) = x - 2^k\left \lfloor \frac{x}{2^k} \right \rfloor. $$

§Worst-case complexity

Constant time and additional memory.

§Panics

Panics if self is negative and pow is greater than Self::WIDTH.

§Examples

See here.

Source§

type Output = u128

Source§

impl ModPowerOf2 for isize

Source§

fn mod_power_of_2(self, pow: u64) -> usize

Divides a number by $2^k$, returning just the remainder. The remainder is non-negative.

If the quotient were computed, the quotient and remainder would satisfy $x = q2^k + r$ and $0 \leq r < 2^k$.

$$ f(x, k) = x - 2^k\left \lfloor \frac{x}{2^k} \right \rfloor. $$

§Worst-case complexity

Constant time and additional memory.

§Panics

Panics if self is negative and pow is greater than Self::WIDTH.

§Examples

See here.

Source§

type Output = usize

Source§

impl ModPowerOf2 for u8

Source§

fn mod_power_of_2(self, pow: u64) -> u8

Divides a number by $2^k$, returning just the remainder.

If the quotient were computed, the quotient and remainder would satisfy $x = q2^k + r$ and $0 \leq r < 2^k$.

$$ f(x, k) = x - 2^k\left \lfloor \frac{x}{2^k} \right \rfloor. $$

§Worst-case complexity

Constant time and additional memory.

§Examples

See here.

Source§

type Output = u8

Source§

impl ModPowerOf2 for u16

Source§

fn mod_power_of_2(self, pow: u64) -> u16

Divides a number by $2^k$, returning just the remainder.

If the quotient were computed, the quotient and remainder would satisfy $x = q2^k + r$ and $0 \leq r < 2^k$.

$$ f(x, k) = x - 2^k\left \lfloor \frac{x}{2^k} \right \rfloor. $$

§Worst-case complexity

Constant time and additional memory.

§Examples

See here.

Source§

type Output = u16

Source§

impl ModPowerOf2 for u32

Source§

fn mod_power_of_2(self, pow: u64) -> u32

Divides a number by $2^k$, returning just the remainder.

If the quotient were computed, the quotient and remainder would satisfy $x = q2^k + r$ and $0 \leq r < 2^k$.

$$ f(x, k) = x - 2^k\left \lfloor \frac{x}{2^k} \right \rfloor. $$

§Worst-case complexity

Constant time and additional memory.

§Examples

See here.

Source§

type Output = u32

Source§

impl ModPowerOf2 for u64

Source§

fn mod_power_of_2(self, pow: u64) -> u64

Divides a number by $2^k$, returning just the remainder.

If the quotient were computed, the quotient and remainder would satisfy $x = q2^k + r$ and $0 \leq r < 2^k$.

$$ f(x, k) = x - 2^k\left \lfloor \frac{x}{2^k} \right \rfloor. $$

§Worst-case complexity

Constant time and additional memory.

§Examples

See here.

Source§

type Output = u64

Source§

impl ModPowerOf2 for u128

Source§

fn mod_power_of_2(self, pow: u64) -> u128

Divides a number by $2^k$, returning just the remainder.

If the quotient were computed, the quotient and remainder would satisfy $x = q2^k + r$ and $0 \leq r < 2^k$.

$$ f(x, k) = x - 2^k\left \lfloor \frac{x}{2^k} \right \rfloor. $$

§Worst-case complexity

Constant time and additional memory.

§Examples

See here.

Source§

type Output = u128

Source§

impl ModPowerOf2 for usize

Source§

fn mod_power_of_2(self, pow: u64) -> usize

Divides a number by $2^k$, returning just the remainder.

If the quotient were computed, the quotient and remainder would satisfy $x = q2^k + r$ and $0 \leq r < 2^k$.

$$ f(x, k) = x - 2^k\left \lfloor \frac{x}{2^k} \right \rfloor. $$

§Worst-case complexity

Constant time and additional memory.

§Examples

See here.

Source§

type Output = usize

Implementors§