pub trait BalancedMod<RHS = Self> {
type Output;
// Required method
fn balanced_mod(self, other: RHS) -> Self::Output;
}Expand description
Divides a number by another number, returning the balanced remainder: the representative of the first number modulo the second that is closest to zero.
The remainder $r$ satisfies $-|y|/2 < r \leq |y|/2$, so a remainder of exactly $|y|/2$ is positive. It is congruent to $x$ modulo $y$, and those two properties determine it uniquely.
Required Associated Types§
Required Methods§
fn balanced_mod(self, other: RHS) -> 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 BalancedMod for i8
impl BalancedMod for i8
Source§fn balanced_mod(self, other: i8) -> i8
fn balanced_mod(self, other: i8) -> i8
Divides a number by another number, returning the balanced remainder: the
representative of self modulo other that is closest to zero.
The remainder $r$ satisfies $-|y|/2 < r \leq |y|/2$ and $r \equiv x \bmod y$, which
determine it uniquely. A remainder of exactly $|y|/2$ is positive. Only the
magnitude of other matters, so negating it leaves the result unchanged.
§Worst-case complexity
Constant time and additional memory.
§Panics
Panics if other is zero.
§Examples
See here.
type Output = i8
Source§impl BalancedMod for i16
impl BalancedMod for i16
Source§fn balanced_mod(self, other: i16) -> i16
fn balanced_mod(self, other: i16) -> i16
Divides a number by another number, returning the balanced remainder: the
representative of self modulo other that is closest to zero.
The remainder $r$ satisfies $-|y|/2 < r \leq |y|/2$ and $r \equiv x \bmod y$, which
determine it uniquely. A remainder of exactly $|y|/2$ is positive. Only the
magnitude of other matters, so negating it leaves the result unchanged.
§Worst-case complexity
Constant time and additional memory.
§Panics
Panics if other is zero.
§Examples
See here.
type Output = i16
Source§impl BalancedMod for i32
impl BalancedMod for i32
Source§fn balanced_mod(self, other: i32) -> i32
fn balanced_mod(self, other: i32) -> i32
Divides a number by another number, returning the balanced remainder: the
representative of self modulo other that is closest to zero.
The remainder $r$ satisfies $-|y|/2 < r \leq |y|/2$ and $r \equiv x \bmod y$, which
determine it uniquely. A remainder of exactly $|y|/2$ is positive. Only the
magnitude of other matters, so negating it leaves the result unchanged.
§Worst-case complexity
Constant time and additional memory.
§Panics
Panics if other is zero.
§Examples
See here.
type Output = i32
Source§impl BalancedMod for i64
impl BalancedMod for i64
Source§fn balanced_mod(self, other: i64) -> i64
fn balanced_mod(self, other: i64) -> i64
Divides a number by another number, returning the balanced remainder: the
representative of self modulo other that is closest to zero.
The remainder $r$ satisfies $-|y|/2 < r \leq |y|/2$ and $r \equiv x \bmod y$, which
determine it uniquely. A remainder of exactly $|y|/2$ is positive. Only the
magnitude of other matters, so negating it leaves the result unchanged.
§Worst-case complexity
Constant time and additional memory.
§Panics
Panics if other is zero.
§Examples
See here.
type Output = i64
Source§impl BalancedMod for i128
impl BalancedMod for i128
Source§fn balanced_mod(self, other: i128) -> i128
fn balanced_mod(self, other: i128) -> i128
Divides a number by another number, returning the balanced remainder: the
representative of self modulo other that is closest to zero.
The remainder $r$ satisfies $-|y|/2 < r \leq |y|/2$ and $r \equiv x \bmod y$, which
determine it uniquely. A remainder of exactly $|y|/2$ is positive. Only the
magnitude of other matters, so negating it leaves the result unchanged.
§Worst-case complexity
Constant time and additional memory.
§Panics
Panics if other is zero.
§Examples
See here.
type Output = i128
Source§impl BalancedMod for isize
impl BalancedMod for isize
Source§fn balanced_mod(self, other: isize) -> isize
fn balanced_mod(self, other: isize) -> isize
Divides a number by another number, returning the balanced remainder: the
representative of self modulo other that is closest to zero.
The remainder $r$ satisfies $-|y|/2 < r \leq |y|/2$ and $r \equiv x \bmod y$, which
determine it uniquely. A remainder of exactly $|y|/2$ is positive. Only the
magnitude of other matters, so negating it leaves the result unchanged.
§Worst-case complexity
Constant time and additional memory.
§Panics
Panics if other is zero.
§Examples
See here.
type Output = isize
Source§impl BalancedMod for u8
impl BalancedMod for u8
Source§fn balanced_mod(self, other: u8) -> i8
fn balanced_mod(self, other: u8) -> i8
Divides a number by another number, returning the balanced remainder: the
representative of self modulo other that is closest to zero.
The remainder $r$ satisfies $-y/2 < r \leq y/2$ and $r \equiv x \bmod y$, which determine it uniquely. A remainder of exactly $y/2$ is positive, so the result may be negative and is returned as the signed type of the same width. It always fits: the magnitude never exceeds $y/2$, which is at most half the unsigned maximum.
§Worst-case complexity
Constant time and additional memory.
§Panics
Panics if other is zero.
§Examples
See here.
type Output = i8
Source§impl BalancedMod for u16
impl BalancedMod for u16
Source§fn balanced_mod(self, other: u16) -> i16
fn balanced_mod(self, other: u16) -> i16
Divides a number by another number, returning the balanced remainder: the
representative of self modulo other that is closest to zero.
The remainder $r$ satisfies $-y/2 < r \leq y/2$ and $r \equiv x \bmod y$, which determine it uniquely. A remainder of exactly $y/2$ is positive, so the result may be negative and is returned as the signed type of the same width. It always fits: the magnitude never exceeds $y/2$, which is at most half the unsigned maximum.
§Worst-case complexity
Constant time and additional memory.
§Panics
Panics if other is zero.
§Examples
See here.
type Output = i16
Source§impl BalancedMod for u32
impl BalancedMod for u32
Source§fn balanced_mod(self, other: u32) -> i32
fn balanced_mod(self, other: u32) -> i32
Divides a number by another number, returning the balanced remainder: the
representative of self modulo other that is closest to zero.
The remainder $r$ satisfies $-y/2 < r \leq y/2$ and $r \equiv x \bmod y$, which determine it uniquely. A remainder of exactly $y/2$ is positive, so the result may be negative and is returned as the signed type of the same width. It always fits: the magnitude never exceeds $y/2$, which is at most half the unsigned maximum.
§Worst-case complexity
Constant time and additional memory.
§Panics
Panics if other is zero.
§Examples
See here.
type Output = i32
Source§impl BalancedMod for u64
impl BalancedMod for u64
Source§fn balanced_mod(self, other: u64) -> i64
fn balanced_mod(self, other: u64) -> i64
Divides a number by another number, returning the balanced remainder: the
representative of self modulo other that is closest to zero.
The remainder $r$ satisfies $-y/2 < r \leq y/2$ and $r \equiv x \bmod y$, which determine it uniquely. A remainder of exactly $y/2$ is positive, so the result may be negative and is returned as the signed type of the same width. It always fits: the magnitude never exceeds $y/2$, which is at most half the unsigned maximum.
§Worst-case complexity
Constant time and additional memory.
§Panics
Panics if other is zero.
§Examples
See here.
type Output = i64
Source§impl BalancedMod for u128
impl BalancedMod for u128
Source§fn balanced_mod(self, other: u128) -> i128
fn balanced_mod(self, other: u128) -> i128
Divides a number by another number, returning the balanced remainder: the
representative of self modulo other that is closest to zero.
The remainder $r$ satisfies $-y/2 < r \leq y/2$ and $r \equiv x \bmod y$, which determine it uniquely. A remainder of exactly $y/2$ is positive, so the result may be negative and is returned as the signed type of the same width. It always fits: the magnitude never exceeds $y/2$, which is at most half the unsigned maximum.
§Worst-case complexity
Constant time and additional memory.
§Panics
Panics if other is zero.
§Examples
See here.
type Output = i128
Source§impl BalancedMod for usize
impl BalancedMod for usize
Source§fn balanced_mod(self, other: usize) -> isize
fn balanced_mod(self, other: usize) -> isize
Divides a number by another number, returning the balanced remainder: the
representative of self modulo other that is closest to zero.
The remainder $r$ satisfies $-y/2 < r \leq y/2$ and $r \equiv x \bmod y$, which determine it uniquely. A remainder of exactly $y/2$ is positive, so the result may be negative and is returned as the signed type of the same width. It always fits: the magnitude never exceeds $y/2$, which is at most half the unsigned maximum.
§Worst-case complexity
Constant time and additional memory.
§Panics
Panics if other is zero.
§Examples
See here.