Trait malachite_base::num::arithmetic::traits::RemPowerOf2
source · pub trait RemPowerOf2 {
type Output;
// Required method
fn rem_power_of_2(self, other: u64) -> Self::Output;
}
Expand description
Divides a number by $2^k$, returning just the remainder. The remainder has the same sign as the number.
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 rem_power_of_2(self, other: u64) -> Self::Output
Implementations on Foreign Types§
source§impl RemPowerOf2 for i8
impl RemPowerOf2 for i8
source§fn rem_power_of_2(self, pow: u64) -> i8
fn rem_power_of_2(self, pow: u64) -> i8
Divides a number by $2^k$, returning just the remainder. The remainder has the same sign as the first number.
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\operatorname{sgn}(x)\left \lfloor \frac{|x|}{2^k} \right \rfloor. $$
§Worst-case complexity
Constant time and additional memory.
§Examples
See here.
type Output = i8
source§impl RemPowerOf2 for i16
impl RemPowerOf2 for i16
source§fn rem_power_of_2(self, pow: u64) -> i16
fn rem_power_of_2(self, pow: u64) -> i16
Divides a number by $2^k$, returning just the remainder. The remainder has the same sign as the first number.
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\operatorname{sgn}(x)\left \lfloor \frac{|x|}{2^k} \right \rfloor. $$
§Worst-case complexity
Constant time and additional memory.
§Examples
See here.
type Output = i16
source§impl RemPowerOf2 for i32
impl RemPowerOf2 for i32
source§fn rem_power_of_2(self, pow: u64) -> i32
fn rem_power_of_2(self, pow: u64) -> i32
Divides a number by $2^k$, returning just the remainder. The remainder has the same sign as the first number.
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\operatorname{sgn}(x)\left \lfloor \frac{|x|}{2^k} \right \rfloor. $$
§Worst-case complexity
Constant time and additional memory.
§Examples
See here.
type Output = i32
source§impl RemPowerOf2 for i64
impl RemPowerOf2 for i64
source§fn rem_power_of_2(self, pow: u64) -> i64
fn rem_power_of_2(self, pow: u64) -> i64
Divides a number by $2^k$, returning just the remainder. The remainder has the same sign as the first number.
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\operatorname{sgn}(x)\left \lfloor \frac{|x|}{2^k} \right \rfloor. $$
§Worst-case complexity
Constant time and additional memory.
§Examples
See here.
type Output = i64
source§impl RemPowerOf2 for i128
impl RemPowerOf2 for i128
source§fn rem_power_of_2(self, pow: u64) -> i128
fn rem_power_of_2(self, pow: u64) -> i128
Divides a number by $2^k$, returning just the remainder. The remainder has the same sign as the first number.
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\operatorname{sgn}(x)\left \lfloor \frac{|x|}{2^k} \right \rfloor. $$
§Worst-case complexity
Constant time and additional memory.
§Examples
See here.
type Output = i128
source§impl RemPowerOf2 for isize
impl RemPowerOf2 for isize
source§fn rem_power_of_2(self, pow: u64) -> isize
fn rem_power_of_2(self, pow: u64) -> isize
Divides a number by $2^k$, returning just the remainder. The remainder has the same sign as the first number.
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\operatorname{sgn}(x)\left \lfloor \frac{|x|}{2^k} \right \rfloor. $$
§Worst-case complexity
Constant time and additional memory.
§Examples
See here.
type Output = isize
source§impl RemPowerOf2 for u8
impl RemPowerOf2 for u8
source§fn rem_power_of_2(self, pow: u64) -> u8
fn rem_power_of_2(self, pow: u64) -> u8
Divides a number by $2^k$, returning just the remainder. For unsigned integers,
rem_power_of_2
is equivalent to mod_power_of_2
.
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 RemPowerOf2 for u16
impl RemPowerOf2 for u16
source§fn rem_power_of_2(self, pow: u64) -> u16
fn rem_power_of_2(self, pow: u64) -> u16
Divides a number by $2^k$, returning just the remainder. For unsigned integers,
rem_power_of_2
is equivalent to mod_power_of_2
.
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 RemPowerOf2 for u32
impl RemPowerOf2 for u32
source§fn rem_power_of_2(self, pow: u64) -> u32
fn rem_power_of_2(self, pow: u64) -> u32
Divides a number by $2^k$, returning just the remainder. For unsigned integers,
rem_power_of_2
is equivalent to mod_power_of_2
.
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 RemPowerOf2 for u64
impl RemPowerOf2 for u64
source§fn rem_power_of_2(self, pow: u64) -> u64
fn rem_power_of_2(self, pow: u64) -> u64
Divides a number by $2^k$, returning just the remainder. For unsigned integers,
rem_power_of_2
is equivalent to mod_power_of_2
.
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 RemPowerOf2 for u128
impl RemPowerOf2 for u128
source§fn rem_power_of_2(self, pow: u64) -> u128
fn rem_power_of_2(self, pow: u64) -> u128
Divides a number by $2^k$, returning just the remainder. For unsigned integers,
rem_power_of_2
is equivalent to mod_power_of_2
.
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 RemPowerOf2 for usize
impl RemPowerOf2 for usize
source§fn rem_power_of_2(self, pow: u64) -> usize
fn rem_power_of_2(self, pow: u64) -> usize
Divides a number by $2^k$, returning just the remainder. For unsigned integers,
rem_power_of_2
is equivalent to mod_power_of_2
.
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.