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§
fn mod_power_of_2(self, other: u64) -> Self::Output
Implementations on Foreign Types§
Source§impl ModPowerOf2 for i8
impl ModPowerOf2 for i8
Source§fn mod_power_of_2(self, pow: u64) -> u8
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.
type Output = u8
Source§impl ModPowerOf2 for i16
impl ModPowerOf2 for i16
Source§fn mod_power_of_2(self, pow: u64) -> u16
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.
type Output = u16
Source§impl ModPowerOf2 for i32
impl ModPowerOf2 for i32
Source§fn mod_power_of_2(self, pow: u64) -> u32
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.
type Output = u32
Source§impl ModPowerOf2 for i64
impl ModPowerOf2 for i64
Source§fn mod_power_of_2(self, pow: u64) -> u64
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.
type Output = u64
Source§impl ModPowerOf2 for i128
impl ModPowerOf2 for i128
Source§fn mod_power_of_2(self, pow: u64) -> u128
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.
type Output = u128
Source§impl ModPowerOf2 for isize
impl ModPowerOf2 for isize
Source§fn mod_power_of_2(self, pow: u64) -> usize
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.
type Output = usize
Source§impl ModPowerOf2 for u8
impl ModPowerOf2 for u8
Source§fn mod_power_of_2(self, pow: u64) -> u8
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.
type Output = u8
Source§impl ModPowerOf2 for u16
impl ModPowerOf2 for u16
Source§fn mod_power_of_2(self, pow: u64) -> u16
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.
type Output = u16
Source§impl ModPowerOf2 for u32
impl ModPowerOf2 for u32
Source§fn mod_power_of_2(self, pow: u64) -> u32
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.
type Output = u32
Source§impl ModPowerOf2 for u64
impl ModPowerOf2 for u64
Source§fn mod_power_of_2(self, pow: u64) -> u64
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.
type Output = u64
Source§impl ModPowerOf2 for u128
impl ModPowerOf2 for u128
Source§fn mod_power_of_2(self, pow: u64) -> u128
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.
type Output = u128
Source§impl ModPowerOf2 for usize
impl ModPowerOf2 for usize
Source§fn mod_power_of_2(self, pow: u64) -> usize
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.