pub trait BalancedModPowerOf2 {
type Output;
// Required method
fn balanced_mod_power_of_2(self, pow: u64) -> Self::Output;
}Expand description
Divides a number by $2^k$, returning the balanced remainder: the representative of the number modulo $2^k$ that is closest to zero.
The remainder $r$ satisfies $-2^{k-1} < r \leq 2^{k-1}$, so a remainder of exactly $2^{k-1}$ is
positive, as with BalancedMod; for $k = 0$ it is 0. It is congruent to $x$ modulo $2^k$, and
those two properties determine it uniquely.
Required Associated Types§
Required Methods§
fn balanced_mod_power_of_2(self, pow: 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 BalancedModPowerOf2 for i8
impl BalancedModPowerOf2 for i8
Source§fn balanced_mod_power_of_2(self, pow: u64) -> i8
fn balanced_mod_power_of_2(self, pow: u64) -> i8
Divides a number by $2^k$, returning the balanced remainder: the representative of
self modulo $2^k$ that is closest to zero.
The remainder $r$ satisfies $-2^{k-1} < r \leq 2^{k-1}$ and $r \equiv x \bmod 2^k$,
which determine it uniquely; for $k = 0$ it is 0. A remainder of exactly $2^{k-1}$
is positive. When pow is greater than Self::WIDTH, every value is its own
balanced remainder.
§Worst-case complexity
Constant time and additional memory.
§Panics
Panics if pow is Self::WIDTH and self is Self::MIN, whose balanced remainder
$2^{W-1}$ does not fit in the type.
§Examples
See here.
type Output = i8
Source§impl BalancedModPowerOf2 for i16
impl BalancedModPowerOf2 for i16
Source§fn balanced_mod_power_of_2(self, pow: u64) -> i16
fn balanced_mod_power_of_2(self, pow: u64) -> i16
Divides a number by $2^k$, returning the balanced remainder: the representative of
self modulo $2^k$ that is closest to zero.
The remainder $r$ satisfies $-2^{k-1} < r \leq 2^{k-1}$ and $r \equiv x \bmod 2^k$,
which determine it uniquely; for $k = 0$ it is 0. A remainder of exactly $2^{k-1}$
is positive. When pow is greater than Self::WIDTH, every value is its own
balanced remainder.
§Worst-case complexity
Constant time and additional memory.
§Panics
Panics if pow is Self::WIDTH and self is Self::MIN, whose balanced remainder
$2^{W-1}$ does not fit in the type.
§Examples
See here.
type Output = i16
Source§impl BalancedModPowerOf2 for i32
impl BalancedModPowerOf2 for i32
Source§fn balanced_mod_power_of_2(self, pow: u64) -> i32
fn balanced_mod_power_of_2(self, pow: u64) -> i32
Divides a number by $2^k$, returning the balanced remainder: the representative of
self modulo $2^k$ that is closest to zero.
The remainder $r$ satisfies $-2^{k-1} < r \leq 2^{k-1}$ and $r \equiv x \bmod 2^k$,
which determine it uniquely; for $k = 0$ it is 0. A remainder of exactly $2^{k-1}$
is positive. When pow is greater than Self::WIDTH, every value is its own
balanced remainder.
§Worst-case complexity
Constant time and additional memory.
§Panics
Panics if pow is Self::WIDTH and self is Self::MIN, whose balanced remainder
$2^{W-1}$ does not fit in the type.
§Examples
See here.
type Output = i32
Source§impl BalancedModPowerOf2 for i64
impl BalancedModPowerOf2 for i64
Source§fn balanced_mod_power_of_2(self, pow: u64) -> i64
fn balanced_mod_power_of_2(self, pow: u64) -> i64
Divides a number by $2^k$, returning the balanced remainder: the representative of
self modulo $2^k$ that is closest to zero.
The remainder $r$ satisfies $-2^{k-1} < r \leq 2^{k-1}$ and $r \equiv x \bmod 2^k$,
which determine it uniquely; for $k = 0$ it is 0. A remainder of exactly $2^{k-1}$
is positive. When pow is greater than Self::WIDTH, every value is its own
balanced remainder.
§Worst-case complexity
Constant time and additional memory.
§Panics
Panics if pow is Self::WIDTH and self is Self::MIN, whose balanced remainder
$2^{W-1}$ does not fit in the type.
§Examples
See here.
type Output = i64
Source§impl BalancedModPowerOf2 for i128
impl BalancedModPowerOf2 for i128
Source§fn balanced_mod_power_of_2(self, pow: u64) -> i128
fn balanced_mod_power_of_2(self, pow: u64) -> i128
Divides a number by $2^k$, returning the balanced remainder: the representative of
self modulo $2^k$ that is closest to zero.
The remainder $r$ satisfies $-2^{k-1} < r \leq 2^{k-1}$ and $r \equiv x \bmod 2^k$,
which determine it uniquely; for $k = 0$ it is 0. A remainder of exactly $2^{k-1}$
is positive. When pow is greater than Self::WIDTH, every value is its own
balanced remainder.
§Worst-case complexity
Constant time and additional memory.
§Panics
Panics if pow is Self::WIDTH and self is Self::MIN, whose balanced remainder
$2^{W-1}$ does not fit in the type.
§Examples
See here.
type Output = i128
Source§impl BalancedModPowerOf2 for isize
impl BalancedModPowerOf2 for isize
Source§fn balanced_mod_power_of_2(self, pow: u64) -> isize
fn balanced_mod_power_of_2(self, pow: u64) -> isize
Divides a number by $2^k$, returning the balanced remainder: the representative of
self modulo $2^k$ that is closest to zero.
The remainder $r$ satisfies $-2^{k-1} < r \leq 2^{k-1}$ and $r \equiv x \bmod 2^k$,
which determine it uniquely; for $k = 0$ it is 0. A remainder of exactly $2^{k-1}$
is positive. When pow is greater than Self::WIDTH, every value is its own
balanced remainder.
§Worst-case complexity
Constant time and additional memory.
§Panics
Panics if pow is Self::WIDTH and self is Self::MIN, whose balanced remainder
$2^{W-1}$ does not fit in the type.
§Examples
See here.
type Output = isize
Source§impl BalancedModPowerOf2 for u8
impl BalancedModPowerOf2 for u8
Source§fn balanced_mod_power_of_2(self, pow: u64) -> i8
fn balanced_mod_power_of_2(self, pow: u64) -> i8
Divides a number by $2^k$, returning the balanced remainder: the representative of
self modulo $2^k$ that is closest to zero.
The remainder $r$ satisfies $-2^{k-1} < r \leq 2^{k-1}$ and $r \equiv x \bmod 2^k$,
which determine it uniquely; for $k = 0$ it is 0. A remainder of exactly $2^{k-1}$
is positive, so the result may be negative and is returned as the signed type of the
same width. This is the same as balanced_mod with
modulus $2^k$, when $2^k$ fits in the type.
§Worst-case complexity
Constant time and additional memory.
§Panics
Panics if the result does not fit in the signed type: if pow is Self::WIDTH and
self is $2^{W-1}$, or if pow is greater than Self::WIDTH and self is at
least $2^{W-1}$, where $W$ is Self::WIDTH.
§Examples
See here.
type Output = i8
Source§impl BalancedModPowerOf2 for u16
impl BalancedModPowerOf2 for u16
Source§fn balanced_mod_power_of_2(self, pow: u64) -> i16
fn balanced_mod_power_of_2(self, pow: u64) -> i16
Divides a number by $2^k$, returning the balanced remainder: the representative of
self modulo $2^k$ that is closest to zero.
The remainder $r$ satisfies $-2^{k-1} < r \leq 2^{k-1}$ and $r \equiv x \bmod 2^k$,
which determine it uniquely; for $k = 0$ it is 0. A remainder of exactly $2^{k-1}$
is positive, so the result may be negative and is returned as the signed type of the
same width. This is the same as balanced_mod with
modulus $2^k$, when $2^k$ fits in the type.
§Worst-case complexity
Constant time and additional memory.
§Panics
Panics if the result does not fit in the signed type: if pow is Self::WIDTH and
self is $2^{W-1}$, or if pow is greater than Self::WIDTH and self is at
least $2^{W-1}$, where $W$ is Self::WIDTH.
§Examples
See here.
type Output = i16
Source§impl BalancedModPowerOf2 for u32
impl BalancedModPowerOf2 for u32
Source§fn balanced_mod_power_of_2(self, pow: u64) -> i32
fn balanced_mod_power_of_2(self, pow: u64) -> i32
Divides a number by $2^k$, returning the balanced remainder: the representative of
self modulo $2^k$ that is closest to zero.
The remainder $r$ satisfies $-2^{k-1} < r \leq 2^{k-1}$ and $r \equiv x \bmod 2^k$,
which determine it uniquely; for $k = 0$ it is 0. A remainder of exactly $2^{k-1}$
is positive, so the result may be negative and is returned as the signed type of the
same width. This is the same as balanced_mod with
modulus $2^k$, when $2^k$ fits in the type.
§Worst-case complexity
Constant time and additional memory.
§Panics
Panics if the result does not fit in the signed type: if pow is Self::WIDTH and
self is $2^{W-1}$, or if pow is greater than Self::WIDTH and self is at
least $2^{W-1}$, where $W$ is Self::WIDTH.
§Examples
See here.
type Output = i32
Source§impl BalancedModPowerOf2 for u64
impl BalancedModPowerOf2 for u64
Source§fn balanced_mod_power_of_2(self, pow: u64) -> i64
fn balanced_mod_power_of_2(self, pow: u64) -> i64
Divides a number by $2^k$, returning the balanced remainder: the representative of
self modulo $2^k$ that is closest to zero.
The remainder $r$ satisfies $-2^{k-1} < r \leq 2^{k-1}$ and $r \equiv x \bmod 2^k$,
which determine it uniquely; for $k = 0$ it is 0. A remainder of exactly $2^{k-1}$
is positive, so the result may be negative and is returned as the signed type of the
same width. This is the same as balanced_mod with
modulus $2^k$, when $2^k$ fits in the type.
§Worst-case complexity
Constant time and additional memory.
§Panics
Panics if the result does not fit in the signed type: if pow is Self::WIDTH and
self is $2^{W-1}$, or if pow is greater than Self::WIDTH and self is at
least $2^{W-1}$, where $W$ is Self::WIDTH.
§Examples
See here.
type Output = i64
Source§impl BalancedModPowerOf2 for u128
impl BalancedModPowerOf2 for u128
Source§fn balanced_mod_power_of_2(self, pow: u64) -> i128
fn balanced_mod_power_of_2(self, pow: u64) -> i128
Divides a number by $2^k$, returning the balanced remainder: the representative of
self modulo $2^k$ that is closest to zero.
The remainder $r$ satisfies $-2^{k-1} < r \leq 2^{k-1}$ and $r \equiv x \bmod 2^k$,
which determine it uniquely; for $k = 0$ it is 0. A remainder of exactly $2^{k-1}$
is positive, so the result may be negative and is returned as the signed type of the
same width. This is the same as balanced_mod with
modulus $2^k$, when $2^k$ fits in the type.
§Worst-case complexity
Constant time and additional memory.
§Panics
Panics if the result does not fit in the signed type: if pow is Self::WIDTH and
self is $2^{W-1}$, or if pow is greater than Self::WIDTH and self is at
least $2^{W-1}$, where $W$ is Self::WIDTH.
§Examples
See here.
type Output = i128
Source§impl BalancedModPowerOf2 for usize
impl BalancedModPowerOf2 for usize
Source§fn balanced_mod_power_of_2(self, pow: u64) -> isize
fn balanced_mod_power_of_2(self, pow: u64) -> isize
Divides a number by $2^k$, returning the balanced remainder: the representative of
self modulo $2^k$ that is closest to zero.
The remainder $r$ satisfies $-2^{k-1} < r \leq 2^{k-1}$ and $r \equiv x \bmod 2^k$,
which determine it uniquely; for $k = 0$ it is 0. A remainder of exactly $2^{k-1}$
is positive, so the result may be negative and is returned as the signed type of the
same width. This is the same as balanced_mod with
modulus $2^k$, when $2^k$ fits in the type.
§Worst-case complexity
Constant time and additional memory.
§Panics
Panics if the result does not fit in the signed type: if pow is Self::WIDTH and
self is $2^{W-1}$, or if pow is greater than Self::WIDTH and self is at
least $2^{W-1}$, where $W$ is Self::WIDTH.
§Examples
See here.