Trait malachite_base::num::arithmetic::traits::ModPowerOf2
source · [−]pub trait ModPowerOf2 {
type Output;
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
sourceimpl ModPowerOf2 for u8
impl ModPowerOf2 for u8
sourcefn 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
sourceimpl ModPowerOf2 for u16
impl ModPowerOf2 for u16
sourcefn 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
sourceimpl ModPowerOf2 for u32
impl ModPowerOf2 for u32
sourcefn 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
sourceimpl ModPowerOf2 for u64
impl ModPowerOf2 for u64
sourcefn 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
sourceimpl ModPowerOf2 for u128
impl ModPowerOf2 for u128
sourcefn 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
sourceimpl ModPowerOf2 for usize
impl ModPowerOf2 for usize
sourcefn 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.
type Output = usize
sourceimpl ModPowerOf2 for i8
impl ModPowerOf2 for i8
sourcefn 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
sourceimpl ModPowerOf2 for i16
impl ModPowerOf2 for i16
sourcefn 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
sourceimpl ModPowerOf2 for i32
impl ModPowerOf2 for i32
sourcefn 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
sourceimpl ModPowerOf2 for i64
impl ModPowerOf2 for i64
sourcefn 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
sourceimpl ModPowerOf2 for i128
impl ModPowerOf2 for i128
sourcefn 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
sourceimpl ModPowerOf2 for isize
impl ModPowerOf2 for isize
sourcefn 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.