Trait malachite_base::num::arithmetic::traits::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§
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.