Trait malachite_base::num::arithmetic::traits::ShrRound
source · [−]pub trait ShrRound<RHS> {
type Output;
fn shr_round(self, other: RHS, rm: RoundingMode) -> Self::Output;
}
Expand description
Right-shifts a number (divides it by a power of 2), rounding the result according to a specified rounding mode.
Rounding might only be necessary if other
is positive.
Required Associated Types
Required Methods
fn shr_round(self, other: RHS, rm: RoundingMode) -> Self::Output
Implementations on Foreign Types
sourceimpl ShrRound<u8> for u8
impl ShrRound<u8> for u8
sourcefn shr_round(self, bits: u8, rm: RoundingMode) -> u8
fn shr_round(self, bits: u8, rm: RoundingMode) -> u8
Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode.
Passing RoundingMode::Floor
or RoundingMode::Down
is equivalent to using
>>
. To test whether RoundingMode::Exact
can be passed, use
self.divisible_by_power_of_2(bits)
.
Let $q = \frac{x}{2^k}$:
$f(x, k, \mathrm{Down}) = f(x, y, \mathrm{Floor}) = \lfloor q \rfloor.$
$f(x, k, \mathrm{Up}) = f(x, y, \mathrm{Ceiling}) = \lceil q \rceil.$
$$ f(x, k, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd}. \end{cases} $$
$f(x, k, \mathrm{Exact}) = q$, but panics if $q \notin \N$.
Worst-case complexity
Constant time and additional memory.
Panics
Panics if rm
is RoundingMode::Exact
but self
is not divisible by
$2^b$.
Examples
See here.
type Output = u8
sourceimpl ShrRound<u16> for u8
impl ShrRound<u16> for u8
sourcefn shr_round(self, bits: u16, rm: RoundingMode) -> u8
fn shr_round(self, bits: u16, rm: RoundingMode) -> u8
Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode.
Passing RoundingMode::Floor
or RoundingMode::Down
is equivalent to using
>>
. To test whether RoundingMode::Exact
can be passed, use
self.divisible_by_power_of_2(bits)
.
Let $q = \frac{x}{2^k}$:
$f(x, k, \mathrm{Down}) = f(x, y, \mathrm{Floor}) = \lfloor q \rfloor.$
$f(x, k, \mathrm{Up}) = f(x, y, \mathrm{Ceiling}) = \lceil q \rceil.$
$$ f(x, k, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd}. \end{cases} $$
$f(x, k, \mathrm{Exact}) = q$, but panics if $q \notin \N$.
Worst-case complexity
Constant time and additional memory.
Panics
Panics if rm
is RoundingMode::Exact
but self
is not divisible by
$2^b$.
Examples
See here.
type Output = u8
sourceimpl ShrRound<u32> for u8
impl ShrRound<u32> for u8
sourcefn shr_round(self, bits: u32, rm: RoundingMode) -> u8
fn shr_round(self, bits: u32, rm: RoundingMode) -> u8
Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode.
Passing RoundingMode::Floor
or RoundingMode::Down
is equivalent to using
>>
. To test whether RoundingMode::Exact
can be passed, use
self.divisible_by_power_of_2(bits)
.
Let $q = \frac{x}{2^k}$:
$f(x, k, \mathrm{Down}) = f(x, y, \mathrm{Floor}) = \lfloor q \rfloor.$
$f(x, k, \mathrm{Up}) = f(x, y, \mathrm{Ceiling}) = \lceil q \rceil.$
$$ f(x, k, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd}. \end{cases} $$
$f(x, k, \mathrm{Exact}) = q$, but panics if $q \notin \N$.
Worst-case complexity
Constant time and additional memory.
Panics
Panics if rm
is RoundingMode::Exact
but self
is not divisible by
$2^b$.
Examples
See here.
type Output = u8
sourceimpl ShrRound<u64> for u8
impl ShrRound<u64> for u8
sourcefn shr_round(self, bits: u64, rm: RoundingMode) -> u8
fn shr_round(self, bits: u64, rm: RoundingMode) -> u8
Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode.
Passing RoundingMode::Floor
or RoundingMode::Down
is equivalent to using
>>
. To test whether RoundingMode::Exact
can be passed, use
self.divisible_by_power_of_2(bits)
.
Let $q = \frac{x}{2^k}$:
$f(x, k, \mathrm{Down}) = f(x, y, \mathrm{Floor}) = \lfloor q \rfloor.$
$f(x, k, \mathrm{Up}) = f(x, y, \mathrm{Ceiling}) = \lceil q \rceil.$
$$ f(x, k, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd}. \end{cases} $$
$f(x, k, \mathrm{Exact}) = q$, but panics if $q \notin \N$.
Worst-case complexity
Constant time and additional memory.
Panics
Panics if rm
is RoundingMode::Exact
but self
is not divisible by
$2^b$.
Examples
See here.
type Output = u8
sourceimpl ShrRound<u128> for u8
impl ShrRound<u128> for u8
sourcefn shr_round(self, bits: u128, rm: RoundingMode) -> u8
fn shr_round(self, bits: u128, rm: RoundingMode) -> u8
Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode.
Passing RoundingMode::Floor
or RoundingMode::Down
is equivalent to using
>>
. To test whether RoundingMode::Exact
can be passed, use
self.divisible_by_power_of_2(bits)
.
Let $q = \frac{x}{2^k}$:
$f(x, k, \mathrm{Down}) = f(x, y, \mathrm{Floor}) = \lfloor q \rfloor.$
$f(x, k, \mathrm{Up}) = f(x, y, \mathrm{Ceiling}) = \lceil q \rceil.$
$$ f(x, k, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd}. \end{cases} $$
$f(x, k, \mathrm{Exact}) = q$, but panics if $q \notin \N$.
Worst-case complexity
Constant time and additional memory.
Panics
Panics if rm
is RoundingMode::Exact
but self
is not divisible by
$2^b$.
Examples
See here.
type Output = u8
sourceimpl ShrRound<usize> for u8
impl ShrRound<usize> for u8
sourcefn shr_round(self, bits: usize, rm: RoundingMode) -> u8
fn shr_round(self, bits: usize, rm: RoundingMode) -> u8
Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode.
Passing RoundingMode::Floor
or RoundingMode::Down
is equivalent to using
>>
. To test whether RoundingMode::Exact
can be passed, use
self.divisible_by_power_of_2(bits)
.
Let $q = \frac{x}{2^k}$:
$f(x, k, \mathrm{Down}) = f(x, y, \mathrm{Floor}) = \lfloor q \rfloor.$
$f(x, k, \mathrm{Up}) = f(x, y, \mathrm{Ceiling}) = \lceil q \rceil.$
$$ f(x, k, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd}. \end{cases} $$
$f(x, k, \mathrm{Exact}) = q$, but panics if $q \notin \N$.
Worst-case complexity
Constant time and additional memory.
Panics
Panics if rm
is RoundingMode::Exact
but self
is not divisible by
$2^b$.
Examples
See here.
type Output = u8
sourceimpl ShrRound<u8> for u16
impl ShrRound<u8> for u16
sourcefn shr_round(self, bits: u8, rm: RoundingMode) -> u16
fn shr_round(self, bits: u8, rm: RoundingMode) -> u16
Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode.
Passing RoundingMode::Floor
or RoundingMode::Down
is equivalent to using
>>
. To test whether RoundingMode::Exact
can be passed, use
self.divisible_by_power_of_2(bits)
.
Let $q = \frac{x}{2^k}$:
$f(x, k, \mathrm{Down}) = f(x, y, \mathrm{Floor}) = \lfloor q \rfloor.$
$f(x, k, \mathrm{Up}) = f(x, y, \mathrm{Ceiling}) = \lceil q \rceil.$
$$ f(x, k, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd}. \end{cases} $$
$f(x, k, \mathrm{Exact}) = q$, but panics if $q \notin \N$.
Worst-case complexity
Constant time and additional memory.
Panics
Panics if rm
is RoundingMode::Exact
but self
is not divisible by
$2^b$.
Examples
See here.
type Output = u16
sourceimpl ShrRound<u16> for u16
impl ShrRound<u16> for u16
sourcefn shr_round(self, bits: u16, rm: RoundingMode) -> u16
fn shr_round(self, bits: u16, rm: RoundingMode) -> u16
Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode.
Passing RoundingMode::Floor
or RoundingMode::Down
is equivalent to using
>>
. To test whether RoundingMode::Exact
can be passed, use
self.divisible_by_power_of_2(bits)
.
Let $q = \frac{x}{2^k}$:
$f(x, k, \mathrm{Down}) = f(x, y, \mathrm{Floor}) = \lfloor q \rfloor.$
$f(x, k, \mathrm{Up}) = f(x, y, \mathrm{Ceiling}) = \lceil q \rceil.$
$$ f(x, k, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd}. \end{cases} $$
$f(x, k, \mathrm{Exact}) = q$, but panics if $q \notin \N$.
Worst-case complexity
Constant time and additional memory.
Panics
Panics if rm
is RoundingMode::Exact
but self
is not divisible by
$2^b$.
Examples
See here.
type Output = u16
sourceimpl ShrRound<u32> for u16
impl ShrRound<u32> for u16
sourcefn shr_round(self, bits: u32, rm: RoundingMode) -> u16
fn shr_round(self, bits: u32, rm: RoundingMode) -> u16
Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode.
Passing RoundingMode::Floor
or RoundingMode::Down
is equivalent to using
>>
. To test whether RoundingMode::Exact
can be passed, use
self.divisible_by_power_of_2(bits)
.
Let $q = \frac{x}{2^k}$:
$f(x, k, \mathrm{Down}) = f(x, y, \mathrm{Floor}) = \lfloor q \rfloor.$
$f(x, k, \mathrm{Up}) = f(x, y, \mathrm{Ceiling}) = \lceil q \rceil.$
$$ f(x, k, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd}. \end{cases} $$
$f(x, k, \mathrm{Exact}) = q$, but panics if $q \notin \N$.
Worst-case complexity
Constant time and additional memory.
Panics
Panics if rm
is RoundingMode::Exact
but self
is not divisible by
$2^b$.
Examples
See here.
type Output = u16
sourceimpl ShrRound<u64> for u16
impl ShrRound<u64> for u16
sourcefn shr_round(self, bits: u64, rm: RoundingMode) -> u16
fn shr_round(self, bits: u64, rm: RoundingMode) -> u16
Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode.
Passing RoundingMode::Floor
or RoundingMode::Down
is equivalent to using
>>
. To test whether RoundingMode::Exact
can be passed, use
self.divisible_by_power_of_2(bits)
.
Let $q = \frac{x}{2^k}$:
$f(x, k, \mathrm{Down}) = f(x, y, \mathrm{Floor}) = \lfloor q \rfloor.$
$f(x, k, \mathrm{Up}) = f(x, y, \mathrm{Ceiling}) = \lceil q \rceil.$
$$ f(x, k, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd}. \end{cases} $$
$f(x, k, \mathrm{Exact}) = q$, but panics if $q \notin \N$.
Worst-case complexity
Constant time and additional memory.
Panics
Panics if rm
is RoundingMode::Exact
but self
is not divisible by
$2^b$.
Examples
See here.
type Output = u16
sourceimpl ShrRound<u128> for u16
impl ShrRound<u128> for u16
sourcefn shr_round(self, bits: u128, rm: RoundingMode) -> u16
fn shr_round(self, bits: u128, rm: RoundingMode) -> u16
Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode.
Passing RoundingMode::Floor
or RoundingMode::Down
is equivalent to using
>>
. To test whether RoundingMode::Exact
can be passed, use
self.divisible_by_power_of_2(bits)
.
Let $q = \frac{x}{2^k}$:
$f(x, k, \mathrm{Down}) = f(x, y, \mathrm{Floor}) = \lfloor q \rfloor.$
$f(x, k, \mathrm{Up}) = f(x, y, \mathrm{Ceiling}) = \lceil q \rceil.$
$$ f(x, k, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd}. \end{cases} $$
$f(x, k, \mathrm{Exact}) = q$, but panics if $q \notin \N$.
Worst-case complexity
Constant time and additional memory.
Panics
Panics if rm
is RoundingMode::Exact
but self
is not divisible by
$2^b$.
Examples
See here.
type Output = u16
sourceimpl ShrRound<usize> for u16
impl ShrRound<usize> for u16
sourcefn shr_round(self, bits: usize, rm: RoundingMode) -> u16
fn shr_round(self, bits: usize, rm: RoundingMode) -> u16
Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode.
Passing RoundingMode::Floor
or RoundingMode::Down
is equivalent to using
>>
. To test whether RoundingMode::Exact
can be passed, use
self.divisible_by_power_of_2(bits)
.
Let $q = \frac{x}{2^k}$:
$f(x, k, \mathrm{Down}) = f(x, y, \mathrm{Floor}) = \lfloor q \rfloor.$
$f(x, k, \mathrm{Up}) = f(x, y, \mathrm{Ceiling}) = \lceil q \rceil.$
$$ f(x, k, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd}. \end{cases} $$
$f(x, k, \mathrm{Exact}) = q$, but panics if $q \notin \N$.
Worst-case complexity
Constant time and additional memory.
Panics
Panics if rm
is RoundingMode::Exact
but self
is not divisible by
$2^b$.
Examples
See here.
type Output = u16
sourceimpl ShrRound<u8> for u32
impl ShrRound<u8> for u32
sourcefn shr_round(self, bits: u8, rm: RoundingMode) -> u32
fn shr_round(self, bits: u8, rm: RoundingMode) -> u32
Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode.
Passing RoundingMode::Floor
or RoundingMode::Down
is equivalent to using
>>
. To test whether RoundingMode::Exact
can be passed, use
self.divisible_by_power_of_2(bits)
.
Let $q = \frac{x}{2^k}$:
$f(x, k, \mathrm{Down}) = f(x, y, \mathrm{Floor}) = \lfloor q \rfloor.$
$f(x, k, \mathrm{Up}) = f(x, y, \mathrm{Ceiling}) = \lceil q \rceil.$
$$ f(x, k, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd}. \end{cases} $$
$f(x, k, \mathrm{Exact}) = q$, but panics if $q \notin \N$.
Worst-case complexity
Constant time and additional memory.
Panics
Panics if rm
is RoundingMode::Exact
but self
is not divisible by
$2^b$.
Examples
See here.
type Output = u32
sourceimpl ShrRound<u16> for u32
impl ShrRound<u16> for u32
sourcefn shr_round(self, bits: u16, rm: RoundingMode) -> u32
fn shr_round(self, bits: u16, rm: RoundingMode) -> u32
Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode.
Passing RoundingMode::Floor
or RoundingMode::Down
is equivalent to using
>>
. To test whether RoundingMode::Exact
can be passed, use
self.divisible_by_power_of_2(bits)
.
Let $q = \frac{x}{2^k}$:
$f(x, k, \mathrm{Down}) = f(x, y, \mathrm{Floor}) = \lfloor q \rfloor.$
$f(x, k, \mathrm{Up}) = f(x, y, \mathrm{Ceiling}) = \lceil q \rceil.$
$$ f(x, k, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd}. \end{cases} $$
$f(x, k, \mathrm{Exact}) = q$, but panics if $q \notin \N$.
Worst-case complexity
Constant time and additional memory.
Panics
Panics if rm
is RoundingMode::Exact
but self
is not divisible by
$2^b$.
Examples
See here.
type Output = u32
sourceimpl ShrRound<u32> for u32
impl ShrRound<u32> for u32
sourcefn shr_round(self, bits: u32, rm: RoundingMode) -> u32
fn shr_round(self, bits: u32, rm: RoundingMode) -> u32
Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode.
Passing RoundingMode::Floor
or RoundingMode::Down
is equivalent to using
>>
. To test whether RoundingMode::Exact
can be passed, use
self.divisible_by_power_of_2(bits)
.
Let $q = \frac{x}{2^k}$:
$f(x, k, \mathrm{Down}) = f(x, y, \mathrm{Floor}) = \lfloor q \rfloor.$
$f(x, k, \mathrm{Up}) = f(x, y, \mathrm{Ceiling}) = \lceil q \rceil.$
$$ f(x, k, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd}. \end{cases} $$
$f(x, k, \mathrm{Exact}) = q$, but panics if $q \notin \N$.
Worst-case complexity
Constant time and additional memory.
Panics
Panics if rm
is RoundingMode::Exact
but self
is not divisible by
$2^b$.
Examples
See here.
type Output = u32
sourceimpl ShrRound<u64> for u32
impl ShrRound<u64> for u32
sourcefn shr_round(self, bits: u64, rm: RoundingMode) -> u32
fn shr_round(self, bits: u64, rm: RoundingMode) -> u32
Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode.
Passing RoundingMode::Floor
or RoundingMode::Down
is equivalent to using
>>
. To test whether RoundingMode::Exact
can be passed, use
self.divisible_by_power_of_2(bits)
.
Let $q = \frac{x}{2^k}$:
$f(x, k, \mathrm{Down}) = f(x, y, \mathrm{Floor}) = \lfloor q \rfloor.$
$f(x, k, \mathrm{Up}) = f(x, y, \mathrm{Ceiling}) = \lceil q \rceil.$
$$ f(x, k, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd}. \end{cases} $$
$f(x, k, \mathrm{Exact}) = q$, but panics if $q \notin \N$.
Worst-case complexity
Constant time and additional memory.
Panics
Panics if rm
is RoundingMode::Exact
but self
is not divisible by
$2^b$.
Examples
See here.
type Output = u32
sourceimpl ShrRound<u128> for u32
impl ShrRound<u128> for u32
sourcefn shr_round(self, bits: u128, rm: RoundingMode) -> u32
fn shr_round(self, bits: u128, rm: RoundingMode) -> u32
Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode.
Passing RoundingMode::Floor
or RoundingMode::Down
is equivalent to using
>>
. To test whether RoundingMode::Exact
can be passed, use
self.divisible_by_power_of_2(bits)
.
Let $q = \frac{x}{2^k}$:
$f(x, k, \mathrm{Down}) = f(x, y, \mathrm{Floor}) = \lfloor q \rfloor.$
$f(x, k, \mathrm{Up}) = f(x, y, \mathrm{Ceiling}) = \lceil q \rceil.$
$$ f(x, k, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd}. \end{cases} $$
$f(x, k, \mathrm{Exact}) = q$, but panics if $q \notin \N$.
Worst-case complexity
Constant time and additional memory.
Panics
Panics if rm
is RoundingMode::Exact
but self
is not divisible by
$2^b$.
Examples
See here.
type Output = u32
sourceimpl ShrRound<usize> for u32
impl ShrRound<usize> for u32
sourcefn shr_round(self, bits: usize, rm: RoundingMode) -> u32
fn shr_round(self, bits: usize, rm: RoundingMode) -> u32
Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode.
Passing RoundingMode::Floor
or RoundingMode::Down
is equivalent to using
>>
. To test whether RoundingMode::Exact
can be passed, use
self.divisible_by_power_of_2(bits)
.
Let $q = \frac{x}{2^k}$:
$f(x, k, \mathrm{Down}) = f(x, y, \mathrm{Floor}) = \lfloor q \rfloor.$
$f(x, k, \mathrm{Up}) = f(x, y, \mathrm{Ceiling}) = \lceil q \rceil.$
$$ f(x, k, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd}. \end{cases} $$
$f(x, k, \mathrm{Exact}) = q$, but panics if $q \notin \N$.
Worst-case complexity
Constant time and additional memory.
Panics
Panics if rm
is RoundingMode::Exact
but self
is not divisible by
$2^b$.
Examples
See here.
type Output = u32
sourceimpl ShrRound<u8> for u64
impl ShrRound<u8> for u64
sourcefn shr_round(self, bits: u8, rm: RoundingMode) -> u64
fn shr_round(self, bits: u8, rm: RoundingMode) -> u64
Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode.
Passing RoundingMode::Floor
or RoundingMode::Down
is equivalent to using
>>
. To test whether RoundingMode::Exact
can be passed, use
self.divisible_by_power_of_2(bits)
.
Let $q = \frac{x}{2^k}$:
$f(x, k, \mathrm{Down}) = f(x, y, \mathrm{Floor}) = \lfloor q \rfloor.$
$f(x, k, \mathrm{Up}) = f(x, y, \mathrm{Ceiling}) = \lceil q \rceil.$
$$ f(x, k, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd}. \end{cases} $$
$f(x, k, \mathrm{Exact}) = q$, but panics if $q \notin \N$.
Worst-case complexity
Constant time and additional memory.
Panics
Panics if rm
is RoundingMode::Exact
but self
is not divisible by
$2^b$.
Examples
See here.
type Output = u64
sourceimpl ShrRound<u16> for u64
impl ShrRound<u16> for u64
sourcefn shr_round(self, bits: u16, rm: RoundingMode) -> u64
fn shr_round(self, bits: u16, rm: RoundingMode) -> u64
Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode.
Passing RoundingMode::Floor
or RoundingMode::Down
is equivalent to using
>>
. To test whether RoundingMode::Exact
can be passed, use
self.divisible_by_power_of_2(bits)
.
Let $q = \frac{x}{2^k}$:
$f(x, k, \mathrm{Down}) = f(x, y, \mathrm{Floor}) = \lfloor q \rfloor.$
$f(x, k, \mathrm{Up}) = f(x, y, \mathrm{Ceiling}) = \lceil q \rceil.$
$$ f(x, k, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd}. \end{cases} $$
$f(x, k, \mathrm{Exact}) = q$, but panics if $q \notin \N$.
Worst-case complexity
Constant time and additional memory.
Panics
Panics if rm
is RoundingMode::Exact
but self
is not divisible by
$2^b$.
Examples
See here.
type Output = u64
sourceimpl ShrRound<u32> for u64
impl ShrRound<u32> for u64
sourcefn shr_round(self, bits: u32, rm: RoundingMode) -> u64
fn shr_round(self, bits: u32, rm: RoundingMode) -> u64
Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode.
Passing RoundingMode::Floor
or RoundingMode::Down
is equivalent to using
>>
. To test whether RoundingMode::Exact
can be passed, use
self.divisible_by_power_of_2(bits)
.
Let $q = \frac{x}{2^k}$:
$f(x, k, \mathrm{Down}) = f(x, y, \mathrm{Floor}) = \lfloor q \rfloor.$
$f(x, k, \mathrm{Up}) = f(x, y, \mathrm{Ceiling}) = \lceil q \rceil.$
$$ f(x, k, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd}. \end{cases} $$
$f(x, k, \mathrm{Exact}) = q$, but panics if $q \notin \N$.
Worst-case complexity
Constant time and additional memory.
Panics
Panics if rm
is RoundingMode::Exact
but self
is not divisible by
$2^b$.
Examples
See here.
type Output = u64
sourceimpl ShrRound<u64> for u64
impl ShrRound<u64> for u64
sourcefn shr_round(self, bits: u64, rm: RoundingMode) -> u64
fn shr_round(self, bits: u64, rm: RoundingMode) -> u64
Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode.
Passing RoundingMode::Floor
or RoundingMode::Down
is equivalent to using
>>
. To test whether RoundingMode::Exact
can be passed, use
self.divisible_by_power_of_2(bits)
.
Let $q = \frac{x}{2^k}$:
$f(x, k, \mathrm{Down}) = f(x, y, \mathrm{Floor}) = \lfloor q \rfloor.$
$f(x, k, \mathrm{Up}) = f(x, y, \mathrm{Ceiling}) = \lceil q \rceil.$
$$ f(x, k, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd}. \end{cases} $$
$f(x, k, \mathrm{Exact}) = q$, but panics if $q \notin \N$.
Worst-case complexity
Constant time and additional memory.
Panics
Panics if rm
is RoundingMode::Exact
but self
is not divisible by
$2^b$.
Examples
See here.
type Output = u64
sourceimpl ShrRound<u128> for u64
impl ShrRound<u128> for u64
sourcefn shr_round(self, bits: u128, rm: RoundingMode) -> u64
fn shr_round(self, bits: u128, rm: RoundingMode) -> u64
Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode.
Passing RoundingMode::Floor
or RoundingMode::Down
is equivalent to using
>>
. To test whether RoundingMode::Exact
can be passed, use
self.divisible_by_power_of_2(bits)
.
Let $q = \frac{x}{2^k}$:
$f(x, k, \mathrm{Down}) = f(x, y, \mathrm{Floor}) = \lfloor q \rfloor.$
$f(x, k, \mathrm{Up}) = f(x, y, \mathrm{Ceiling}) = \lceil q \rceil.$
$$ f(x, k, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd}. \end{cases} $$
$f(x, k, \mathrm{Exact}) = q$, but panics if $q \notin \N$.
Worst-case complexity
Constant time and additional memory.
Panics
Panics if rm
is RoundingMode::Exact
but self
is not divisible by
$2^b$.
Examples
See here.
type Output = u64
sourceimpl ShrRound<usize> for u64
impl ShrRound<usize> for u64
sourcefn shr_round(self, bits: usize, rm: RoundingMode) -> u64
fn shr_round(self, bits: usize, rm: RoundingMode) -> u64
Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode.
Passing RoundingMode::Floor
or RoundingMode::Down
is equivalent to using
>>
. To test whether RoundingMode::Exact
can be passed, use
self.divisible_by_power_of_2(bits)
.
Let $q = \frac{x}{2^k}$:
$f(x, k, \mathrm{Down}) = f(x, y, \mathrm{Floor}) = \lfloor q \rfloor.$
$f(x, k, \mathrm{Up}) = f(x, y, \mathrm{Ceiling}) = \lceil q \rceil.$
$$ f(x, k, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd}. \end{cases} $$
$f(x, k, \mathrm{Exact}) = q$, but panics if $q \notin \N$.
Worst-case complexity
Constant time and additional memory.
Panics
Panics if rm
is RoundingMode::Exact
but self
is not divisible by
$2^b$.
Examples
See here.
type Output = u64
sourceimpl ShrRound<u8> for u128
impl ShrRound<u8> for u128
sourcefn shr_round(self, bits: u8, rm: RoundingMode) -> u128
fn shr_round(self, bits: u8, rm: RoundingMode) -> u128
Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode.
Passing RoundingMode::Floor
or RoundingMode::Down
is equivalent to using
>>
. To test whether RoundingMode::Exact
can be passed, use
self.divisible_by_power_of_2(bits)
.
Let $q = \frac{x}{2^k}$:
$f(x, k, \mathrm{Down}) = f(x, y, \mathrm{Floor}) = \lfloor q \rfloor.$
$f(x, k, \mathrm{Up}) = f(x, y, \mathrm{Ceiling}) = \lceil q \rceil.$
$$ f(x, k, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd}. \end{cases} $$
$f(x, k, \mathrm{Exact}) = q$, but panics if $q \notin \N$.
Worst-case complexity
Constant time and additional memory.
Panics
Panics if rm
is RoundingMode::Exact
but self
is not divisible by
$2^b$.
Examples
See here.
type Output = u128
sourceimpl ShrRound<u16> for u128
impl ShrRound<u16> for u128
sourcefn shr_round(self, bits: u16, rm: RoundingMode) -> u128
fn shr_round(self, bits: u16, rm: RoundingMode) -> u128
Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode.
Passing RoundingMode::Floor
or RoundingMode::Down
is equivalent to using
>>
. To test whether RoundingMode::Exact
can be passed, use
self.divisible_by_power_of_2(bits)
.
Let $q = \frac{x}{2^k}$:
$f(x, k, \mathrm{Down}) = f(x, y, \mathrm{Floor}) = \lfloor q \rfloor.$
$f(x, k, \mathrm{Up}) = f(x, y, \mathrm{Ceiling}) = \lceil q \rceil.$
$$ f(x, k, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd}. \end{cases} $$
$f(x, k, \mathrm{Exact}) = q$, but panics if $q \notin \N$.
Worst-case complexity
Constant time and additional memory.
Panics
Panics if rm
is RoundingMode::Exact
but self
is not divisible by
$2^b$.
Examples
See here.
type Output = u128
sourceimpl ShrRound<u32> for u128
impl ShrRound<u32> for u128
sourcefn shr_round(self, bits: u32, rm: RoundingMode) -> u128
fn shr_round(self, bits: u32, rm: RoundingMode) -> u128
Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode.
Passing RoundingMode::Floor
or RoundingMode::Down
is equivalent to using
>>
. To test whether RoundingMode::Exact
can be passed, use
self.divisible_by_power_of_2(bits)
.
Let $q = \frac{x}{2^k}$:
$f(x, k, \mathrm{Down}) = f(x, y, \mathrm{Floor}) = \lfloor q \rfloor.$
$f(x, k, \mathrm{Up}) = f(x, y, \mathrm{Ceiling}) = \lceil q \rceil.$
$$ f(x, k, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd}. \end{cases} $$
$f(x, k, \mathrm{Exact}) = q$, but panics if $q \notin \N$.
Worst-case complexity
Constant time and additional memory.
Panics
Panics if rm
is RoundingMode::Exact
but self
is not divisible by
$2^b$.
Examples
See here.
type Output = u128
sourceimpl ShrRound<u64> for u128
impl ShrRound<u64> for u128
sourcefn shr_round(self, bits: u64, rm: RoundingMode) -> u128
fn shr_round(self, bits: u64, rm: RoundingMode) -> u128
Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode.
Passing RoundingMode::Floor
or RoundingMode::Down
is equivalent to using
>>
. To test whether RoundingMode::Exact
can be passed, use
self.divisible_by_power_of_2(bits)
.
Let $q = \frac{x}{2^k}$:
$f(x, k, \mathrm{Down}) = f(x, y, \mathrm{Floor}) = \lfloor q \rfloor.$
$f(x, k, \mathrm{Up}) = f(x, y, \mathrm{Ceiling}) = \lceil q \rceil.$
$$ f(x, k, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd}. \end{cases} $$
$f(x, k, \mathrm{Exact}) = q$, but panics if $q \notin \N$.
Worst-case complexity
Constant time and additional memory.
Panics
Panics if rm
is RoundingMode::Exact
but self
is not divisible by
$2^b$.
Examples
See here.
type Output = u128
sourceimpl ShrRound<u128> for u128
impl ShrRound<u128> for u128
sourcefn shr_round(self, bits: u128, rm: RoundingMode) -> u128
fn shr_round(self, bits: u128, rm: RoundingMode) -> u128
Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode.
Passing RoundingMode::Floor
or RoundingMode::Down
is equivalent to using
>>
. To test whether RoundingMode::Exact
can be passed, use
self.divisible_by_power_of_2(bits)
.
Let $q = \frac{x}{2^k}$:
$f(x, k, \mathrm{Down}) = f(x, y, \mathrm{Floor}) = \lfloor q \rfloor.$
$f(x, k, \mathrm{Up}) = f(x, y, \mathrm{Ceiling}) = \lceil q \rceil.$
$$ f(x, k, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd}. \end{cases} $$
$f(x, k, \mathrm{Exact}) = q$, but panics if $q \notin \N$.
Worst-case complexity
Constant time and additional memory.
Panics
Panics if rm
is RoundingMode::Exact
but self
is not divisible by
$2^b$.
Examples
See here.
type Output = u128
sourceimpl ShrRound<usize> for u128
impl ShrRound<usize> for u128
sourcefn shr_round(self, bits: usize, rm: RoundingMode) -> u128
fn shr_round(self, bits: usize, rm: RoundingMode) -> u128
Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode.
Passing RoundingMode::Floor
or RoundingMode::Down
is equivalent to using
>>
. To test whether RoundingMode::Exact
can be passed, use
self.divisible_by_power_of_2(bits)
.
Let $q = \frac{x}{2^k}$:
$f(x, k, \mathrm{Down}) = f(x, y, \mathrm{Floor}) = \lfloor q \rfloor.$
$f(x, k, \mathrm{Up}) = f(x, y, \mathrm{Ceiling}) = \lceil q \rceil.$
$$ f(x, k, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd}. \end{cases} $$
$f(x, k, \mathrm{Exact}) = q$, but panics if $q \notin \N$.
Worst-case complexity
Constant time and additional memory.
Panics
Panics if rm
is RoundingMode::Exact
but self
is not divisible by
$2^b$.
Examples
See here.
type Output = u128
sourceimpl ShrRound<u8> for usize
impl ShrRound<u8> for usize
sourcefn shr_round(self, bits: u8, rm: RoundingMode) -> usize
fn shr_round(self, bits: u8, rm: RoundingMode) -> usize
Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode.
Passing RoundingMode::Floor
or RoundingMode::Down
is equivalent to using
>>
. To test whether RoundingMode::Exact
can be passed, use
self.divisible_by_power_of_2(bits)
.
Let $q = \frac{x}{2^k}$:
$f(x, k, \mathrm{Down}) = f(x, y, \mathrm{Floor}) = \lfloor q \rfloor.$
$f(x, k, \mathrm{Up}) = f(x, y, \mathrm{Ceiling}) = \lceil q \rceil.$
$$ f(x, k, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd}. \end{cases} $$
$f(x, k, \mathrm{Exact}) = q$, but panics if $q \notin \N$.
Worst-case complexity
Constant time and additional memory.
Panics
Panics if rm
is RoundingMode::Exact
but self
is not divisible by
$2^b$.
Examples
See here.
type Output = usize
sourceimpl ShrRound<u16> for usize
impl ShrRound<u16> for usize
sourcefn shr_round(self, bits: u16, rm: RoundingMode) -> usize
fn shr_round(self, bits: u16, rm: RoundingMode) -> usize
Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode.
Passing RoundingMode::Floor
or RoundingMode::Down
is equivalent to using
>>
. To test whether RoundingMode::Exact
can be passed, use
self.divisible_by_power_of_2(bits)
.
Let $q = \frac{x}{2^k}$:
$f(x, k, \mathrm{Down}) = f(x, y, \mathrm{Floor}) = \lfloor q \rfloor.$
$f(x, k, \mathrm{Up}) = f(x, y, \mathrm{Ceiling}) = \lceil q \rceil.$
$$ f(x, k, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd}. \end{cases} $$
$f(x, k, \mathrm{Exact}) = q$, but panics if $q \notin \N$.
Worst-case complexity
Constant time and additional memory.
Panics
Panics if rm
is RoundingMode::Exact
but self
is not divisible by
$2^b$.
Examples
See here.
type Output = usize
sourceimpl ShrRound<u32> for usize
impl ShrRound<u32> for usize
sourcefn shr_round(self, bits: u32, rm: RoundingMode) -> usize
fn shr_round(self, bits: u32, rm: RoundingMode) -> usize
Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode.
Passing RoundingMode::Floor
or RoundingMode::Down
is equivalent to using
>>
. To test whether RoundingMode::Exact
can be passed, use
self.divisible_by_power_of_2(bits)
.
Let $q = \frac{x}{2^k}$:
$f(x, k, \mathrm{Down}) = f(x, y, \mathrm{Floor}) = \lfloor q \rfloor.$
$f(x, k, \mathrm{Up}) = f(x, y, \mathrm{Ceiling}) = \lceil q \rceil.$
$$ f(x, k, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd}. \end{cases} $$
$f(x, k, \mathrm{Exact}) = q$, but panics if $q \notin \N$.
Worst-case complexity
Constant time and additional memory.
Panics
Panics if rm
is RoundingMode::Exact
but self
is not divisible by
$2^b$.
Examples
See here.
type Output = usize
sourceimpl ShrRound<u64> for usize
impl ShrRound<u64> for usize
sourcefn shr_round(self, bits: u64, rm: RoundingMode) -> usize
fn shr_round(self, bits: u64, rm: RoundingMode) -> usize
Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode.
Passing RoundingMode::Floor
or RoundingMode::Down
is equivalent to using
>>
. To test whether RoundingMode::Exact
can be passed, use
self.divisible_by_power_of_2(bits)
.
Let $q = \frac{x}{2^k}$:
$f(x, k, \mathrm{Down}) = f(x, y, \mathrm{Floor}) = \lfloor q \rfloor.$
$f(x, k, \mathrm{Up}) = f(x, y, \mathrm{Ceiling}) = \lceil q \rceil.$
$$ f(x, k, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd}. \end{cases} $$
$f(x, k, \mathrm{Exact}) = q$, but panics if $q \notin \N$.
Worst-case complexity
Constant time and additional memory.
Panics
Panics if rm
is RoundingMode::Exact
but self
is not divisible by
$2^b$.
Examples
See here.
type Output = usize
sourceimpl ShrRound<u128> for usize
impl ShrRound<u128> for usize
sourcefn shr_round(self, bits: u128, rm: RoundingMode) -> usize
fn shr_round(self, bits: u128, rm: RoundingMode) -> usize
Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode.
Passing RoundingMode::Floor
or RoundingMode::Down
is equivalent to using
>>
. To test whether RoundingMode::Exact
can be passed, use
self.divisible_by_power_of_2(bits)
.
Let $q = \frac{x}{2^k}$:
$f(x, k, \mathrm{Down}) = f(x, y, \mathrm{Floor}) = \lfloor q \rfloor.$
$f(x, k, \mathrm{Up}) = f(x, y, \mathrm{Ceiling}) = \lceil q \rceil.$
$$ f(x, k, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd}. \end{cases} $$
$f(x, k, \mathrm{Exact}) = q$, but panics if $q \notin \N$.
Worst-case complexity
Constant time and additional memory.
Panics
Panics if rm
is RoundingMode::Exact
but self
is not divisible by
$2^b$.
Examples
See here.
type Output = usize
sourceimpl ShrRound<usize> for usize
impl ShrRound<usize> for usize
sourcefn shr_round(self, bits: usize, rm: RoundingMode) -> usize
fn shr_round(self, bits: usize, rm: RoundingMode) -> usize
Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode.
Passing RoundingMode::Floor
or RoundingMode::Down
is equivalent to using
>>
. To test whether RoundingMode::Exact
can be passed, use
self.divisible_by_power_of_2(bits)
.
Let $q = \frac{x}{2^k}$:
$f(x, k, \mathrm{Down}) = f(x, y, \mathrm{Floor}) = \lfloor q \rfloor.$
$f(x, k, \mathrm{Up}) = f(x, y, \mathrm{Ceiling}) = \lceil q \rceil.$
$$ f(x, k, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd}. \end{cases} $$
$f(x, k, \mathrm{Exact}) = q$, but panics if $q \notin \N$.
Worst-case complexity
Constant time and additional memory.
Panics
Panics if rm
is RoundingMode::Exact
but self
is not divisible by
$2^b$.
Examples
See here.
type Output = usize
sourceimpl ShrRound<u8> for i8
impl ShrRound<u8> for i8
sourcefn shr_round(self, bits: u8, rm: RoundingMode) -> i8
fn shr_round(self, bits: u8, rm: RoundingMode) -> i8
Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode.
Passing RoundingMode::Floor
or RoundingMode::Down
is equivalent to
using >>
. To test whether RoundingMode::Exact
can be passed, use
self.divisible_by_power_of_2(bits)
.
Let $q = \frac{x}{2^p}$:
$f(x, p, \mathrm{Down}) = f(x, y, \mathrm{Floor}) = \lfloor q \rfloor.$
$f(x, p, \mathrm{Up}) = f(x, y, \mathrm{Ceiling}) = \lceil q \rceil.$
$$ f(x, p, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd}. \end{cases} $$
$f(x, p, \mathrm{Exact}) = q$, but panics if $q \notin \N$.
Worst-case complexity
Constant time and additional memory.
Panics
Panics if rm
is RoundingMode::Exact
but self
is not divisible by
$2^b$.
Examples
See here.
type Output = i8
sourceimpl ShrRound<u16> for i8
impl ShrRound<u16> for i8
sourcefn shr_round(self, bits: u16, rm: RoundingMode) -> i8
fn shr_round(self, bits: u16, rm: RoundingMode) -> i8
Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode.
Passing RoundingMode::Floor
or RoundingMode::Down
is equivalent to
using >>
. To test whether RoundingMode::Exact
can be passed, use
self.divisible_by_power_of_2(bits)
.
Let $q = \frac{x}{2^p}$:
$f(x, p, \mathrm{Down}) = f(x, y, \mathrm{Floor}) = \lfloor q \rfloor.$
$f(x, p, \mathrm{Up}) = f(x, y, \mathrm{Ceiling}) = \lceil q \rceil.$
$$ f(x, p, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd}. \end{cases} $$
$f(x, p, \mathrm{Exact}) = q$, but panics if $q \notin \N$.
Worst-case complexity
Constant time and additional memory.
Panics
Panics if rm
is RoundingMode::Exact
but self
is not divisible by
$2^b$.
Examples
See here.
type Output = i8
sourceimpl ShrRound<u32> for i8
impl ShrRound<u32> for i8
sourcefn shr_round(self, bits: u32, rm: RoundingMode) -> i8
fn shr_round(self, bits: u32, rm: RoundingMode) -> i8
Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode.
Passing RoundingMode::Floor
or RoundingMode::Down
is equivalent to
using >>
. To test whether RoundingMode::Exact
can be passed, use
self.divisible_by_power_of_2(bits)
.
Let $q = \frac{x}{2^p}$:
$f(x, p, \mathrm{Down}) = f(x, y, \mathrm{Floor}) = \lfloor q \rfloor.$
$f(x, p, \mathrm{Up}) = f(x, y, \mathrm{Ceiling}) = \lceil q \rceil.$
$$ f(x, p, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd}. \end{cases} $$
$f(x, p, \mathrm{Exact}) = q$, but panics if $q \notin \N$.
Worst-case complexity
Constant time and additional memory.
Panics
Panics if rm
is RoundingMode::Exact
but self
is not divisible by
$2^b$.
Examples
See here.
type Output = i8
sourceimpl ShrRound<u64> for i8
impl ShrRound<u64> for i8
sourcefn shr_round(self, bits: u64, rm: RoundingMode) -> i8
fn shr_round(self, bits: u64, rm: RoundingMode) -> i8
Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode.
Passing RoundingMode::Floor
or RoundingMode::Down
is equivalent to
using >>
. To test whether RoundingMode::Exact
can be passed, use
self.divisible_by_power_of_2(bits)
.
Let $q = \frac{x}{2^p}$:
$f(x, p, \mathrm{Down}) = f(x, y, \mathrm{Floor}) = \lfloor q \rfloor.$
$f(x, p, \mathrm{Up}) = f(x, y, \mathrm{Ceiling}) = \lceil q \rceil.$
$$ f(x, p, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd}. \end{cases} $$
$f(x, p, \mathrm{Exact}) = q$, but panics if $q \notin \N$.
Worst-case complexity
Constant time and additional memory.
Panics
Panics if rm
is RoundingMode::Exact
but self
is not divisible by
$2^b$.
Examples
See here.
type Output = i8
sourceimpl ShrRound<u128> for i8
impl ShrRound<u128> for i8
sourcefn shr_round(self, bits: u128, rm: RoundingMode) -> i8
fn shr_round(self, bits: u128, rm: RoundingMode) -> i8
Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode.
Passing RoundingMode::Floor
or RoundingMode::Down
is equivalent to
using >>
. To test whether RoundingMode::Exact
can be passed, use
self.divisible_by_power_of_2(bits)
.
Let $q = \frac{x}{2^p}$:
$f(x, p, \mathrm{Down}) = f(x, y, \mathrm{Floor}) = \lfloor q \rfloor.$
$f(x, p, \mathrm{Up}) = f(x, y, \mathrm{Ceiling}) = \lceil q \rceil.$
$$ f(x, p, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd}. \end{cases} $$
$f(x, p, \mathrm{Exact}) = q$, but panics if $q \notin \N$.
Worst-case complexity
Constant time and additional memory.
Panics
Panics if rm
is RoundingMode::Exact
but self
is not divisible by
$2^b$.
Examples
See here.
type Output = i8
sourceimpl ShrRound<usize> for i8
impl ShrRound<usize> for i8
sourcefn shr_round(self, bits: usize, rm: RoundingMode) -> i8
fn shr_round(self, bits: usize, rm: RoundingMode) -> i8
Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode.
Passing RoundingMode::Floor
or RoundingMode::Down
is equivalent to
using >>
. To test whether RoundingMode::Exact
can be passed, use
self.divisible_by_power_of_2(bits)
.
Let $q = \frac{x}{2^p}$:
$f(x, p, \mathrm{Down}) = f(x, y, \mathrm{Floor}) = \lfloor q \rfloor.$
$f(x, p, \mathrm{Up}) = f(x, y, \mathrm{Ceiling}) = \lceil q \rceil.$
$$ f(x, p, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd}. \end{cases} $$
$f(x, p, \mathrm{Exact}) = q$, but panics if $q \notin \N$.
Worst-case complexity
Constant time and additional memory.
Panics
Panics if rm
is RoundingMode::Exact
but self
is not divisible by
$2^b$.
Examples
See here.
type Output = i8
sourceimpl ShrRound<u8> for i16
impl ShrRound<u8> for i16
sourcefn shr_round(self, bits: u8, rm: RoundingMode) -> i16
fn shr_round(self, bits: u8, rm: RoundingMode) -> i16
Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode.
Passing RoundingMode::Floor
or RoundingMode::Down
is equivalent to
using >>
. To test whether RoundingMode::Exact
can be passed, use
self.divisible_by_power_of_2(bits)
.
Let $q = \frac{x}{2^p}$:
$f(x, p, \mathrm{Down}) = f(x, y, \mathrm{Floor}) = \lfloor q \rfloor.$
$f(x, p, \mathrm{Up}) = f(x, y, \mathrm{Ceiling}) = \lceil q \rceil.$
$$ f(x, p, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd}. \end{cases} $$
$f(x, p, \mathrm{Exact}) = q$, but panics if $q \notin \N$.
Worst-case complexity
Constant time and additional memory.
Panics
Panics if rm
is RoundingMode::Exact
but self
is not divisible by
$2^b$.
Examples
See here.
type Output = i16
sourceimpl ShrRound<u16> for i16
impl ShrRound<u16> for i16
sourcefn shr_round(self, bits: u16, rm: RoundingMode) -> i16
fn shr_round(self, bits: u16, rm: RoundingMode) -> i16
Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode.
Passing RoundingMode::Floor
or RoundingMode::Down
is equivalent to
using >>
. To test whether RoundingMode::Exact
can be passed, use
self.divisible_by_power_of_2(bits)
.
Let $q = \frac{x}{2^p}$:
$f(x, p, \mathrm{Down}) = f(x, y, \mathrm{Floor}) = \lfloor q \rfloor.$
$f(x, p, \mathrm{Up}) = f(x, y, \mathrm{Ceiling}) = \lceil q \rceil.$
$$ f(x, p, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd}. \end{cases} $$
$f(x, p, \mathrm{Exact}) = q$, but panics if $q \notin \N$.
Worst-case complexity
Constant time and additional memory.
Panics
Panics if rm
is RoundingMode::Exact
but self
is not divisible by
$2^b$.
Examples
See here.
type Output = i16
sourceimpl ShrRound<u32> for i16
impl ShrRound<u32> for i16
sourcefn shr_round(self, bits: u32, rm: RoundingMode) -> i16
fn shr_round(self, bits: u32, rm: RoundingMode) -> i16
Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode.
Passing RoundingMode::Floor
or RoundingMode::Down
is equivalent to
using >>
. To test whether RoundingMode::Exact
can be passed, use
self.divisible_by_power_of_2(bits)
.
Let $q = \frac{x}{2^p}$:
$f(x, p, \mathrm{Down}) = f(x, y, \mathrm{Floor}) = \lfloor q \rfloor.$
$f(x, p, \mathrm{Up}) = f(x, y, \mathrm{Ceiling}) = \lceil q \rceil.$
$$ f(x, p, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd}. \end{cases} $$
$f(x, p, \mathrm{Exact}) = q$, but panics if $q \notin \N$.
Worst-case complexity
Constant time and additional memory.
Panics
Panics if rm
is RoundingMode::Exact
but self
is not divisible by
$2^b$.
Examples
See here.
type Output = i16
sourceimpl ShrRound<u64> for i16
impl ShrRound<u64> for i16
sourcefn shr_round(self, bits: u64, rm: RoundingMode) -> i16
fn shr_round(self, bits: u64, rm: RoundingMode) -> i16
Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode.
Passing RoundingMode::Floor
or RoundingMode::Down
is equivalent to
using >>
. To test whether RoundingMode::Exact
can be passed, use
self.divisible_by_power_of_2(bits)
.
Let $q = \frac{x}{2^p}$:
$f(x, p, \mathrm{Down}) = f(x, y, \mathrm{Floor}) = \lfloor q \rfloor.$
$f(x, p, \mathrm{Up}) = f(x, y, \mathrm{Ceiling}) = \lceil q \rceil.$
$$ f(x, p, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd}. \end{cases} $$
$f(x, p, \mathrm{Exact}) = q$, but panics if $q \notin \N$.
Worst-case complexity
Constant time and additional memory.
Panics
Panics if rm
is RoundingMode::Exact
but self
is not divisible by
$2^b$.
Examples
See here.
type Output = i16
sourceimpl ShrRound<u128> for i16
impl ShrRound<u128> for i16
sourcefn shr_round(self, bits: u128, rm: RoundingMode) -> i16
fn shr_round(self, bits: u128, rm: RoundingMode) -> i16
Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode.
Passing RoundingMode::Floor
or RoundingMode::Down
is equivalent to
using >>
. To test whether RoundingMode::Exact
can be passed, use
self.divisible_by_power_of_2(bits)
.
Let $q = \frac{x}{2^p}$:
$f(x, p, \mathrm{Down}) = f(x, y, \mathrm{Floor}) = \lfloor q \rfloor.$
$f(x, p, \mathrm{Up}) = f(x, y, \mathrm{Ceiling}) = \lceil q \rceil.$
$$ f(x, p, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd}. \end{cases} $$
$f(x, p, \mathrm{Exact}) = q$, but panics if $q \notin \N$.
Worst-case complexity
Constant time and additional memory.
Panics
Panics if rm
is RoundingMode::Exact
but self
is not divisible by
$2^b$.
Examples
See here.
type Output = i16
sourceimpl ShrRound<usize> for i16
impl ShrRound<usize> for i16
sourcefn shr_round(self, bits: usize, rm: RoundingMode) -> i16
fn shr_round(self, bits: usize, rm: RoundingMode) -> i16
Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode.
Passing RoundingMode::Floor
or RoundingMode::Down
is equivalent to
using >>
. To test whether RoundingMode::Exact
can be passed, use
self.divisible_by_power_of_2(bits)
.
Let $q = \frac{x}{2^p}$:
$f(x, p, \mathrm{Down}) = f(x, y, \mathrm{Floor}) = \lfloor q \rfloor.$
$f(x, p, \mathrm{Up}) = f(x, y, \mathrm{Ceiling}) = \lceil q \rceil.$
$$ f(x, p, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd}. \end{cases} $$
$f(x, p, \mathrm{Exact}) = q$, but panics if $q \notin \N$.
Worst-case complexity
Constant time and additional memory.
Panics
Panics if rm
is RoundingMode::Exact
but self
is not divisible by
$2^b$.
Examples
See here.
type Output = i16
sourceimpl ShrRound<u8> for i32
impl ShrRound<u8> for i32
sourcefn shr_round(self, bits: u8, rm: RoundingMode) -> i32
fn shr_round(self, bits: u8, rm: RoundingMode) -> i32
Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode.
Passing RoundingMode::Floor
or RoundingMode::Down
is equivalent to
using >>
. To test whether RoundingMode::Exact
can be passed, use
self.divisible_by_power_of_2(bits)
.
Let $q = \frac{x}{2^p}$:
$f(x, p, \mathrm{Down}) = f(x, y, \mathrm{Floor}) = \lfloor q \rfloor.$
$f(x, p, \mathrm{Up}) = f(x, y, \mathrm{Ceiling}) = \lceil q \rceil.$
$$ f(x, p, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd}. \end{cases} $$
$f(x, p, \mathrm{Exact}) = q$, but panics if $q \notin \N$.
Worst-case complexity
Constant time and additional memory.
Panics
Panics if rm
is RoundingMode::Exact
but self
is not divisible by
$2^b$.
Examples
See here.
type Output = i32
sourceimpl ShrRound<u16> for i32
impl ShrRound<u16> for i32
sourcefn shr_round(self, bits: u16, rm: RoundingMode) -> i32
fn shr_round(self, bits: u16, rm: RoundingMode) -> i32
Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode.
Passing RoundingMode::Floor
or RoundingMode::Down
is equivalent to
using >>
. To test whether RoundingMode::Exact
can be passed, use
self.divisible_by_power_of_2(bits)
.
Let $q = \frac{x}{2^p}$:
$f(x, p, \mathrm{Down}) = f(x, y, \mathrm{Floor}) = \lfloor q \rfloor.$
$f(x, p, \mathrm{Up}) = f(x, y, \mathrm{Ceiling}) = \lceil q \rceil.$
$$ f(x, p, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd}. \end{cases} $$
$f(x, p, \mathrm{Exact}) = q$, but panics if $q \notin \N$.
Worst-case complexity
Constant time and additional memory.
Panics
Panics if rm
is RoundingMode::Exact
but self
is not divisible by
$2^b$.
Examples
See here.
type Output = i32
sourceimpl ShrRound<u32> for i32
impl ShrRound<u32> for i32
sourcefn shr_round(self, bits: u32, rm: RoundingMode) -> i32
fn shr_round(self, bits: u32, rm: RoundingMode) -> i32
Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode.
Passing RoundingMode::Floor
or RoundingMode::Down
is equivalent to
using >>
. To test whether RoundingMode::Exact
can be passed, use
self.divisible_by_power_of_2(bits)
.
Let $q = \frac{x}{2^p}$:
$f(x, p, \mathrm{Down}) = f(x, y, \mathrm{Floor}) = \lfloor q \rfloor.$
$f(x, p, \mathrm{Up}) = f(x, y, \mathrm{Ceiling}) = \lceil q \rceil.$
$$ f(x, p, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd}. \end{cases} $$
$f(x, p, \mathrm{Exact}) = q$, but panics if $q \notin \N$.
Worst-case complexity
Constant time and additional memory.
Panics
Panics if rm
is RoundingMode::Exact
but self
is not divisible by
$2^b$.
Examples
See here.
type Output = i32
sourceimpl ShrRound<u64> for i32
impl ShrRound<u64> for i32
sourcefn shr_round(self, bits: u64, rm: RoundingMode) -> i32
fn shr_round(self, bits: u64, rm: RoundingMode) -> i32
Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode.
Passing RoundingMode::Floor
or RoundingMode::Down
is equivalent to
using >>
. To test whether RoundingMode::Exact
can be passed, use
self.divisible_by_power_of_2(bits)
.
Let $q = \frac{x}{2^p}$:
$f(x, p, \mathrm{Down}) = f(x, y, \mathrm{Floor}) = \lfloor q \rfloor.$
$f(x, p, \mathrm{Up}) = f(x, y, \mathrm{Ceiling}) = \lceil q \rceil.$
$$ f(x, p, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd}. \end{cases} $$
$f(x, p, \mathrm{Exact}) = q$, but panics if $q \notin \N$.
Worst-case complexity
Constant time and additional memory.
Panics
Panics if rm
is RoundingMode::Exact
but self
is not divisible by
$2^b$.
Examples
See here.
type Output = i32
sourceimpl ShrRound<u128> for i32
impl ShrRound<u128> for i32
sourcefn shr_round(self, bits: u128, rm: RoundingMode) -> i32
fn shr_round(self, bits: u128, rm: RoundingMode) -> i32
Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode.
Passing RoundingMode::Floor
or RoundingMode::Down
is equivalent to
using >>
. To test whether RoundingMode::Exact
can be passed, use
self.divisible_by_power_of_2(bits)
.
Let $q = \frac{x}{2^p}$:
$f(x, p, \mathrm{Down}) = f(x, y, \mathrm{Floor}) = \lfloor q \rfloor.$
$f(x, p, \mathrm{Up}) = f(x, y, \mathrm{Ceiling}) = \lceil q \rceil.$
$$ f(x, p, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd}. \end{cases} $$
$f(x, p, \mathrm{Exact}) = q$, but panics if $q \notin \N$.
Worst-case complexity
Constant time and additional memory.
Panics
Panics if rm
is RoundingMode::Exact
but self
is not divisible by
$2^b$.
Examples
See here.
type Output = i32
sourceimpl ShrRound<usize> for i32
impl ShrRound<usize> for i32
sourcefn shr_round(self, bits: usize, rm: RoundingMode) -> i32
fn shr_round(self, bits: usize, rm: RoundingMode) -> i32
Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode.
Passing RoundingMode::Floor
or RoundingMode::Down
is equivalent to
using >>
. To test whether RoundingMode::Exact
can be passed, use
self.divisible_by_power_of_2(bits)
.
Let $q = \frac{x}{2^p}$:
$f(x, p, \mathrm{Down}) = f(x, y, \mathrm{Floor}) = \lfloor q \rfloor.$
$f(x, p, \mathrm{Up}) = f(x, y, \mathrm{Ceiling}) = \lceil q \rceil.$
$$ f(x, p, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd}. \end{cases} $$
$f(x, p, \mathrm{Exact}) = q$, but panics if $q \notin \N$.
Worst-case complexity
Constant time and additional memory.
Panics
Panics if rm
is RoundingMode::Exact
but self
is not divisible by
$2^b$.
Examples
See here.
type Output = i32
sourceimpl ShrRound<u8> for i64
impl ShrRound<u8> for i64
sourcefn shr_round(self, bits: u8, rm: RoundingMode) -> i64
fn shr_round(self, bits: u8, rm: RoundingMode) -> i64
Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode.
Passing RoundingMode::Floor
or RoundingMode::Down
is equivalent to
using >>
. To test whether RoundingMode::Exact
can be passed, use
self.divisible_by_power_of_2(bits)
.
Let $q = \frac{x}{2^p}$:
$f(x, p, \mathrm{Down}) = f(x, y, \mathrm{Floor}) = \lfloor q \rfloor.$
$f(x, p, \mathrm{Up}) = f(x, y, \mathrm{Ceiling}) = \lceil q \rceil.$
$$ f(x, p, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd}. \end{cases} $$
$f(x, p, \mathrm{Exact}) = q$, but panics if $q \notin \N$.
Worst-case complexity
Constant time and additional memory.
Panics
Panics if rm
is RoundingMode::Exact
but self
is not divisible by
$2^b$.
Examples
See here.
type Output = i64
sourceimpl ShrRound<u16> for i64
impl ShrRound<u16> for i64
sourcefn shr_round(self, bits: u16, rm: RoundingMode) -> i64
fn shr_round(self, bits: u16, rm: RoundingMode) -> i64
Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode.
Passing RoundingMode::Floor
or RoundingMode::Down
is equivalent to
using >>
. To test whether RoundingMode::Exact
can be passed, use
self.divisible_by_power_of_2(bits)
.
Let $q = \frac{x}{2^p}$:
$f(x, p, \mathrm{Down}) = f(x, y, \mathrm{Floor}) = \lfloor q \rfloor.$
$f(x, p, \mathrm{Up}) = f(x, y, \mathrm{Ceiling}) = \lceil q \rceil.$
$$ f(x, p, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd}. \end{cases} $$
$f(x, p, \mathrm{Exact}) = q$, but panics if $q \notin \N$.
Worst-case complexity
Constant time and additional memory.
Panics
Panics if rm
is RoundingMode::Exact
but self
is not divisible by
$2^b$.
Examples
See here.
type Output = i64
sourceimpl ShrRound<u32> for i64
impl ShrRound<u32> for i64
sourcefn shr_round(self, bits: u32, rm: RoundingMode) -> i64
fn shr_round(self, bits: u32, rm: RoundingMode) -> i64
Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode.
Passing RoundingMode::Floor
or RoundingMode::Down
is equivalent to
using >>
. To test whether RoundingMode::Exact
can be passed, use
self.divisible_by_power_of_2(bits)
.
Let $q = \frac{x}{2^p}$:
$f(x, p, \mathrm{Down}) = f(x, y, \mathrm{Floor}) = \lfloor q \rfloor.$
$f(x, p, \mathrm{Up}) = f(x, y, \mathrm{Ceiling}) = \lceil q \rceil.$
$$ f(x, p, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd}. \end{cases} $$
$f(x, p, \mathrm{Exact}) = q$, but panics if $q \notin \N$.
Worst-case complexity
Constant time and additional memory.
Panics
Panics if rm
is RoundingMode::Exact
but self
is not divisible by
$2^b$.
Examples
See here.
type Output = i64
sourceimpl ShrRound<u64> for i64
impl ShrRound<u64> for i64
sourcefn shr_round(self, bits: u64, rm: RoundingMode) -> i64
fn shr_round(self, bits: u64, rm: RoundingMode) -> i64
Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode.
Passing RoundingMode::Floor
or RoundingMode::Down
is equivalent to
using >>
. To test whether RoundingMode::Exact
can be passed, use
self.divisible_by_power_of_2(bits)
.
Let $q = \frac{x}{2^p}$:
$f(x, p, \mathrm{Down}) = f(x, y, \mathrm{Floor}) = \lfloor q \rfloor.$
$f(x, p, \mathrm{Up}) = f(x, y, \mathrm{Ceiling}) = \lceil q \rceil.$
$$ f(x, p, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd}. \end{cases} $$
$f(x, p, \mathrm{Exact}) = q$, but panics if $q \notin \N$.
Worst-case complexity
Constant time and additional memory.
Panics
Panics if rm
is RoundingMode::Exact
but self
is not divisible by
$2^b$.
Examples
See here.
type Output = i64
sourceimpl ShrRound<u128> for i64
impl ShrRound<u128> for i64
sourcefn shr_round(self, bits: u128, rm: RoundingMode) -> i64
fn shr_round(self, bits: u128, rm: RoundingMode) -> i64
Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode.
Passing RoundingMode::Floor
or RoundingMode::Down
is equivalent to
using >>
. To test whether RoundingMode::Exact
can be passed, use
self.divisible_by_power_of_2(bits)
.
Let $q = \frac{x}{2^p}$:
$f(x, p, \mathrm{Down}) = f(x, y, \mathrm{Floor}) = \lfloor q \rfloor.$
$f(x, p, \mathrm{Up}) = f(x, y, \mathrm{Ceiling}) = \lceil q \rceil.$
$$ f(x, p, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd}. \end{cases} $$
$f(x, p, \mathrm{Exact}) = q$, but panics if $q \notin \N$.
Worst-case complexity
Constant time and additional memory.
Panics
Panics if rm
is RoundingMode::Exact
but self
is not divisible by
$2^b$.
Examples
See here.
type Output = i64
sourceimpl ShrRound<usize> for i64
impl ShrRound<usize> for i64
sourcefn shr_round(self, bits: usize, rm: RoundingMode) -> i64
fn shr_round(self, bits: usize, rm: RoundingMode) -> i64
Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode.
Passing RoundingMode::Floor
or RoundingMode::Down
is equivalent to
using >>
. To test whether RoundingMode::Exact
can be passed, use
self.divisible_by_power_of_2(bits)
.
Let $q = \frac{x}{2^p}$:
$f(x, p, \mathrm{Down}) = f(x, y, \mathrm{Floor}) = \lfloor q \rfloor.$
$f(x, p, \mathrm{Up}) = f(x, y, \mathrm{Ceiling}) = \lceil q \rceil.$
$$ f(x, p, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd}. \end{cases} $$
$f(x, p, \mathrm{Exact}) = q$, but panics if $q \notin \N$.
Worst-case complexity
Constant time and additional memory.
Panics
Panics if rm
is RoundingMode::Exact
but self
is not divisible by
$2^b$.
Examples
See here.
type Output = i64
sourceimpl ShrRound<u8> for i128
impl ShrRound<u8> for i128
sourcefn shr_round(self, bits: u8, rm: RoundingMode) -> i128
fn shr_round(self, bits: u8, rm: RoundingMode) -> i128
Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode.
Passing RoundingMode::Floor
or RoundingMode::Down
is equivalent to
using >>
. To test whether RoundingMode::Exact
can be passed, use
self.divisible_by_power_of_2(bits)
.
Let $q = \frac{x}{2^p}$:
$f(x, p, \mathrm{Down}) = f(x, y, \mathrm{Floor}) = \lfloor q \rfloor.$
$f(x, p, \mathrm{Up}) = f(x, y, \mathrm{Ceiling}) = \lceil q \rceil.$
$$ f(x, p, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd}. \end{cases} $$
$f(x, p, \mathrm{Exact}) = q$, but panics if $q \notin \N$.
Worst-case complexity
Constant time and additional memory.
Panics
Panics if rm
is RoundingMode::Exact
but self
is not divisible by
$2^b$.
Examples
See here.
type Output = i128
sourceimpl ShrRound<u16> for i128
impl ShrRound<u16> for i128
sourcefn shr_round(self, bits: u16, rm: RoundingMode) -> i128
fn shr_round(self, bits: u16, rm: RoundingMode) -> i128
Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode.
Passing RoundingMode::Floor
or RoundingMode::Down
is equivalent to
using >>
. To test whether RoundingMode::Exact
can be passed, use
self.divisible_by_power_of_2(bits)
.
Let $q = \frac{x}{2^p}$:
$f(x, p, \mathrm{Down}) = f(x, y, \mathrm{Floor}) = \lfloor q \rfloor.$
$f(x, p, \mathrm{Up}) = f(x, y, \mathrm{Ceiling}) = \lceil q \rceil.$
$$ f(x, p, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd}. \end{cases} $$
$f(x, p, \mathrm{Exact}) = q$, but panics if $q \notin \N$.
Worst-case complexity
Constant time and additional memory.
Panics
Panics if rm
is RoundingMode::Exact
but self
is not divisible by
$2^b$.
Examples
See here.
type Output = i128
sourceimpl ShrRound<u32> for i128
impl ShrRound<u32> for i128
sourcefn shr_round(self, bits: u32, rm: RoundingMode) -> i128
fn shr_round(self, bits: u32, rm: RoundingMode) -> i128
Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode.
Passing RoundingMode::Floor
or RoundingMode::Down
is equivalent to
using >>
. To test whether RoundingMode::Exact
can be passed, use
self.divisible_by_power_of_2(bits)
.
Let $q = \frac{x}{2^p}$:
$f(x, p, \mathrm{Down}) = f(x, y, \mathrm{Floor}) = \lfloor q \rfloor.$
$f(x, p, \mathrm{Up}) = f(x, y, \mathrm{Ceiling}) = \lceil q \rceil.$
$$ f(x, p, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd}. \end{cases} $$
$f(x, p, \mathrm{Exact}) = q$, but panics if $q \notin \N$.
Worst-case complexity
Constant time and additional memory.
Panics
Panics if rm
is RoundingMode::Exact
but self
is not divisible by
$2^b$.
Examples
See here.
type Output = i128
sourceimpl ShrRound<u64> for i128
impl ShrRound<u64> for i128
sourcefn shr_round(self, bits: u64, rm: RoundingMode) -> i128
fn shr_round(self, bits: u64, rm: RoundingMode) -> i128
Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode.
Passing RoundingMode::Floor
or RoundingMode::Down
is equivalent to
using >>
. To test whether RoundingMode::Exact
can be passed, use
self.divisible_by_power_of_2(bits)
.
Let $q = \frac{x}{2^p}$:
$f(x, p, \mathrm{Down}) = f(x, y, \mathrm{Floor}) = \lfloor q \rfloor.$
$f(x, p, \mathrm{Up}) = f(x, y, \mathrm{Ceiling}) = \lceil q \rceil.$
$$ f(x, p, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd}. \end{cases} $$
$f(x, p, \mathrm{Exact}) = q$, but panics if $q \notin \N$.
Worst-case complexity
Constant time and additional memory.
Panics
Panics if rm
is RoundingMode::Exact
but self
is not divisible by
$2^b$.
Examples
See here.
type Output = i128
sourceimpl ShrRound<u128> for i128
impl ShrRound<u128> for i128
sourcefn shr_round(self, bits: u128, rm: RoundingMode) -> i128
fn shr_round(self, bits: u128, rm: RoundingMode) -> i128
Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode.
Passing RoundingMode::Floor
or RoundingMode::Down
is equivalent to
using >>
. To test whether RoundingMode::Exact
can be passed, use
self.divisible_by_power_of_2(bits)
.
Let $q = \frac{x}{2^p}$:
$f(x, p, \mathrm{Down}) = f(x, y, \mathrm{Floor}) = \lfloor q \rfloor.$
$f(x, p, \mathrm{Up}) = f(x, y, \mathrm{Ceiling}) = \lceil q \rceil.$
$$ f(x, p, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd}. \end{cases} $$
$f(x, p, \mathrm{Exact}) = q$, but panics if $q \notin \N$.
Worst-case complexity
Constant time and additional memory.
Panics
Panics if rm
is RoundingMode::Exact
but self
is not divisible by
$2^b$.
Examples
See here.
type Output = i128
sourceimpl ShrRound<usize> for i128
impl ShrRound<usize> for i128
sourcefn shr_round(self, bits: usize, rm: RoundingMode) -> i128
fn shr_round(self, bits: usize, rm: RoundingMode) -> i128
Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode.
Passing RoundingMode::Floor
or RoundingMode::Down
is equivalent to
using >>
. To test whether RoundingMode::Exact
can be passed, use
self.divisible_by_power_of_2(bits)
.
Let $q = \frac{x}{2^p}$:
$f(x, p, \mathrm{Down}) = f(x, y, \mathrm{Floor}) = \lfloor q \rfloor.$
$f(x, p, \mathrm{Up}) = f(x, y, \mathrm{Ceiling}) = \lceil q \rceil.$
$$ f(x, p, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd}. \end{cases} $$
$f(x, p, \mathrm{Exact}) = q$, but panics if $q \notin \N$.
Worst-case complexity
Constant time and additional memory.
Panics
Panics if rm
is RoundingMode::Exact
but self
is not divisible by
$2^b$.
Examples
See here.
type Output = i128
sourceimpl ShrRound<u8> for isize
impl ShrRound<u8> for isize
sourcefn shr_round(self, bits: u8, rm: RoundingMode) -> isize
fn shr_round(self, bits: u8, rm: RoundingMode) -> isize
Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode.
Passing RoundingMode::Floor
or RoundingMode::Down
is equivalent to
using >>
. To test whether RoundingMode::Exact
can be passed, use
self.divisible_by_power_of_2(bits)
.
Let $q = \frac{x}{2^p}$:
$f(x, p, \mathrm{Down}) = f(x, y, \mathrm{Floor}) = \lfloor q \rfloor.$
$f(x, p, \mathrm{Up}) = f(x, y, \mathrm{Ceiling}) = \lceil q \rceil.$
$$ f(x, p, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd}. \end{cases} $$
$f(x, p, \mathrm{Exact}) = q$, but panics if $q \notin \N$.
Worst-case complexity
Constant time and additional memory.
Panics
Panics if rm
is RoundingMode::Exact
but self
is not divisible by
$2^b$.
Examples
See here.
type Output = isize
sourceimpl ShrRound<u16> for isize
impl ShrRound<u16> for isize
sourcefn shr_round(self, bits: u16, rm: RoundingMode) -> isize
fn shr_round(self, bits: u16, rm: RoundingMode) -> isize
Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode.
Passing RoundingMode::Floor
or RoundingMode::Down
is equivalent to
using >>
. To test whether RoundingMode::Exact
can be passed, use
self.divisible_by_power_of_2(bits)
.
Let $q = \frac{x}{2^p}$:
$f(x, p, \mathrm{Down}) = f(x, y, \mathrm{Floor}) = \lfloor q \rfloor.$
$f(x, p, \mathrm{Up}) = f(x, y, \mathrm{Ceiling}) = \lceil q \rceil.$
$$ f(x, p, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd}. \end{cases} $$
$f(x, p, \mathrm{Exact}) = q$, but panics if $q \notin \N$.
Worst-case complexity
Constant time and additional memory.
Panics
Panics if rm
is RoundingMode::Exact
but self
is not divisible by
$2^b$.
Examples
See here.
type Output = isize
sourceimpl ShrRound<u32> for isize
impl ShrRound<u32> for isize
sourcefn shr_round(self, bits: u32, rm: RoundingMode) -> isize
fn shr_round(self, bits: u32, rm: RoundingMode) -> isize
Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode.
Passing RoundingMode::Floor
or RoundingMode::Down
is equivalent to
using >>
. To test whether RoundingMode::Exact
can be passed, use
self.divisible_by_power_of_2(bits)
.
Let $q = \frac{x}{2^p}$:
$f(x, p, \mathrm{Down}) = f(x, y, \mathrm{Floor}) = \lfloor q \rfloor.$
$f(x, p, \mathrm{Up}) = f(x, y, \mathrm{Ceiling}) = \lceil q \rceil.$
$$ f(x, p, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd}. \end{cases} $$
$f(x, p, \mathrm{Exact}) = q$, but panics if $q \notin \N$.
Worst-case complexity
Constant time and additional memory.
Panics
Panics if rm
is RoundingMode::Exact
but self
is not divisible by
$2^b$.
Examples
See here.
type Output = isize
sourceimpl ShrRound<u64> for isize
impl ShrRound<u64> for isize
sourcefn shr_round(self, bits: u64, rm: RoundingMode) -> isize
fn shr_round(self, bits: u64, rm: RoundingMode) -> isize
Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode.
Passing RoundingMode::Floor
or RoundingMode::Down
is equivalent to
using >>
. To test whether RoundingMode::Exact
can be passed, use
self.divisible_by_power_of_2(bits)
.
Let $q = \frac{x}{2^p}$:
$f(x, p, \mathrm{Down}) = f(x, y, \mathrm{Floor}) = \lfloor q \rfloor.$
$f(x, p, \mathrm{Up}) = f(x, y, \mathrm{Ceiling}) = \lceil q \rceil.$
$$ f(x, p, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd}. \end{cases} $$
$f(x, p, \mathrm{Exact}) = q$, but panics if $q \notin \N$.
Worst-case complexity
Constant time and additional memory.
Panics
Panics if rm
is RoundingMode::Exact
but self
is not divisible by
$2^b$.
Examples
See here.
type Output = isize
sourceimpl ShrRound<u128> for isize
impl ShrRound<u128> for isize
sourcefn shr_round(self, bits: u128, rm: RoundingMode) -> isize
fn shr_round(self, bits: u128, rm: RoundingMode) -> isize
Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode.
Passing RoundingMode::Floor
or RoundingMode::Down
is equivalent to
using >>
. To test whether RoundingMode::Exact
can be passed, use
self.divisible_by_power_of_2(bits)
.
Let $q = \frac{x}{2^p}$:
$f(x, p, \mathrm{Down}) = f(x, y, \mathrm{Floor}) = \lfloor q \rfloor.$
$f(x, p, \mathrm{Up}) = f(x, y, \mathrm{Ceiling}) = \lceil q \rceil.$
$$ f(x, p, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd}. \end{cases} $$
$f(x, p, \mathrm{Exact}) = q$, but panics if $q \notin \N$.
Worst-case complexity
Constant time and additional memory.
Panics
Panics if rm
is RoundingMode::Exact
but self
is not divisible by
$2^b$.
Examples
See here.
type Output = isize
sourceimpl ShrRound<usize> for isize
impl ShrRound<usize> for isize
sourcefn shr_round(self, bits: usize, rm: RoundingMode) -> isize
fn shr_round(self, bits: usize, rm: RoundingMode) -> isize
Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode.
Passing RoundingMode::Floor
or RoundingMode::Down
is equivalent to
using >>
. To test whether RoundingMode::Exact
can be passed, use
self.divisible_by_power_of_2(bits)
.
Let $q = \frac{x}{2^p}$:
$f(x, p, \mathrm{Down}) = f(x, y, \mathrm{Floor}) = \lfloor q \rfloor.$
$f(x, p, \mathrm{Up}) = f(x, y, \mathrm{Ceiling}) = \lceil q \rceil.$
$$ f(x, p, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd}. \end{cases} $$
$f(x, p, \mathrm{Exact}) = q$, but panics if $q \notin \N$.
Worst-case complexity
Constant time and additional memory.
Panics
Panics if rm
is RoundingMode::Exact
but self
is not divisible by
$2^b$.
Examples
See here.
type Output = isize
sourceimpl ShrRound<i8> for u8
impl ShrRound<i8> for u8
sourcefn shr_round(self, bits: i8, rm: RoundingMode) -> u8
fn shr_round(self, bits: i8, rm: RoundingMode) -> u8
Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode.
Passing RoundingMode::Floor
or RoundingMode::Down
is equivalent to
using >>
. To test whether RoundingMode::Exact
can be passed, use
self.divisible_by_power_of_2(bits)
. Rounding might only be necessary if
bits
is non-negative.
Let $q = \frac{x}{2^p}$:
$f(x, p, \mathrm{Down}) = \operatorname{sgn}(q) \lfloor |q| \rfloor.$
$f(x, p, \mathrm{Up}) = \operatorname{sgn}(q) \lceil |q| \rceil.$
$f(x, p, \mathrm{Floor}) = \lfloor q \rfloor.$
$f(x, p, \mathrm{Ceiling}) = \lceil q \rceil.$
$$ f(x, p, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd}. \end{cases} $$
$f(x, p, \mathrm{Exact}) = q$, but panics if $q \notin \Z$.
Worst-case complexity
Constant time and additional memory.
Panics
Panics if bits
is positive and rm
is RoundingMode::Exact
but self
is
not divisible by $2^b$.
Examples
See here.
type Output = u8
sourceimpl ShrRound<i16> for u8
impl ShrRound<i16> for u8
sourcefn shr_round(self, bits: i16, rm: RoundingMode) -> u8
fn shr_round(self, bits: i16, rm: RoundingMode) -> u8
Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode.
Passing RoundingMode::Floor
or RoundingMode::Down
is equivalent to
using >>
. To test whether RoundingMode::Exact
can be passed, use
self.divisible_by_power_of_2(bits)
. Rounding might only be necessary if
bits
is non-negative.
Let $q = \frac{x}{2^p}$:
$f(x, p, \mathrm{Down}) = \operatorname{sgn}(q) \lfloor |q| \rfloor.$
$f(x, p, \mathrm{Up}) = \operatorname{sgn}(q) \lceil |q| \rceil.$
$f(x, p, \mathrm{Floor}) = \lfloor q \rfloor.$
$f(x, p, \mathrm{Ceiling}) = \lceil q \rceil.$
$$ f(x, p, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd}. \end{cases} $$
$f(x, p, \mathrm{Exact}) = q$, but panics if $q \notin \Z$.
Worst-case complexity
Constant time and additional memory.
Panics
Panics if bits
is positive and rm
is RoundingMode::Exact
but self
is
not divisible by $2^b$.
Examples
See here.
type Output = u8
sourceimpl ShrRound<i32> for u8
impl ShrRound<i32> for u8
sourcefn shr_round(self, bits: i32, rm: RoundingMode) -> u8
fn shr_round(self, bits: i32, rm: RoundingMode) -> u8
Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode.
Passing RoundingMode::Floor
or RoundingMode::Down
is equivalent to
using >>
. To test whether RoundingMode::Exact
can be passed, use
self.divisible_by_power_of_2(bits)
. Rounding might only be necessary if
bits
is non-negative.
Let $q = \frac{x}{2^p}$:
$f(x, p, \mathrm{Down}) = \operatorname{sgn}(q) \lfloor |q| \rfloor.$
$f(x, p, \mathrm{Up}) = \operatorname{sgn}(q) \lceil |q| \rceil.$
$f(x, p, \mathrm{Floor}) = \lfloor q \rfloor.$
$f(x, p, \mathrm{Ceiling}) = \lceil q \rceil.$
$$ f(x, p, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd}. \end{cases} $$
$f(x, p, \mathrm{Exact}) = q$, but panics if $q \notin \Z$.
Worst-case complexity
Constant time and additional memory.
Panics
Panics if bits
is positive and rm
is RoundingMode::Exact
but self
is
not divisible by $2^b$.
Examples
See here.
type Output = u8
sourceimpl ShrRound<i64> for u8
impl ShrRound<i64> for u8
sourcefn shr_round(self, bits: i64, rm: RoundingMode) -> u8
fn shr_round(self, bits: i64, rm: RoundingMode) -> u8
Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode.
Passing RoundingMode::Floor
or RoundingMode::Down
is equivalent to
using >>
. To test whether RoundingMode::Exact
can be passed, use
self.divisible_by_power_of_2(bits)
. Rounding might only be necessary if
bits
is non-negative.
Let $q = \frac{x}{2^p}$:
$f(x, p, \mathrm{Down}) = \operatorname{sgn}(q) \lfloor |q| \rfloor.$
$f(x, p, \mathrm{Up}) = \operatorname{sgn}(q) \lceil |q| \rceil.$
$f(x, p, \mathrm{Floor}) = \lfloor q \rfloor.$
$f(x, p, \mathrm{Ceiling}) = \lceil q \rceil.$
$$ f(x, p, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd}. \end{cases} $$
$f(x, p, \mathrm{Exact}) = q$, but panics if $q \notin \Z$.
Worst-case complexity
Constant time and additional memory.
Panics
Panics if bits
is positive and rm
is RoundingMode::Exact
but self
is
not divisible by $2^b$.
Examples
See here.
type Output = u8
sourceimpl ShrRound<i128> for u8
impl ShrRound<i128> for u8
sourcefn shr_round(self, bits: i128, rm: RoundingMode) -> u8
fn shr_round(self, bits: i128, rm: RoundingMode) -> u8
Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode.
Passing RoundingMode::Floor
or RoundingMode::Down
is equivalent to
using >>
. To test whether RoundingMode::Exact
can be passed, use
self.divisible_by_power_of_2(bits)
. Rounding might only be necessary if
bits
is non-negative.
Let $q = \frac{x}{2^p}$:
$f(x, p, \mathrm{Down}) = \operatorname{sgn}(q) \lfloor |q| \rfloor.$
$f(x, p, \mathrm{Up}) = \operatorname{sgn}(q) \lceil |q| \rceil.$
$f(x, p, \mathrm{Floor}) = \lfloor q \rfloor.$
$f(x, p, \mathrm{Ceiling}) = \lceil q \rceil.$
$$ f(x, p, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd}. \end{cases} $$
$f(x, p, \mathrm{Exact}) = q$, but panics if $q \notin \Z$.
Worst-case complexity
Constant time and additional memory.
Panics
Panics if bits
is positive and rm
is RoundingMode::Exact
but self
is
not divisible by $2^b$.
Examples
See here.
type Output = u8
sourceimpl ShrRound<isize> for u8
impl ShrRound<isize> for u8
sourcefn shr_round(self, bits: isize, rm: RoundingMode) -> u8
fn shr_round(self, bits: isize, rm: RoundingMode) -> u8
Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode.
Passing RoundingMode::Floor
or RoundingMode::Down
is equivalent to
using >>
. To test whether RoundingMode::Exact
can be passed, use
self.divisible_by_power_of_2(bits)
. Rounding might only be necessary if
bits
is non-negative.
Let $q = \frac{x}{2^p}$:
$f(x, p, \mathrm{Down}) = \operatorname{sgn}(q) \lfloor |q| \rfloor.$
$f(x, p, \mathrm{Up}) = \operatorname{sgn}(q) \lceil |q| \rceil.$
$f(x, p, \mathrm{Floor}) = \lfloor q \rfloor.$
$f(x, p, \mathrm{Ceiling}) = \lceil q \rceil.$
$$ f(x, p, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd}. \end{cases} $$
$f(x, p, \mathrm{Exact}) = q$, but panics if $q \notin \Z$.
Worst-case complexity
Constant time and additional memory.
Panics
Panics if bits
is positive and rm
is RoundingMode::Exact
but self
is
not divisible by $2^b$.
Examples
See here.
type Output = u8
sourceimpl ShrRound<i8> for u16
impl ShrRound<i8> for u16
sourcefn shr_round(self, bits: i8, rm: RoundingMode) -> u16
fn shr_round(self, bits: i8, rm: RoundingMode) -> u16
Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode.
Passing RoundingMode::Floor
or RoundingMode::Down
is equivalent to
using >>
. To test whether RoundingMode::Exact
can be passed, use
self.divisible_by_power_of_2(bits)
. Rounding might only be necessary if
bits
is non-negative.
Let $q = \frac{x}{2^p}$:
$f(x, p, \mathrm{Down}) = \operatorname{sgn}(q) \lfloor |q| \rfloor.$
$f(x, p, \mathrm{Up}) = \operatorname{sgn}(q) \lceil |q| \rceil.$
$f(x, p, \mathrm{Floor}) = \lfloor q \rfloor.$
$f(x, p, \mathrm{Ceiling}) = \lceil q \rceil.$
$$ f(x, p, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd}. \end{cases} $$
$f(x, p, \mathrm{Exact}) = q$, but panics if $q \notin \Z$.
Worst-case complexity
Constant time and additional memory.
Panics
Panics if bits
is positive and rm
is RoundingMode::Exact
but self
is
not divisible by $2^b$.
Examples
See here.
type Output = u16
sourceimpl ShrRound<i16> for u16
impl ShrRound<i16> for u16
sourcefn shr_round(self, bits: i16, rm: RoundingMode) -> u16
fn shr_round(self, bits: i16, rm: RoundingMode) -> u16
Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode.
Passing RoundingMode::Floor
or RoundingMode::Down
is equivalent to
using >>
. To test whether RoundingMode::Exact
can be passed, use
self.divisible_by_power_of_2(bits)
. Rounding might only be necessary if
bits
is non-negative.
Let $q = \frac{x}{2^p}$:
$f(x, p, \mathrm{Down}) = \operatorname{sgn}(q) \lfloor |q| \rfloor.$
$f(x, p, \mathrm{Up}) = \operatorname{sgn}(q) \lceil |q| \rceil.$
$f(x, p, \mathrm{Floor}) = \lfloor q \rfloor.$
$f(x, p, \mathrm{Ceiling}) = \lceil q \rceil.$
$$ f(x, p, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd}. \end{cases} $$
$f(x, p, \mathrm{Exact}) = q$, but panics if $q \notin \Z$.
Worst-case complexity
Constant time and additional memory.
Panics
Panics if bits
is positive and rm
is RoundingMode::Exact
but self
is
not divisible by $2^b$.
Examples
See here.
type Output = u16
sourceimpl ShrRound<i32> for u16
impl ShrRound<i32> for u16
sourcefn shr_round(self, bits: i32, rm: RoundingMode) -> u16
fn shr_round(self, bits: i32, rm: RoundingMode) -> u16
Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode.
Passing RoundingMode::Floor
or RoundingMode::Down
is equivalent to
using >>
. To test whether RoundingMode::Exact
can be passed, use
self.divisible_by_power_of_2(bits)
. Rounding might only be necessary if
bits
is non-negative.
Let $q = \frac{x}{2^p}$:
$f(x, p, \mathrm{Down}) = \operatorname{sgn}(q) \lfloor |q| \rfloor.$
$f(x, p, \mathrm{Up}) = \operatorname{sgn}(q) \lceil |q| \rceil.$
$f(x, p, \mathrm{Floor}) = \lfloor q \rfloor.$
$f(x, p, \mathrm{Ceiling}) = \lceil q \rceil.$
$$ f(x, p, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd}. \end{cases} $$
$f(x, p, \mathrm{Exact}) = q$, but panics if $q \notin \Z$.
Worst-case complexity
Constant time and additional memory.
Panics
Panics if bits
is positive and rm
is RoundingMode::Exact
but self
is
not divisible by $2^b$.
Examples
See here.
type Output = u16
sourceimpl ShrRound<i64> for u16
impl ShrRound<i64> for u16
sourcefn shr_round(self, bits: i64, rm: RoundingMode) -> u16
fn shr_round(self, bits: i64, rm: RoundingMode) -> u16
Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode.
Passing RoundingMode::Floor
or RoundingMode::Down
is equivalent to
using >>
. To test whether RoundingMode::Exact
can be passed, use
self.divisible_by_power_of_2(bits)
. Rounding might only be necessary if
bits
is non-negative.
Let $q = \frac{x}{2^p}$:
$f(x, p, \mathrm{Down}) = \operatorname{sgn}(q) \lfloor |q| \rfloor.$
$f(x, p, \mathrm{Up}) = \operatorname{sgn}(q) \lceil |q| \rceil.$
$f(x, p, \mathrm{Floor}) = \lfloor q \rfloor.$
$f(x, p, \mathrm{Ceiling}) = \lceil q \rceil.$
$$ f(x, p, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd}. \end{cases} $$
$f(x, p, \mathrm{Exact}) = q$, but panics if $q \notin \Z$.
Worst-case complexity
Constant time and additional memory.
Panics
Panics if bits
is positive and rm
is RoundingMode::Exact
but self
is
not divisible by $2^b$.
Examples
See here.
type Output = u16
sourceimpl ShrRound<i128> for u16
impl ShrRound<i128> for u16
sourcefn shr_round(self, bits: i128, rm: RoundingMode) -> u16
fn shr_round(self, bits: i128, rm: RoundingMode) -> u16
Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode.
Passing RoundingMode::Floor
or RoundingMode::Down
is equivalent to
using >>
. To test whether RoundingMode::Exact
can be passed, use
self.divisible_by_power_of_2(bits)
. Rounding might only be necessary if
bits
is non-negative.
Let $q = \frac{x}{2^p}$:
$f(x, p, \mathrm{Down}) = \operatorname{sgn}(q) \lfloor |q| \rfloor.$
$f(x, p, \mathrm{Up}) = \operatorname{sgn}(q) \lceil |q| \rceil.$
$f(x, p, \mathrm{Floor}) = \lfloor q \rfloor.$
$f(x, p, \mathrm{Ceiling}) = \lceil q \rceil.$
$$ f(x, p, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd}. \end{cases} $$
$f(x, p, \mathrm{Exact}) = q$, but panics if $q \notin \Z$.
Worst-case complexity
Constant time and additional memory.
Panics
Panics if bits
is positive and rm
is RoundingMode::Exact
but self
is
not divisible by $2^b$.
Examples
See here.
type Output = u16
sourceimpl ShrRound<isize> for u16
impl ShrRound<isize> for u16
sourcefn shr_round(self, bits: isize, rm: RoundingMode) -> u16
fn shr_round(self, bits: isize, rm: RoundingMode) -> u16
Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode.
Passing RoundingMode::Floor
or RoundingMode::Down
is equivalent to
using >>
. To test whether RoundingMode::Exact
can be passed, use
self.divisible_by_power_of_2(bits)
. Rounding might only be necessary if
bits
is non-negative.
Let $q = \frac{x}{2^p}$:
$f(x, p, \mathrm{Down}) = \operatorname{sgn}(q) \lfloor |q| \rfloor.$
$f(x, p, \mathrm{Up}) = \operatorname{sgn}(q) \lceil |q| \rceil.$
$f(x, p, \mathrm{Floor}) = \lfloor q \rfloor.$
$f(x, p, \mathrm{Ceiling}) = \lceil q \rceil.$
$$ f(x, p, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd}. \end{cases} $$
$f(x, p, \mathrm{Exact}) = q$, but panics if $q \notin \Z$.
Worst-case complexity
Constant time and additional memory.
Panics
Panics if bits
is positive and rm
is RoundingMode::Exact
but self
is
not divisible by $2^b$.
Examples
See here.
type Output = u16
sourceimpl ShrRound<i8> for u32
impl ShrRound<i8> for u32
sourcefn shr_round(self, bits: i8, rm: RoundingMode) -> u32
fn shr_round(self, bits: i8, rm: RoundingMode) -> u32
Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode.
Passing RoundingMode::Floor
or RoundingMode::Down
is equivalent to
using >>
. To test whether RoundingMode::Exact
can be passed, use
self.divisible_by_power_of_2(bits)
. Rounding might only be necessary if
bits
is non-negative.
Let $q = \frac{x}{2^p}$:
$f(x, p, \mathrm{Down}) = \operatorname{sgn}(q) \lfloor |q| \rfloor.$
$f(x, p, \mathrm{Up}) = \operatorname{sgn}(q) \lceil |q| \rceil.$
$f(x, p, \mathrm{Floor}) = \lfloor q \rfloor.$
$f(x, p, \mathrm{Ceiling}) = \lceil q \rceil.$
$$ f(x, p, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd}. \end{cases} $$
$f(x, p, \mathrm{Exact}) = q$, but panics if $q \notin \Z$.
Worst-case complexity
Constant time and additional memory.
Panics
Panics if bits
is positive and rm
is RoundingMode::Exact
but self
is
not divisible by $2^b$.
Examples
See here.
type Output = u32
sourceimpl ShrRound<i16> for u32
impl ShrRound<i16> for u32
sourcefn shr_round(self, bits: i16, rm: RoundingMode) -> u32
fn shr_round(self, bits: i16, rm: RoundingMode) -> u32
Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode.
Passing RoundingMode::Floor
or RoundingMode::Down
is equivalent to
using >>
. To test whether RoundingMode::Exact
can be passed, use
self.divisible_by_power_of_2(bits)
. Rounding might only be necessary if
bits
is non-negative.
Let $q = \frac{x}{2^p}$:
$f(x, p, \mathrm{Down}) = \operatorname{sgn}(q) \lfloor |q| \rfloor.$
$f(x, p, \mathrm{Up}) = \operatorname{sgn}(q) \lceil |q| \rceil.$
$f(x, p, \mathrm{Floor}) = \lfloor q \rfloor.$
$f(x, p, \mathrm{Ceiling}) = \lceil q \rceil.$
$$ f(x, p, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd}. \end{cases} $$
$f(x, p, \mathrm{Exact}) = q$, but panics if $q \notin \Z$.
Worst-case complexity
Constant time and additional memory.
Panics
Panics if bits
is positive and rm
is RoundingMode::Exact
but self
is
not divisible by $2^b$.
Examples
See here.
type Output = u32
sourceimpl ShrRound<i32> for u32
impl ShrRound<i32> for u32
sourcefn shr_round(self, bits: i32, rm: RoundingMode) -> u32
fn shr_round(self, bits: i32, rm: RoundingMode) -> u32
Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode.
Passing RoundingMode::Floor
or RoundingMode::Down
is equivalent to
using >>
. To test whether RoundingMode::Exact
can be passed, use
self.divisible_by_power_of_2(bits)
. Rounding might only be necessary if
bits
is non-negative.
Let $q = \frac{x}{2^p}$:
$f(x, p, \mathrm{Down}) = \operatorname{sgn}(q) \lfloor |q| \rfloor.$
$f(x, p, \mathrm{Up}) = \operatorname{sgn}(q) \lceil |q| \rceil.$
$f(x, p, \mathrm{Floor}) = \lfloor q \rfloor.$
$f(x, p, \mathrm{Ceiling}) = \lceil q \rceil.$
$$ f(x, p, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd}. \end{cases} $$
$f(x, p, \mathrm{Exact}) = q$, but panics if $q \notin \Z$.
Worst-case complexity
Constant time and additional memory.
Panics
Panics if bits
is positive and rm
is RoundingMode::Exact
but self
is
not divisible by $2^b$.
Examples
See here.
type Output = u32
sourceimpl ShrRound<i64> for u32
impl ShrRound<i64> for u32
sourcefn shr_round(self, bits: i64, rm: RoundingMode) -> u32
fn shr_round(self, bits: i64, rm: RoundingMode) -> u32
Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode.
Passing RoundingMode::Floor
or RoundingMode::Down
is equivalent to
using >>
. To test whether RoundingMode::Exact
can be passed, use
self.divisible_by_power_of_2(bits)
. Rounding might only be necessary if
bits
is non-negative.
Let $q = \frac{x}{2^p}$:
$f(x, p, \mathrm{Down}) = \operatorname{sgn}(q) \lfloor |q| \rfloor.$
$f(x, p, \mathrm{Up}) = \operatorname{sgn}(q) \lceil |q| \rceil.$
$f(x, p, \mathrm{Floor}) = \lfloor q \rfloor.$
$f(x, p, \mathrm{Ceiling}) = \lceil q \rceil.$
$$ f(x, p, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd}. \end{cases} $$
$f(x, p, \mathrm{Exact}) = q$, but panics if $q \notin \Z$.
Worst-case complexity
Constant time and additional memory.
Panics
Panics if bits
is positive and rm
is RoundingMode::Exact
but self
is
not divisible by $2^b$.
Examples
See here.
type Output = u32
sourceimpl ShrRound<i128> for u32
impl ShrRound<i128> for u32
sourcefn shr_round(self, bits: i128, rm: RoundingMode) -> u32
fn shr_round(self, bits: i128, rm: RoundingMode) -> u32
Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode.
Passing RoundingMode::Floor
or RoundingMode::Down
is equivalent to
using >>
. To test whether RoundingMode::Exact
can be passed, use
self.divisible_by_power_of_2(bits)
. Rounding might only be necessary if
bits
is non-negative.
Let $q = \frac{x}{2^p}$:
$f(x, p, \mathrm{Down}) = \operatorname{sgn}(q) \lfloor |q| \rfloor.$
$f(x, p, \mathrm{Up}) = \operatorname{sgn}(q) \lceil |q| \rceil.$
$f(x, p, \mathrm{Floor}) = \lfloor q \rfloor.$
$f(x, p, \mathrm{Ceiling}) = \lceil q \rceil.$
$$ f(x, p, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd}. \end{cases} $$
$f(x, p, \mathrm{Exact}) = q$, but panics if $q \notin \Z$.
Worst-case complexity
Constant time and additional memory.
Panics
Panics if bits
is positive and rm
is RoundingMode::Exact
but self
is
not divisible by $2^b$.
Examples
See here.
type Output = u32
sourceimpl ShrRound<isize> for u32
impl ShrRound<isize> for u32
sourcefn shr_round(self, bits: isize, rm: RoundingMode) -> u32
fn shr_round(self, bits: isize, rm: RoundingMode) -> u32
Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode.
Passing RoundingMode::Floor
or RoundingMode::Down
is equivalent to
using >>
. To test whether RoundingMode::Exact
can be passed, use
self.divisible_by_power_of_2(bits)
. Rounding might only be necessary if
bits
is non-negative.
Let $q = \frac{x}{2^p}$:
$f(x, p, \mathrm{Down}) = \operatorname{sgn}(q) \lfloor |q| \rfloor.$
$f(x, p, \mathrm{Up}) = \operatorname{sgn}(q) \lceil |q| \rceil.$
$f(x, p, \mathrm{Floor}) = \lfloor q \rfloor.$
$f(x, p, \mathrm{Ceiling}) = \lceil q \rceil.$
$$ f(x, p, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd}. \end{cases} $$
$f(x, p, \mathrm{Exact}) = q$, but panics if $q \notin \Z$.
Worst-case complexity
Constant time and additional memory.
Panics
Panics if bits
is positive and rm
is RoundingMode::Exact
but self
is
not divisible by $2^b$.
Examples
See here.
type Output = u32
sourceimpl ShrRound<i8> for u64
impl ShrRound<i8> for u64
sourcefn shr_round(self, bits: i8, rm: RoundingMode) -> u64
fn shr_round(self, bits: i8, rm: RoundingMode) -> u64
Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode.
Passing RoundingMode::Floor
or RoundingMode::Down
is equivalent to
using >>
. To test whether RoundingMode::Exact
can be passed, use
self.divisible_by_power_of_2(bits)
. Rounding might only be necessary if
bits
is non-negative.
Let $q = \frac{x}{2^p}$:
$f(x, p, \mathrm{Down}) = \operatorname{sgn}(q) \lfloor |q| \rfloor.$
$f(x, p, \mathrm{Up}) = \operatorname{sgn}(q) \lceil |q| \rceil.$
$f(x, p, \mathrm{Floor}) = \lfloor q \rfloor.$
$f(x, p, \mathrm{Ceiling}) = \lceil q \rceil.$
$$ f(x, p, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd}. \end{cases} $$
$f(x, p, \mathrm{Exact}) = q$, but panics if $q \notin \Z$.
Worst-case complexity
Constant time and additional memory.
Panics
Panics if bits
is positive and rm
is RoundingMode::Exact
but self
is
not divisible by $2^b$.
Examples
See here.
type Output = u64
sourceimpl ShrRound<i16> for u64
impl ShrRound<i16> for u64
sourcefn shr_round(self, bits: i16, rm: RoundingMode) -> u64
fn shr_round(self, bits: i16, rm: RoundingMode) -> u64
Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode.
Passing RoundingMode::Floor
or RoundingMode::Down
is equivalent to
using >>
. To test whether RoundingMode::Exact
can be passed, use
self.divisible_by_power_of_2(bits)
. Rounding might only be necessary if
bits
is non-negative.
Let $q = \frac{x}{2^p}$:
$f(x, p, \mathrm{Down}) = \operatorname{sgn}(q) \lfloor |q| \rfloor.$
$f(x, p, \mathrm{Up}) = \operatorname{sgn}(q) \lceil |q| \rceil.$
$f(x, p, \mathrm{Floor}) = \lfloor q \rfloor.$
$f(x, p, \mathrm{Ceiling}) = \lceil q \rceil.$
$$ f(x, p, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd}. \end{cases} $$
$f(x, p, \mathrm{Exact}) = q$, but panics if $q \notin \Z$.
Worst-case complexity
Constant time and additional memory.
Panics
Panics if bits
is positive and rm
is RoundingMode::Exact
but self
is
not divisible by $2^b$.
Examples
See here.
type Output = u64
sourceimpl ShrRound<i32> for u64
impl ShrRound<i32> for u64
sourcefn shr_round(self, bits: i32, rm: RoundingMode) -> u64
fn shr_round(self, bits: i32, rm: RoundingMode) -> u64
Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode.
Passing RoundingMode::Floor
or RoundingMode::Down
is equivalent to
using >>
. To test whether RoundingMode::Exact
can be passed, use
self.divisible_by_power_of_2(bits)
. Rounding might only be necessary if
bits
is non-negative.
Let $q = \frac{x}{2^p}$:
$f(x, p, \mathrm{Down}) = \operatorname{sgn}(q) \lfloor |q| \rfloor.$
$f(x, p, \mathrm{Up}) = \operatorname{sgn}(q) \lceil |q| \rceil.$
$f(x, p, \mathrm{Floor}) = \lfloor q \rfloor.$
$f(x, p, \mathrm{Ceiling}) = \lceil q \rceil.$
$$ f(x, p, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd}. \end{cases} $$
$f(x, p, \mathrm{Exact}) = q$, but panics if $q \notin \Z$.
Worst-case complexity
Constant time and additional memory.
Panics
Panics if bits
is positive and rm
is RoundingMode::Exact
but self
is
not divisible by $2^b$.
Examples
See here.
type Output = u64
sourceimpl ShrRound<i64> for u64
impl ShrRound<i64> for u64
sourcefn shr_round(self, bits: i64, rm: RoundingMode) -> u64
fn shr_round(self, bits: i64, rm: RoundingMode) -> u64
Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode.
Passing RoundingMode::Floor
or RoundingMode::Down
is equivalent to
using >>
. To test whether RoundingMode::Exact
can be passed, use
self.divisible_by_power_of_2(bits)
. Rounding might only be necessary if
bits
is non-negative.
Let $q = \frac{x}{2^p}$:
$f(x, p, \mathrm{Down}) = \operatorname{sgn}(q) \lfloor |q| \rfloor.$
$f(x, p, \mathrm{Up}) = \operatorname{sgn}(q) \lceil |q| \rceil.$
$f(x, p, \mathrm{Floor}) = \lfloor q \rfloor.$
$f(x, p, \mathrm{Ceiling}) = \lceil q \rceil.$
$$ f(x, p, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd}. \end{cases} $$
$f(x, p, \mathrm{Exact}) = q$, but panics if $q \notin \Z$.
Worst-case complexity
Constant time and additional memory.
Panics
Panics if bits
is positive and rm
is RoundingMode::Exact
but self
is
not divisible by $2^b$.
Examples
See here.
type Output = u64
sourceimpl ShrRound<i128> for u64
impl ShrRound<i128> for u64
sourcefn shr_round(self, bits: i128, rm: RoundingMode) -> u64
fn shr_round(self, bits: i128, rm: RoundingMode) -> u64
Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode.
Passing RoundingMode::Floor
or RoundingMode::Down
is equivalent to
using >>
. To test whether RoundingMode::Exact
can be passed, use
self.divisible_by_power_of_2(bits)
. Rounding might only be necessary if
bits
is non-negative.
Let $q = \frac{x}{2^p}$:
$f(x, p, \mathrm{Down}) = \operatorname{sgn}(q) \lfloor |q| \rfloor.$
$f(x, p, \mathrm{Up}) = \operatorname{sgn}(q) \lceil |q| \rceil.$
$f(x, p, \mathrm{Floor}) = \lfloor q \rfloor.$
$f(x, p, \mathrm{Ceiling}) = \lceil q \rceil.$
$$ f(x, p, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd}. \end{cases} $$
$f(x, p, \mathrm{Exact}) = q$, but panics if $q \notin \Z$.
Worst-case complexity
Constant time and additional memory.
Panics
Panics if bits
is positive and rm
is RoundingMode::Exact
but self
is
not divisible by $2^b$.
Examples
See here.
type Output = u64
sourceimpl ShrRound<isize> for u64
impl ShrRound<isize> for u64
sourcefn shr_round(self, bits: isize, rm: RoundingMode) -> u64
fn shr_round(self, bits: isize, rm: RoundingMode) -> u64
Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode.
Passing RoundingMode::Floor
or RoundingMode::Down
is equivalent to
using >>
. To test whether RoundingMode::Exact
can be passed, use
self.divisible_by_power_of_2(bits)
. Rounding might only be necessary if
bits
is non-negative.
Let $q = \frac{x}{2^p}$:
$f(x, p, \mathrm{Down}) = \operatorname{sgn}(q) \lfloor |q| \rfloor.$
$f(x, p, \mathrm{Up}) = \operatorname{sgn}(q) \lceil |q| \rceil.$
$f(x, p, \mathrm{Floor}) = \lfloor q \rfloor.$
$f(x, p, \mathrm{Ceiling}) = \lceil q \rceil.$
$$ f(x, p, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd}. \end{cases} $$
$f(x, p, \mathrm{Exact}) = q$, but panics if $q \notin \Z$.
Worst-case complexity
Constant time and additional memory.
Panics
Panics if bits
is positive and rm
is RoundingMode::Exact
but self
is
not divisible by $2^b$.
Examples
See here.
type Output = u64
sourceimpl ShrRound<i8> for u128
impl ShrRound<i8> for u128
sourcefn shr_round(self, bits: i8, rm: RoundingMode) -> u128
fn shr_round(self, bits: i8, rm: RoundingMode) -> u128
Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode.
Passing RoundingMode::Floor
or RoundingMode::Down
is equivalent to
using >>
. To test whether RoundingMode::Exact
can be passed, use
self.divisible_by_power_of_2(bits)
. Rounding might only be necessary if
bits
is non-negative.
Let $q = \frac{x}{2^p}$:
$f(x, p, \mathrm{Down}) = \operatorname{sgn}(q) \lfloor |q| \rfloor.$
$f(x, p, \mathrm{Up}) = \operatorname{sgn}(q) \lceil |q| \rceil.$
$f(x, p, \mathrm{Floor}) = \lfloor q \rfloor.$
$f(x, p, \mathrm{Ceiling}) = \lceil q \rceil.$
$$ f(x, p, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd}. \end{cases} $$
$f(x, p, \mathrm{Exact}) = q$, but panics if $q \notin \Z$.
Worst-case complexity
Constant time and additional memory.
Panics
Panics if bits
is positive and rm
is RoundingMode::Exact
but self
is
not divisible by $2^b$.
Examples
See here.
type Output = u128
sourceimpl ShrRound<i16> for u128
impl ShrRound<i16> for u128
sourcefn shr_round(self, bits: i16, rm: RoundingMode) -> u128
fn shr_round(self, bits: i16, rm: RoundingMode) -> u128
Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode.
Passing RoundingMode::Floor
or RoundingMode::Down
is equivalent to
using >>
. To test whether RoundingMode::Exact
can be passed, use
self.divisible_by_power_of_2(bits)
. Rounding might only be necessary if
bits
is non-negative.
Let $q = \frac{x}{2^p}$:
$f(x, p, \mathrm{Down}) = \operatorname{sgn}(q) \lfloor |q| \rfloor.$
$f(x, p, \mathrm{Up}) = \operatorname{sgn}(q) \lceil |q| \rceil.$
$f(x, p, \mathrm{Floor}) = \lfloor q \rfloor.$
$f(x, p, \mathrm{Ceiling}) = \lceil q \rceil.$
$$ f(x, p, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd}. \end{cases} $$
$f(x, p, \mathrm{Exact}) = q$, but panics if $q \notin \Z$.
Worst-case complexity
Constant time and additional memory.
Panics
Panics if bits
is positive and rm
is RoundingMode::Exact
but self
is
not divisible by $2^b$.
Examples
See here.
type Output = u128
sourceimpl ShrRound<i32> for u128
impl ShrRound<i32> for u128
sourcefn shr_round(self, bits: i32, rm: RoundingMode) -> u128
fn shr_round(self, bits: i32, rm: RoundingMode) -> u128
Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode.
Passing RoundingMode::Floor
or RoundingMode::Down
is equivalent to
using >>
. To test whether RoundingMode::Exact
can be passed, use
self.divisible_by_power_of_2(bits)
. Rounding might only be necessary if
bits
is non-negative.
Let $q = \frac{x}{2^p}$:
$f(x, p, \mathrm{Down}) = \operatorname{sgn}(q) \lfloor |q| \rfloor.$
$f(x, p, \mathrm{Up}) = \operatorname{sgn}(q) \lceil |q| \rceil.$
$f(x, p, \mathrm{Floor}) = \lfloor q \rfloor.$
$f(x, p, \mathrm{Ceiling}) = \lceil q \rceil.$
$$ f(x, p, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd}. \end{cases} $$
$f(x, p, \mathrm{Exact}) = q$, but panics if $q \notin \Z$.
Worst-case complexity
Constant time and additional memory.
Panics
Panics if bits
is positive and rm
is RoundingMode::Exact
but self
is
not divisible by $2^b$.
Examples
See here.
type Output = u128
sourceimpl ShrRound<i64> for u128
impl ShrRound<i64> for u128
sourcefn shr_round(self, bits: i64, rm: RoundingMode) -> u128
fn shr_round(self, bits: i64, rm: RoundingMode) -> u128
Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode.
Passing RoundingMode::Floor
or RoundingMode::Down
is equivalent to
using >>
. To test whether RoundingMode::Exact
can be passed, use
self.divisible_by_power_of_2(bits)
. Rounding might only be necessary if
bits
is non-negative.
Let $q = \frac{x}{2^p}$:
$f(x, p, \mathrm{Down}) = \operatorname{sgn}(q) \lfloor |q| \rfloor.$
$f(x, p, \mathrm{Up}) = \operatorname{sgn}(q) \lceil |q| \rceil.$
$f(x, p, \mathrm{Floor}) = \lfloor q \rfloor.$
$f(x, p, \mathrm{Ceiling}) = \lceil q \rceil.$
$$ f(x, p, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd}. \end{cases} $$
$f(x, p, \mathrm{Exact}) = q$, but panics if $q \notin \Z$.
Worst-case complexity
Constant time and additional memory.
Panics
Panics if bits
is positive and rm
is RoundingMode::Exact
but self
is
not divisible by $2^b$.
Examples
See here.
type Output = u128
sourceimpl ShrRound<i128> for u128
impl ShrRound<i128> for u128
sourcefn shr_round(self, bits: i128, rm: RoundingMode) -> u128
fn shr_round(self, bits: i128, rm: RoundingMode) -> u128
Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode.
Passing RoundingMode::Floor
or RoundingMode::Down
is equivalent to
using >>
. To test whether RoundingMode::Exact
can be passed, use
self.divisible_by_power_of_2(bits)
. Rounding might only be necessary if
bits
is non-negative.
Let $q = \frac{x}{2^p}$:
$f(x, p, \mathrm{Down}) = \operatorname{sgn}(q) \lfloor |q| \rfloor.$
$f(x, p, \mathrm{Up}) = \operatorname{sgn}(q) \lceil |q| \rceil.$
$f(x, p, \mathrm{Floor}) = \lfloor q \rfloor.$
$f(x, p, \mathrm{Ceiling}) = \lceil q \rceil.$
$$ f(x, p, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd}. \end{cases} $$
$f(x, p, \mathrm{Exact}) = q$, but panics if $q \notin \Z$.
Worst-case complexity
Constant time and additional memory.
Panics
Panics if bits
is positive and rm
is RoundingMode::Exact
but self
is
not divisible by $2^b$.
Examples
See here.
type Output = u128
sourceimpl ShrRound<isize> for u128
impl ShrRound<isize> for u128
sourcefn shr_round(self, bits: isize, rm: RoundingMode) -> u128
fn shr_round(self, bits: isize, rm: RoundingMode) -> u128
Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode.
Passing RoundingMode::Floor
or RoundingMode::Down
is equivalent to
using >>
. To test whether RoundingMode::Exact
can be passed, use
self.divisible_by_power_of_2(bits)
. Rounding might only be necessary if
bits
is non-negative.
Let $q = \frac{x}{2^p}$:
$f(x, p, \mathrm{Down}) = \operatorname{sgn}(q) \lfloor |q| \rfloor.$
$f(x, p, \mathrm{Up}) = \operatorname{sgn}(q) \lceil |q| \rceil.$
$f(x, p, \mathrm{Floor}) = \lfloor q \rfloor.$
$f(x, p, \mathrm{Ceiling}) = \lceil q \rceil.$
$$ f(x, p, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd}. \end{cases} $$
$f(x, p, \mathrm{Exact}) = q$, but panics if $q \notin \Z$.
Worst-case complexity
Constant time and additional memory.
Panics
Panics if bits
is positive and rm
is RoundingMode::Exact
but self
is
not divisible by $2^b$.
Examples
See here.
type Output = u128
sourceimpl ShrRound<i8> for usize
impl ShrRound<i8> for usize
sourcefn shr_round(self, bits: i8, rm: RoundingMode) -> usize
fn shr_round(self, bits: i8, rm: RoundingMode) -> usize
Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode.
Passing RoundingMode::Floor
or RoundingMode::Down
is equivalent to
using >>
. To test whether RoundingMode::Exact
can be passed, use
self.divisible_by_power_of_2(bits)
. Rounding might only be necessary if
bits
is non-negative.
Let $q = \frac{x}{2^p}$:
$f(x, p, \mathrm{Down}) = \operatorname{sgn}(q) \lfloor |q| \rfloor.$
$f(x, p, \mathrm{Up}) = \operatorname{sgn}(q) \lceil |q| \rceil.$
$f(x, p, \mathrm{Floor}) = \lfloor q \rfloor.$
$f(x, p, \mathrm{Ceiling}) = \lceil q \rceil.$
$$ f(x, p, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd}. \end{cases} $$
$f(x, p, \mathrm{Exact}) = q$, but panics if $q \notin \Z$.
Worst-case complexity
Constant time and additional memory.
Panics
Panics if bits
is positive and rm
is RoundingMode::Exact
but self
is
not divisible by $2^b$.
Examples
See here.
type Output = usize
sourceimpl ShrRound<i16> for usize
impl ShrRound<i16> for usize
sourcefn shr_round(self, bits: i16, rm: RoundingMode) -> usize
fn shr_round(self, bits: i16, rm: RoundingMode) -> usize
Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode.
Passing RoundingMode::Floor
or RoundingMode::Down
is equivalent to
using >>
. To test whether RoundingMode::Exact
can be passed, use
self.divisible_by_power_of_2(bits)
. Rounding might only be necessary if
bits
is non-negative.
Let $q = \frac{x}{2^p}$:
$f(x, p, \mathrm{Down}) = \operatorname{sgn}(q) \lfloor |q| \rfloor.$
$f(x, p, \mathrm{Up}) = \operatorname{sgn}(q) \lceil |q| \rceil.$
$f(x, p, \mathrm{Floor}) = \lfloor q \rfloor.$
$f(x, p, \mathrm{Ceiling}) = \lceil q \rceil.$
$$ f(x, p, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd}. \end{cases} $$
$f(x, p, \mathrm{Exact}) = q$, but panics if $q \notin \Z$.
Worst-case complexity
Constant time and additional memory.
Panics
Panics if bits
is positive and rm
is RoundingMode::Exact
but self
is
not divisible by $2^b$.
Examples
See here.
type Output = usize
sourceimpl ShrRound<i32> for usize
impl ShrRound<i32> for usize
sourcefn shr_round(self, bits: i32, rm: RoundingMode) -> usize
fn shr_round(self, bits: i32, rm: RoundingMode) -> usize
Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode.
Passing RoundingMode::Floor
or RoundingMode::Down
is equivalent to
using >>
. To test whether RoundingMode::Exact
can be passed, use
self.divisible_by_power_of_2(bits)
. Rounding might only be necessary if
bits
is non-negative.
Let $q = \frac{x}{2^p}$:
$f(x, p, \mathrm{Down}) = \operatorname{sgn}(q) \lfloor |q| \rfloor.$
$f(x, p, \mathrm{Up}) = \operatorname{sgn}(q) \lceil |q| \rceil.$
$f(x, p, \mathrm{Floor}) = \lfloor q \rfloor.$
$f(x, p, \mathrm{Ceiling}) = \lceil q \rceil.$
$$ f(x, p, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd}. \end{cases} $$
$f(x, p, \mathrm{Exact}) = q$, but panics if $q \notin \Z$.
Worst-case complexity
Constant time and additional memory.
Panics
Panics if bits
is positive and rm
is RoundingMode::Exact
but self
is
not divisible by $2^b$.
Examples
See here.
type Output = usize
sourceimpl ShrRound<i64> for usize
impl ShrRound<i64> for usize
sourcefn shr_round(self, bits: i64, rm: RoundingMode) -> usize
fn shr_round(self, bits: i64, rm: RoundingMode) -> usize
Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode.
Passing RoundingMode::Floor
or RoundingMode::Down
is equivalent to
using >>
. To test whether RoundingMode::Exact
can be passed, use
self.divisible_by_power_of_2(bits)
. Rounding might only be necessary if
bits
is non-negative.
Let $q = \frac{x}{2^p}$:
$f(x, p, \mathrm{Down}) = \operatorname{sgn}(q) \lfloor |q| \rfloor.$
$f(x, p, \mathrm{Up}) = \operatorname{sgn}(q) \lceil |q| \rceil.$
$f(x, p, \mathrm{Floor}) = \lfloor q \rfloor.$
$f(x, p, \mathrm{Ceiling}) = \lceil q \rceil.$
$$ f(x, p, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd}. \end{cases} $$
$f(x, p, \mathrm{Exact}) = q$, but panics if $q \notin \Z$.
Worst-case complexity
Constant time and additional memory.
Panics
Panics if bits
is positive and rm
is RoundingMode::Exact
but self
is
not divisible by $2^b$.
Examples
See here.
type Output = usize
sourceimpl ShrRound<i128> for usize
impl ShrRound<i128> for usize
sourcefn shr_round(self, bits: i128, rm: RoundingMode) -> usize
fn shr_round(self, bits: i128, rm: RoundingMode) -> usize
Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode.
Passing RoundingMode::Floor
or RoundingMode::Down
is equivalent to
using >>
. To test whether RoundingMode::Exact
can be passed, use
self.divisible_by_power_of_2(bits)
. Rounding might only be necessary if
bits
is non-negative.
Let $q = \frac{x}{2^p}$:
$f(x, p, \mathrm{Down}) = \operatorname{sgn}(q) \lfloor |q| \rfloor.$
$f(x, p, \mathrm{Up}) = \operatorname{sgn}(q) \lceil |q| \rceil.$
$f(x, p, \mathrm{Floor}) = \lfloor q \rfloor.$
$f(x, p, \mathrm{Ceiling}) = \lceil q \rceil.$
$$ f(x, p, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd}. \end{cases} $$
$f(x, p, \mathrm{Exact}) = q$, but panics if $q \notin \Z$.
Worst-case complexity
Constant time and additional memory.
Panics
Panics if bits
is positive and rm
is RoundingMode::Exact
but self
is
not divisible by $2^b$.
Examples
See here.
type Output = usize
sourceimpl ShrRound<isize> for usize
impl ShrRound<isize> for usize
sourcefn shr_round(self, bits: isize, rm: RoundingMode) -> usize
fn shr_round(self, bits: isize, rm: RoundingMode) -> usize
Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode.
Passing RoundingMode::Floor
or RoundingMode::Down
is equivalent to
using >>
. To test whether RoundingMode::Exact
can be passed, use
self.divisible_by_power_of_2(bits)
. Rounding might only be necessary if
bits
is non-negative.
Let $q = \frac{x}{2^p}$:
$f(x, p, \mathrm{Down}) = \operatorname{sgn}(q) \lfloor |q| \rfloor.$
$f(x, p, \mathrm{Up}) = \operatorname{sgn}(q) \lceil |q| \rceil.$
$f(x, p, \mathrm{Floor}) = \lfloor q \rfloor.$
$f(x, p, \mathrm{Ceiling}) = \lceil q \rceil.$
$$ f(x, p, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd}. \end{cases} $$
$f(x, p, \mathrm{Exact}) = q$, but panics if $q \notin \Z$.
Worst-case complexity
Constant time and additional memory.
Panics
Panics if bits
is positive and rm
is RoundingMode::Exact
but self
is
not divisible by $2^b$.
Examples
See here.
type Output = usize
sourceimpl ShrRound<i8> for i8
impl ShrRound<i8> for i8
sourcefn shr_round(self, bits: i8, rm: RoundingMode) -> i8
fn shr_round(self, bits: i8, rm: RoundingMode) -> i8
Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode.
Passing RoundingMode::Floor
or RoundingMode::Down
is equivalent to
using >>
. To test whether RoundingMode::Exact
can be passed, use
self.divisible_by_power_of_2(bits)
. Rounding might only be necessary if
bits
is non-negative.
Let $q = \frac{x}{2^p}$:
$f(x, p, \mathrm{Down}) = \operatorname{sgn}(q) \lfloor |q| \rfloor.$
$f(x, p, \mathrm{Up}) = \operatorname{sgn}(q) \lceil |q| \rceil.$
$f(x, p, \mathrm{Floor}) = \lfloor q \rfloor.$
$f(x, p, \mathrm{Ceiling}) = \lceil q \rceil.$
$$ f(x, p, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd}. \end{cases} $$
$f(x, p, \mathrm{Exact}) = q$, but panics if $q \notin \Z$.
Worst-case complexity
Constant time and additional memory.
Panics
Panics if bits
is positive and rm
is RoundingMode::Exact
but self
is
not divisible by $2^b$.
Examples
See here.
type Output = i8
sourceimpl ShrRound<i16> for i8
impl ShrRound<i16> for i8
sourcefn shr_round(self, bits: i16, rm: RoundingMode) -> i8
fn shr_round(self, bits: i16, rm: RoundingMode) -> i8
Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode.
Passing RoundingMode::Floor
or RoundingMode::Down
is equivalent to
using >>
. To test whether RoundingMode::Exact
can be passed, use
self.divisible_by_power_of_2(bits)
. Rounding might only be necessary if
bits
is non-negative.
Let $q = \frac{x}{2^p}$:
$f(x, p, \mathrm{Down}) = \operatorname{sgn}(q) \lfloor |q| \rfloor.$
$f(x, p, \mathrm{Up}) = \operatorname{sgn}(q) \lceil |q| \rceil.$
$f(x, p, \mathrm{Floor}) = \lfloor q \rfloor.$
$f(x, p, \mathrm{Ceiling}) = \lceil q \rceil.$
$$ f(x, p, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd}. \end{cases} $$
$f(x, p, \mathrm{Exact}) = q$, but panics if $q \notin \Z$.
Worst-case complexity
Constant time and additional memory.
Panics
Panics if bits
is positive and rm
is RoundingMode::Exact
but self
is
not divisible by $2^b$.
Examples
See here.
type Output = i8
sourceimpl ShrRound<i32> for i8
impl ShrRound<i32> for i8
sourcefn shr_round(self, bits: i32, rm: RoundingMode) -> i8
fn shr_round(self, bits: i32, rm: RoundingMode) -> i8
Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode.
Passing RoundingMode::Floor
or RoundingMode::Down
is equivalent to
using >>
. To test whether RoundingMode::Exact
can be passed, use
self.divisible_by_power_of_2(bits)
. Rounding might only be necessary if
bits
is non-negative.
Let $q = \frac{x}{2^p}$:
$f(x, p, \mathrm{Down}) = \operatorname{sgn}(q) \lfloor |q| \rfloor.$
$f(x, p, \mathrm{Up}) = \operatorname{sgn}(q) \lceil |q| \rceil.$
$f(x, p, \mathrm{Floor}) = \lfloor q \rfloor.$
$f(x, p, \mathrm{Ceiling}) = \lceil q \rceil.$
$$ f(x, p, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd}. \end{cases} $$
$f(x, p, \mathrm{Exact}) = q$, but panics if $q \notin \Z$.
Worst-case complexity
Constant time and additional memory.
Panics
Panics if bits
is positive and rm
is RoundingMode::Exact
but self
is
not divisible by $2^b$.
Examples
See here.
type Output = i8
sourceimpl ShrRound<i64> for i8
impl ShrRound<i64> for i8
sourcefn shr_round(self, bits: i64, rm: RoundingMode) -> i8
fn shr_round(self, bits: i64, rm: RoundingMode) -> i8
Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode.
Passing RoundingMode::Floor
or RoundingMode::Down
is equivalent to
using >>
. To test whether RoundingMode::Exact
can be passed, use
self.divisible_by_power_of_2(bits)
. Rounding might only be necessary if
bits
is non-negative.
Let $q = \frac{x}{2^p}$:
$f(x, p, \mathrm{Down}) = \operatorname{sgn}(q) \lfloor |q| \rfloor.$
$f(x, p, \mathrm{Up}) = \operatorname{sgn}(q) \lceil |q| \rceil.$
$f(x, p, \mathrm{Floor}) = \lfloor q \rfloor.$
$f(x, p, \mathrm{Ceiling}) = \lceil q \rceil.$
$$ f(x, p, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd}. \end{cases} $$
$f(x, p, \mathrm{Exact}) = q$, but panics if $q \notin \Z$.
Worst-case complexity
Constant time and additional memory.
Panics
Panics if bits
is positive and rm
is RoundingMode::Exact
but self
is
not divisible by $2^b$.
Examples
See here.
type Output = i8
sourceimpl ShrRound<i128> for i8
impl ShrRound<i128> for i8
sourcefn shr_round(self, bits: i128, rm: RoundingMode) -> i8
fn shr_round(self, bits: i128, rm: RoundingMode) -> i8
Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode.
Passing RoundingMode::Floor
or RoundingMode::Down
is equivalent to
using >>
. To test whether RoundingMode::Exact
can be passed, use
self.divisible_by_power_of_2(bits)
. Rounding might only be necessary if
bits
is non-negative.
Let $q = \frac{x}{2^p}$:
$f(x, p, \mathrm{Down}) = \operatorname{sgn}(q) \lfloor |q| \rfloor.$
$f(x, p, \mathrm{Up}) = \operatorname{sgn}(q) \lceil |q| \rceil.$
$f(x, p, \mathrm{Floor}) = \lfloor q \rfloor.$
$f(x, p, \mathrm{Ceiling}) = \lceil q \rceil.$
$$ f(x, p, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd}. \end{cases} $$
$f(x, p, \mathrm{Exact}) = q$, but panics if $q \notin \Z$.
Worst-case complexity
Constant time and additional memory.
Panics
Panics if bits
is positive and rm
is RoundingMode::Exact
but self
is
not divisible by $2^b$.
Examples
See here.
type Output = i8
sourceimpl ShrRound<isize> for i8
impl ShrRound<isize> for i8
sourcefn shr_round(self, bits: isize, rm: RoundingMode) -> i8
fn shr_round(self, bits: isize, rm: RoundingMode) -> i8
Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode.
Passing RoundingMode::Floor
or RoundingMode::Down
is equivalent to
using >>
. To test whether RoundingMode::Exact
can be passed, use
self.divisible_by_power_of_2(bits)
. Rounding might only be necessary if
bits
is non-negative.
Let $q = \frac{x}{2^p}$:
$f(x, p, \mathrm{Down}) = \operatorname{sgn}(q) \lfloor |q| \rfloor.$
$f(x, p, \mathrm{Up}) = \operatorname{sgn}(q) \lceil |q| \rceil.$
$f(x, p, \mathrm{Floor}) = \lfloor q \rfloor.$
$f(x, p, \mathrm{Ceiling}) = \lceil q \rceil.$
$$ f(x, p, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd}. \end{cases} $$
$f(x, p, \mathrm{Exact}) = q$, but panics if $q \notin \Z$.
Worst-case complexity
Constant time and additional memory.
Panics
Panics if bits
is positive and rm
is RoundingMode::Exact
but self
is
not divisible by $2^b$.
Examples
See here.
type Output = i8
sourceimpl ShrRound<i8> for i16
impl ShrRound<i8> for i16
sourcefn shr_round(self, bits: i8, rm: RoundingMode) -> i16
fn shr_round(self, bits: i8, rm: RoundingMode) -> i16
Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode.
Passing RoundingMode::Floor
or RoundingMode::Down
is equivalent to
using >>
. To test whether RoundingMode::Exact
can be passed, use
self.divisible_by_power_of_2(bits)
. Rounding might only be necessary if
bits
is non-negative.
Let $q = \frac{x}{2^p}$:
$f(x, p, \mathrm{Down}) = \operatorname{sgn}(q) \lfloor |q| \rfloor.$
$f(x, p, \mathrm{Up}) = \operatorname{sgn}(q) \lceil |q| \rceil.$
$f(x, p, \mathrm{Floor}) = \lfloor q \rfloor.$
$f(x, p, \mathrm{Ceiling}) = \lceil q \rceil.$
$$ f(x, p, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd}. \end{cases} $$
$f(x, p, \mathrm{Exact}) = q$, but panics if $q \notin \Z$.
Worst-case complexity
Constant time and additional memory.
Panics
Panics if bits
is positive and rm
is RoundingMode::Exact
but self
is
not divisible by $2^b$.
Examples
See here.
type Output = i16
sourceimpl ShrRound<i16> for i16
impl ShrRound<i16> for i16
sourcefn shr_round(self, bits: i16, rm: RoundingMode) -> i16
fn shr_round(self, bits: i16, rm: RoundingMode) -> i16
Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode.
Passing RoundingMode::Floor
or RoundingMode::Down
is equivalent to
using >>
. To test whether RoundingMode::Exact
can be passed, use
self.divisible_by_power_of_2(bits)
. Rounding might only be necessary if
bits
is non-negative.
Let $q = \frac{x}{2^p}$:
$f(x, p, \mathrm{Down}) = \operatorname{sgn}(q) \lfloor |q| \rfloor.$
$f(x, p, \mathrm{Up}) = \operatorname{sgn}(q) \lceil |q| \rceil.$
$f(x, p, \mathrm{Floor}) = \lfloor q \rfloor.$
$f(x, p, \mathrm{Ceiling}) = \lceil q \rceil.$
$$ f(x, p, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd}. \end{cases} $$
$f(x, p, \mathrm{Exact}) = q$, but panics if $q \notin \Z$.
Worst-case complexity
Constant time and additional memory.
Panics
Panics if bits
is positive and rm
is RoundingMode::Exact
but self
is
not divisible by $2^b$.
Examples
See here.
type Output = i16
sourceimpl ShrRound<i32> for i16
impl ShrRound<i32> for i16
sourcefn shr_round(self, bits: i32, rm: RoundingMode) -> i16
fn shr_round(self, bits: i32, rm: RoundingMode) -> i16
Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode.
Passing RoundingMode::Floor
or RoundingMode::Down
is equivalent to
using >>
. To test whether RoundingMode::Exact
can be passed, use
self.divisible_by_power_of_2(bits)
. Rounding might only be necessary if
bits
is non-negative.
Let $q = \frac{x}{2^p}$:
$f(x, p, \mathrm{Down}) = \operatorname{sgn}(q) \lfloor |q| \rfloor.$
$f(x, p, \mathrm{Up}) = \operatorname{sgn}(q) \lceil |q| \rceil.$
$f(x, p, \mathrm{Floor}) = \lfloor q \rfloor.$
$f(x, p, \mathrm{Ceiling}) = \lceil q \rceil.$
$$ f(x, p, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd}. \end{cases} $$
$f(x, p, \mathrm{Exact}) = q$, but panics if $q \notin \Z$.
Worst-case complexity
Constant time and additional memory.
Panics
Panics if bits
is positive and rm
is RoundingMode::Exact
but self
is
not divisible by $2^b$.
Examples
See here.
type Output = i16
sourceimpl ShrRound<i64> for i16
impl ShrRound<i64> for i16
sourcefn shr_round(self, bits: i64, rm: RoundingMode) -> i16
fn shr_round(self, bits: i64, rm: RoundingMode) -> i16
Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode.
Passing RoundingMode::Floor
or RoundingMode::Down
is equivalent to
using >>
. To test whether RoundingMode::Exact
can be passed, use
self.divisible_by_power_of_2(bits)
. Rounding might only be necessary if
bits
is non-negative.
Let $q = \frac{x}{2^p}$:
$f(x, p, \mathrm{Down}) = \operatorname{sgn}(q) \lfloor |q| \rfloor.$
$f(x, p, \mathrm{Up}) = \operatorname{sgn}(q) \lceil |q| \rceil.$
$f(x, p, \mathrm{Floor}) = \lfloor q \rfloor.$
$f(x, p, \mathrm{Ceiling}) = \lceil q \rceil.$
$$ f(x, p, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd}. \end{cases} $$
$f(x, p, \mathrm{Exact}) = q$, but panics if $q \notin \Z$.
Worst-case complexity
Constant time and additional memory.
Panics
Panics if bits
is positive and rm
is RoundingMode::Exact
but self
is
not divisible by $2^b$.
Examples
See here.
type Output = i16
sourceimpl ShrRound<i128> for i16
impl ShrRound<i128> for i16
sourcefn shr_round(self, bits: i128, rm: RoundingMode) -> i16
fn shr_round(self, bits: i128, rm: RoundingMode) -> i16
Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode.
Passing RoundingMode::Floor
or RoundingMode::Down
is equivalent to
using >>
. To test whether RoundingMode::Exact
can be passed, use
self.divisible_by_power_of_2(bits)
. Rounding might only be necessary if
bits
is non-negative.
Let $q = \frac{x}{2^p}$:
$f(x, p, \mathrm{Down}) = \operatorname{sgn}(q) \lfloor |q| \rfloor.$
$f(x, p, \mathrm{Up}) = \operatorname{sgn}(q) \lceil |q| \rceil.$
$f(x, p, \mathrm{Floor}) = \lfloor q \rfloor.$
$f(x, p, \mathrm{Ceiling}) = \lceil q \rceil.$
$$ f(x, p, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd}. \end{cases} $$
$f(x, p, \mathrm{Exact}) = q$, but panics if $q \notin \Z$.
Worst-case complexity
Constant time and additional memory.
Panics
Panics if bits
is positive and rm
is RoundingMode::Exact
but self
is
not divisible by $2^b$.
Examples
See here.
type Output = i16
sourceimpl ShrRound<isize> for i16
impl ShrRound<isize> for i16
sourcefn shr_round(self, bits: isize, rm: RoundingMode) -> i16
fn shr_round(self, bits: isize, rm: RoundingMode) -> i16
Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode.
Passing RoundingMode::Floor
or RoundingMode::Down
is equivalent to
using >>
. To test whether RoundingMode::Exact
can be passed, use
self.divisible_by_power_of_2(bits)
. Rounding might only be necessary if
bits
is non-negative.
Let $q = \frac{x}{2^p}$:
$f(x, p, \mathrm{Down}) = \operatorname{sgn}(q) \lfloor |q| \rfloor.$
$f(x, p, \mathrm{Up}) = \operatorname{sgn}(q) \lceil |q| \rceil.$
$f(x, p, \mathrm{Floor}) = \lfloor q \rfloor.$
$f(x, p, \mathrm{Ceiling}) = \lceil q \rceil.$
$$ f(x, p, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd}. \end{cases} $$
$f(x, p, \mathrm{Exact}) = q$, but panics if $q \notin \Z$.
Worst-case complexity
Constant time and additional memory.
Panics
Panics if bits
is positive and rm
is RoundingMode::Exact
but self
is
not divisible by $2^b$.
Examples
See here.
type Output = i16
sourceimpl ShrRound<i8> for i32
impl ShrRound<i8> for i32
sourcefn shr_round(self, bits: i8, rm: RoundingMode) -> i32
fn shr_round(self, bits: i8, rm: RoundingMode) -> i32
Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode.
Passing RoundingMode::Floor
or RoundingMode::Down
is equivalent to
using >>
. To test whether RoundingMode::Exact
can be passed, use
self.divisible_by_power_of_2(bits)
. Rounding might only be necessary if
bits
is non-negative.
Let $q = \frac{x}{2^p}$:
$f(x, p, \mathrm{Down}) = \operatorname{sgn}(q) \lfloor |q| \rfloor.$
$f(x, p, \mathrm{Up}) = \operatorname{sgn}(q) \lceil |q| \rceil.$
$f(x, p, \mathrm{Floor}) = \lfloor q \rfloor.$
$f(x, p, \mathrm{Ceiling}) = \lceil q \rceil.$
$$ f(x, p, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd}. \end{cases} $$
$f(x, p, \mathrm{Exact}) = q$, but panics if $q \notin \Z$.
Worst-case complexity
Constant time and additional memory.
Panics
Panics if bits
is positive and rm
is RoundingMode::Exact
but self
is
not divisible by $2^b$.
Examples
See here.
type Output = i32
sourceimpl ShrRound<i16> for i32
impl ShrRound<i16> for i32
sourcefn shr_round(self, bits: i16, rm: RoundingMode) -> i32
fn shr_round(self, bits: i16, rm: RoundingMode) -> i32
Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode.
Passing RoundingMode::Floor
or RoundingMode::Down
is equivalent to
using >>
. To test whether RoundingMode::Exact
can be passed, use
self.divisible_by_power_of_2(bits)
. Rounding might only be necessary if
bits
is non-negative.
Let $q = \frac{x}{2^p}$:
$f(x, p, \mathrm{Down}) = \operatorname{sgn}(q) \lfloor |q| \rfloor.$
$f(x, p, \mathrm{Up}) = \operatorname{sgn}(q) \lceil |q| \rceil.$
$f(x, p, \mathrm{Floor}) = \lfloor q \rfloor.$
$f(x, p, \mathrm{Ceiling}) = \lceil q \rceil.$
$$ f(x, p, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd}. \end{cases} $$
$f(x, p, \mathrm{Exact}) = q$, but panics if $q \notin \Z$.
Worst-case complexity
Constant time and additional memory.
Panics
Panics if bits
is positive and rm
is RoundingMode::Exact
but self
is
not divisible by $2^b$.
Examples
See here.
type Output = i32
sourceimpl ShrRound<i32> for i32
impl ShrRound<i32> for i32
sourcefn shr_round(self, bits: i32, rm: RoundingMode) -> i32
fn shr_round(self, bits: i32, rm: RoundingMode) -> i32
Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode.
Passing RoundingMode::Floor
or RoundingMode::Down
is equivalent to
using >>
. To test whether RoundingMode::Exact
can be passed, use
self.divisible_by_power_of_2(bits)
. Rounding might only be necessary if
bits
is non-negative.
Let $q = \frac{x}{2^p}$:
$f(x, p, \mathrm{Down}) = \operatorname{sgn}(q) \lfloor |q| \rfloor.$
$f(x, p, \mathrm{Up}) = \operatorname{sgn}(q) \lceil |q| \rceil.$
$f(x, p, \mathrm{Floor}) = \lfloor q \rfloor.$
$f(x, p, \mathrm{Ceiling}) = \lceil q \rceil.$
$$ f(x, p, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd}. \end{cases} $$
$f(x, p, \mathrm{Exact}) = q$, but panics if $q \notin \Z$.
Worst-case complexity
Constant time and additional memory.
Panics
Panics if bits
is positive and rm
is RoundingMode::Exact
but self
is
not divisible by $2^b$.
Examples
See here.
type Output = i32
sourceimpl ShrRound<i64> for i32
impl ShrRound<i64> for i32
sourcefn shr_round(self, bits: i64, rm: RoundingMode) -> i32
fn shr_round(self, bits: i64, rm: RoundingMode) -> i32
Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode.
Passing RoundingMode::Floor
or RoundingMode::Down
is equivalent to
using >>
. To test whether RoundingMode::Exact
can be passed, use
self.divisible_by_power_of_2(bits)
. Rounding might only be necessary if
bits
is non-negative.
Let $q = \frac{x}{2^p}$:
$f(x, p, \mathrm{Down}) = \operatorname{sgn}(q) \lfloor |q| \rfloor.$
$f(x, p, \mathrm{Up}) = \operatorname{sgn}(q) \lceil |q| \rceil.$
$f(x, p, \mathrm{Floor}) = \lfloor q \rfloor.$
$f(x, p, \mathrm{Ceiling}) = \lceil q \rceil.$
$$ f(x, p, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd}. \end{cases} $$
$f(x, p, \mathrm{Exact}) = q$, but panics if $q \notin \Z$.
Worst-case complexity
Constant time and additional memory.
Panics
Panics if bits
is positive and rm
is RoundingMode::Exact
but self
is
not divisible by $2^b$.
Examples
See here.
type Output = i32
sourceimpl ShrRound<i128> for i32
impl ShrRound<i128> for i32
sourcefn shr_round(self, bits: i128, rm: RoundingMode) -> i32
fn shr_round(self, bits: i128, rm: RoundingMode) -> i32
Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode.
Passing RoundingMode::Floor
or RoundingMode::Down
is equivalent to
using >>
. To test whether RoundingMode::Exact
can be passed, use
self.divisible_by_power_of_2(bits)
. Rounding might only be necessary if
bits
is non-negative.
Let $q = \frac{x}{2^p}$:
$f(x, p, \mathrm{Down}) = \operatorname{sgn}(q) \lfloor |q| \rfloor.$
$f(x, p, \mathrm{Up}) = \operatorname{sgn}(q) \lceil |q| \rceil.$
$f(x, p, \mathrm{Floor}) = \lfloor q \rfloor.$
$f(x, p, \mathrm{Ceiling}) = \lceil q \rceil.$
$$ f(x, p, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd}. \end{cases} $$
$f(x, p, \mathrm{Exact}) = q$, but panics if $q \notin \Z$.
Worst-case complexity
Constant time and additional memory.
Panics
Panics if bits
is positive and rm
is RoundingMode::Exact
but self
is
not divisible by $2^b$.
Examples
See here.
type Output = i32
sourceimpl ShrRound<isize> for i32
impl ShrRound<isize> for i32
sourcefn shr_round(self, bits: isize, rm: RoundingMode) -> i32
fn shr_round(self, bits: isize, rm: RoundingMode) -> i32
Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode.
Passing RoundingMode::Floor
or RoundingMode::Down
is equivalent to
using >>
. To test whether RoundingMode::Exact
can be passed, use
self.divisible_by_power_of_2(bits)
. Rounding might only be necessary if
bits
is non-negative.
Let $q = \frac{x}{2^p}$:
$f(x, p, \mathrm{Down}) = \operatorname{sgn}(q) \lfloor |q| \rfloor.$
$f(x, p, \mathrm{Up}) = \operatorname{sgn}(q) \lceil |q| \rceil.$
$f(x, p, \mathrm{Floor}) = \lfloor q \rfloor.$
$f(x, p, \mathrm{Ceiling}) = \lceil q \rceil.$
$$ f(x, p, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd}. \end{cases} $$
$f(x, p, \mathrm{Exact}) = q$, but panics if $q \notin \Z$.
Worst-case complexity
Constant time and additional memory.
Panics
Panics if bits
is positive and rm
is RoundingMode::Exact
but self
is
not divisible by $2^b$.
Examples
See here.
type Output = i32
sourceimpl ShrRound<i8> for i64
impl ShrRound<i8> for i64
sourcefn shr_round(self, bits: i8, rm: RoundingMode) -> i64
fn shr_round(self, bits: i8, rm: RoundingMode) -> i64
Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode.
Passing RoundingMode::Floor
or RoundingMode::Down
is equivalent to
using >>
. To test whether RoundingMode::Exact
can be passed, use
self.divisible_by_power_of_2(bits)
. Rounding might only be necessary if
bits
is non-negative.
Let $q = \frac{x}{2^p}$:
$f(x, p, \mathrm{Down}) = \operatorname{sgn}(q) \lfloor |q| \rfloor.$
$f(x, p, \mathrm{Up}) = \operatorname{sgn}(q) \lceil |q| \rceil.$
$f(x, p, \mathrm{Floor}) = \lfloor q \rfloor.$
$f(x, p, \mathrm{Ceiling}) = \lceil q \rceil.$
$$ f(x, p, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd}. \end{cases} $$
$f(x, p, \mathrm{Exact}) = q$, but panics if $q \notin \Z$.
Worst-case complexity
Constant time and additional memory.
Panics
Panics if bits
is positive and rm
is RoundingMode::Exact
but self
is
not divisible by $2^b$.
Examples
See here.
type Output = i64
sourceimpl ShrRound<i16> for i64
impl ShrRound<i16> for i64
sourcefn shr_round(self, bits: i16, rm: RoundingMode) -> i64
fn shr_round(self, bits: i16, rm: RoundingMode) -> i64
Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode.
Passing RoundingMode::Floor
or RoundingMode::Down
is equivalent to
using >>
. To test whether RoundingMode::Exact
can be passed, use
self.divisible_by_power_of_2(bits)
. Rounding might only be necessary if
bits
is non-negative.
Let $q = \frac{x}{2^p}$:
$f(x, p, \mathrm{Down}) = \operatorname{sgn}(q) \lfloor |q| \rfloor.$
$f(x, p, \mathrm{Up}) = \operatorname{sgn}(q) \lceil |q| \rceil.$
$f(x, p, \mathrm{Floor}) = \lfloor q \rfloor.$
$f(x, p, \mathrm{Ceiling}) = \lceil q \rceil.$
$$ f(x, p, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd}. \end{cases} $$
$f(x, p, \mathrm{Exact}) = q$, but panics if $q \notin \Z$.
Worst-case complexity
Constant time and additional memory.
Panics
Panics if bits
is positive and rm
is RoundingMode::Exact
but self
is
not divisible by $2^b$.
Examples
See here.
type Output = i64
sourceimpl ShrRound<i32> for i64
impl ShrRound<i32> for i64
sourcefn shr_round(self, bits: i32, rm: RoundingMode) -> i64
fn shr_round(self, bits: i32, rm: RoundingMode) -> i64
Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode.
Passing RoundingMode::Floor
or RoundingMode::Down
is equivalent to
using >>
. To test whether RoundingMode::Exact
can be passed, use
self.divisible_by_power_of_2(bits)
. Rounding might only be necessary if
bits
is non-negative.
Let $q = \frac{x}{2^p}$:
$f(x, p, \mathrm{Down}) = \operatorname{sgn}(q) \lfloor |q| \rfloor.$
$f(x, p, \mathrm{Up}) = \operatorname{sgn}(q) \lceil |q| \rceil.$
$f(x, p, \mathrm{Floor}) = \lfloor q \rfloor.$
$f(x, p, \mathrm{Ceiling}) = \lceil q \rceil.$
$$ f(x, p, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd}. \end{cases} $$
$f(x, p, \mathrm{Exact}) = q$, but panics if $q \notin \Z$.
Worst-case complexity
Constant time and additional memory.
Panics
Panics if bits
is positive and rm
is RoundingMode::Exact
but self
is
not divisible by $2^b$.
Examples
See here.
type Output = i64
sourceimpl ShrRound<i64> for i64
impl ShrRound<i64> for i64
sourcefn shr_round(self, bits: i64, rm: RoundingMode) -> i64
fn shr_round(self, bits: i64, rm: RoundingMode) -> i64
Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode.
Passing RoundingMode::Floor
or RoundingMode::Down
is equivalent to
using >>
. To test whether RoundingMode::Exact
can be passed, use
self.divisible_by_power_of_2(bits)
. Rounding might only be necessary if
bits
is non-negative.
Let $q = \frac{x}{2^p}$:
$f(x, p, \mathrm{Down}) = \operatorname{sgn}(q) \lfloor |q| \rfloor.$
$f(x, p, \mathrm{Up}) = \operatorname{sgn}(q) \lceil |q| \rceil.$
$f(x, p, \mathrm{Floor}) = \lfloor q \rfloor.$
$f(x, p, \mathrm{Ceiling}) = \lceil q \rceil.$
$$ f(x, p, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd}. \end{cases} $$
$f(x, p, \mathrm{Exact}) = q$, but panics if $q \notin \Z$.
Worst-case complexity
Constant time and additional memory.
Panics
Panics if bits
is positive and rm
is RoundingMode::Exact
but self
is
not divisible by $2^b$.
Examples
See here.
type Output = i64
sourceimpl ShrRound<i128> for i64
impl ShrRound<i128> for i64
sourcefn shr_round(self, bits: i128, rm: RoundingMode) -> i64
fn shr_round(self, bits: i128, rm: RoundingMode) -> i64
Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode.
Passing RoundingMode::Floor
or RoundingMode::Down
is equivalent to
using >>
. To test whether RoundingMode::Exact
can be passed, use
self.divisible_by_power_of_2(bits)
. Rounding might only be necessary if
bits
is non-negative.
Let $q = \frac{x}{2^p}$:
$f(x, p, \mathrm{Down}) = \operatorname{sgn}(q) \lfloor |q| \rfloor.$
$f(x, p, \mathrm{Up}) = \operatorname{sgn}(q) \lceil |q| \rceil.$
$f(x, p, \mathrm{Floor}) = \lfloor q \rfloor.$
$f(x, p, \mathrm{Ceiling}) = \lceil q \rceil.$
$$ f(x, p, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd}. \end{cases} $$
$f(x, p, \mathrm{Exact}) = q$, but panics if $q \notin \Z$.
Worst-case complexity
Constant time and additional memory.
Panics
Panics if bits
is positive and rm
is RoundingMode::Exact
but self
is
not divisible by $2^b$.
Examples
See here.
type Output = i64
sourceimpl ShrRound<isize> for i64
impl ShrRound<isize> for i64
sourcefn shr_round(self, bits: isize, rm: RoundingMode) -> i64
fn shr_round(self, bits: isize, rm: RoundingMode) -> i64
Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode.
Passing RoundingMode::Floor
or RoundingMode::Down
is equivalent to
using >>
. To test whether RoundingMode::Exact
can be passed, use
self.divisible_by_power_of_2(bits)
. Rounding might only be necessary if
bits
is non-negative.
Let $q = \frac{x}{2^p}$:
$f(x, p, \mathrm{Down}) = \operatorname{sgn}(q) \lfloor |q| \rfloor.$
$f(x, p, \mathrm{Up}) = \operatorname{sgn}(q) \lceil |q| \rceil.$
$f(x, p, \mathrm{Floor}) = \lfloor q \rfloor.$
$f(x, p, \mathrm{Ceiling}) = \lceil q \rceil.$
$$ f(x, p, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd}. \end{cases} $$
$f(x, p, \mathrm{Exact}) = q$, but panics if $q \notin \Z$.
Worst-case complexity
Constant time and additional memory.
Panics
Panics if bits
is positive and rm
is RoundingMode::Exact
but self
is
not divisible by $2^b$.
Examples
See here.
type Output = i64
sourceimpl ShrRound<i8> for i128
impl ShrRound<i8> for i128
sourcefn shr_round(self, bits: i8, rm: RoundingMode) -> i128
fn shr_round(self, bits: i8, rm: RoundingMode) -> i128
Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode.
Passing RoundingMode::Floor
or RoundingMode::Down
is equivalent to
using >>
. To test whether RoundingMode::Exact
can be passed, use
self.divisible_by_power_of_2(bits)
. Rounding might only be necessary if
bits
is non-negative.
Let $q = \frac{x}{2^p}$:
$f(x, p, \mathrm{Down}) = \operatorname{sgn}(q) \lfloor |q| \rfloor.$
$f(x, p, \mathrm{Up}) = \operatorname{sgn}(q) \lceil |q| \rceil.$
$f(x, p, \mathrm{Floor}) = \lfloor q \rfloor.$
$f(x, p, \mathrm{Ceiling}) = \lceil q \rceil.$
$$ f(x, p, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd}. \end{cases} $$
$f(x, p, \mathrm{Exact}) = q$, but panics if $q \notin \Z$.
Worst-case complexity
Constant time and additional memory.
Panics
Panics if bits
is positive and rm
is RoundingMode::Exact
but self
is
not divisible by $2^b$.
Examples
See here.
type Output = i128
sourceimpl ShrRound<i16> for i128
impl ShrRound<i16> for i128
sourcefn shr_round(self, bits: i16, rm: RoundingMode) -> i128
fn shr_round(self, bits: i16, rm: RoundingMode) -> i128
Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode.
Passing RoundingMode::Floor
or RoundingMode::Down
is equivalent to
using >>
. To test whether RoundingMode::Exact
can be passed, use
self.divisible_by_power_of_2(bits)
. Rounding might only be necessary if
bits
is non-negative.
Let $q = \frac{x}{2^p}$:
$f(x, p, \mathrm{Down}) = \operatorname{sgn}(q) \lfloor |q| \rfloor.$
$f(x, p, \mathrm{Up}) = \operatorname{sgn}(q) \lceil |q| \rceil.$
$f(x, p, \mathrm{Floor}) = \lfloor q \rfloor.$
$f(x, p, \mathrm{Ceiling}) = \lceil q \rceil.$
$$ f(x, p, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd}. \end{cases} $$
$f(x, p, \mathrm{Exact}) = q$, but panics if $q \notin \Z$.
Worst-case complexity
Constant time and additional memory.
Panics
Panics if bits
is positive and rm
is RoundingMode::Exact
but self
is
not divisible by $2^b$.
Examples
See here.
type Output = i128
sourceimpl ShrRound<i32> for i128
impl ShrRound<i32> for i128
sourcefn shr_round(self, bits: i32, rm: RoundingMode) -> i128
fn shr_round(self, bits: i32, rm: RoundingMode) -> i128
Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode.
Passing RoundingMode::Floor
or RoundingMode::Down
is equivalent to
using >>
. To test whether RoundingMode::Exact
can be passed, use
self.divisible_by_power_of_2(bits)
. Rounding might only be necessary if
bits
is non-negative.
Let $q = \frac{x}{2^p}$:
$f(x, p, \mathrm{Down}) = \operatorname{sgn}(q) \lfloor |q| \rfloor.$
$f(x, p, \mathrm{Up}) = \operatorname{sgn}(q) \lceil |q| \rceil.$
$f(x, p, \mathrm{Floor}) = \lfloor q \rfloor.$
$f(x, p, \mathrm{Ceiling}) = \lceil q \rceil.$
$$ f(x, p, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd}. \end{cases} $$
$f(x, p, \mathrm{Exact}) = q$, but panics if $q \notin \Z$.
Worst-case complexity
Constant time and additional memory.
Panics
Panics if bits
is positive and rm
is RoundingMode::Exact
but self
is
not divisible by $2^b$.
Examples
See here.
type Output = i128
sourceimpl ShrRound<i64> for i128
impl ShrRound<i64> for i128
sourcefn shr_round(self, bits: i64, rm: RoundingMode) -> i128
fn shr_round(self, bits: i64, rm: RoundingMode) -> i128
Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode.
Passing RoundingMode::Floor
or RoundingMode::Down
is equivalent to
using >>
. To test whether RoundingMode::Exact
can be passed, use
self.divisible_by_power_of_2(bits)
. Rounding might only be necessary if
bits
is non-negative.
Let $q = \frac{x}{2^p}$:
$f(x, p, \mathrm{Down}) = \operatorname{sgn}(q) \lfloor |q| \rfloor.$
$f(x, p, \mathrm{Up}) = \operatorname{sgn}(q) \lceil |q| \rceil.$
$f(x, p, \mathrm{Floor}) = \lfloor q \rfloor.$
$f(x, p, \mathrm{Ceiling}) = \lceil q \rceil.$
$$ f(x, p, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd}. \end{cases} $$
$f(x, p, \mathrm{Exact}) = q$, but panics if $q \notin \Z$.
Worst-case complexity
Constant time and additional memory.
Panics
Panics if bits
is positive and rm
is RoundingMode::Exact
but self
is
not divisible by $2^b$.
Examples
See here.
type Output = i128
sourceimpl ShrRound<i128> for i128
impl ShrRound<i128> for i128
sourcefn shr_round(self, bits: i128, rm: RoundingMode) -> i128
fn shr_round(self, bits: i128, rm: RoundingMode) -> i128
Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode.
Passing RoundingMode::Floor
or RoundingMode::Down
is equivalent to
using >>
. To test whether RoundingMode::Exact
can be passed, use
self.divisible_by_power_of_2(bits)
. Rounding might only be necessary if
bits
is non-negative.
Let $q = \frac{x}{2^p}$:
$f(x, p, \mathrm{Down}) = \operatorname{sgn}(q) \lfloor |q| \rfloor.$
$f(x, p, \mathrm{Up}) = \operatorname{sgn}(q) \lceil |q| \rceil.$
$f(x, p, \mathrm{Floor}) = \lfloor q \rfloor.$
$f(x, p, \mathrm{Ceiling}) = \lceil q \rceil.$
$$ f(x, p, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd}. \end{cases} $$
$f(x, p, \mathrm{Exact}) = q$, but panics if $q \notin \Z$.
Worst-case complexity
Constant time and additional memory.
Panics
Panics if bits
is positive and rm
is RoundingMode::Exact
but self
is
not divisible by $2^b$.
Examples
See here.
type Output = i128
sourceimpl ShrRound<isize> for i128
impl ShrRound<isize> for i128
sourcefn shr_round(self, bits: isize, rm: RoundingMode) -> i128
fn shr_round(self, bits: isize, rm: RoundingMode) -> i128
Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode.
Passing RoundingMode::Floor
or RoundingMode::Down
is equivalent to
using >>
. To test whether RoundingMode::Exact
can be passed, use
self.divisible_by_power_of_2(bits)
. Rounding might only be necessary if
bits
is non-negative.
Let $q = \frac{x}{2^p}$:
$f(x, p, \mathrm{Down}) = \operatorname{sgn}(q) \lfloor |q| \rfloor.$
$f(x, p, \mathrm{Up}) = \operatorname{sgn}(q) \lceil |q| \rceil.$
$f(x, p, \mathrm{Floor}) = \lfloor q \rfloor.$
$f(x, p, \mathrm{Ceiling}) = \lceil q \rceil.$
$$ f(x, p, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd}. \end{cases} $$
$f(x, p, \mathrm{Exact}) = q$, but panics if $q \notin \Z$.
Worst-case complexity
Constant time and additional memory.
Panics
Panics if bits
is positive and rm
is RoundingMode::Exact
but self
is
not divisible by $2^b$.
Examples
See here.
type Output = i128
sourceimpl ShrRound<i8> for isize
impl ShrRound<i8> for isize
sourcefn shr_round(self, bits: i8, rm: RoundingMode) -> isize
fn shr_round(self, bits: i8, rm: RoundingMode) -> isize
Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode.
Passing RoundingMode::Floor
or RoundingMode::Down
is equivalent to
using >>
. To test whether RoundingMode::Exact
can be passed, use
self.divisible_by_power_of_2(bits)
. Rounding might only be necessary if
bits
is non-negative.
Let $q = \frac{x}{2^p}$:
$f(x, p, \mathrm{Down}) = \operatorname{sgn}(q) \lfloor |q| \rfloor.$
$f(x, p, \mathrm{Up}) = \operatorname{sgn}(q) \lceil |q| \rceil.$
$f(x, p, \mathrm{Floor}) = \lfloor q \rfloor.$
$f(x, p, \mathrm{Ceiling}) = \lceil q \rceil.$
$$ f(x, p, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd}. \end{cases} $$
$f(x, p, \mathrm{Exact}) = q$, but panics if $q \notin \Z$.
Worst-case complexity
Constant time and additional memory.
Panics
Panics if bits
is positive and rm
is RoundingMode::Exact
but self
is
not divisible by $2^b$.
Examples
See here.
type Output = isize
sourceimpl ShrRound<i16> for isize
impl ShrRound<i16> for isize
sourcefn shr_round(self, bits: i16, rm: RoundingMode) -> isize
fn shr_round(self, bits: i16, rm: RoundingMode) -> isize
Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode.
Passing RoundingMode::Floor
or RoundingMode::Down
is equivalent to
using >>
. To test whether RoundingMode::Exact
can be passed, use
self.divisible_by_power_of_2(bits)
. Rounding might only be necessary if
bits
is non-negative.
Let $q = \frac{x}{2^p}$:
$f(x, p, \mathrm{Down}) = \operatorname{sgn}(q) \lfloor |q| \rfloor.$
$f(x, p, \mathrm{Up}) = \operatorname{sgn}(q) \lceil |q| \rceil.$
$f(x, p, \mathrm{Floor}) = \lfloor q \rfloor.$
$f(x, p, \mathrm{Ceiling}) = \lceil q \rceil.$
$$ f(x, p, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd}. \end{cases} $$
$f(x, p, \mathrm{Exact}) = q$, but panics if $q \notin \Z$.
Worst-case complexity
Constant time and additional memory.
Panics
Panics if bits
is positive and rm
is RoundingMode::Exact
but self
is
not divisible by $2^b$.
Examples
See here.
type Output = isize
sourceimpl ShrRound<i32> for isize
impl ShrRound<i32> for isize
sourcefn shr_round(self, bits: i32, rm: RoundingMode) -> isize
fn shr_round(self, bits: i32, rm: RoundingMode) -> isize
Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode.
Passing RoundingMode::Floor
or RoundingMode::Down
is equivalent to
using >>
. To test whether RoundingMode::Exact
can be passed, use
self.divisible_by_power_of_2(bits)
. Rounding might only be necessary if
bits
is non-negative.
Let $q = \frac{x}{2^p}$:
$f(x, p, \mathrm{Down}) = \operatorname{sgn}(q) \lfloor |q| \rfloor.$
$f(x, p, \mathrm{Up}) = \operatorname{sgn}(q) \lceil |q| \rceil.$
$f(x, p, \mathrm{Floor}) = \lfloor q \rfloor.$
$f(x, p, \mathrm{Ceiling}) = \lceil q \rceil.$
$$ f(x, p, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd}. \end{cases} $$
$f(x, p, \mathrm{Exact}) = q$, but panics if $q \notin \Z$.
Worst-case complexity
Constant time and additional memory.
Panics
Panics if bits
is positive and rm
is RoundingMode::Exact
but self
is
not divisible by $2^b$.
Examples
See here.
type Output = isize
sourceimpl ShrRound<i64> for isize
impl ShrRound<i64> for isize
sourcefn shr_round(self, bits: i64, rm: RoundingMode) -> isize
fn shr_round(self, bits: i64, rm: RoundingMode) -> isize
Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode.
Passing RoundingMode::Floor
or RoundingMode::Down
is equivalent to
using >>
. To test whether RoundingMode::Exact
can be passed, use
self.divisible_by_power_of_2(bits)
. Rounding might only be necessary if
bits
is non-negative.
Let $q = \frac{x}{2^p}$:
$f(x, p, \mathrm{Down}) = \operatorname{sgn}(q) \lfloor |q| \rfloor.$
$f(x, p, \mathrm{Up}) = \operatorname{sgn}(q) \lceil |q| \rceil.$
$f(x, p, \mathrm{Floor}) = \lfloor q \rfloor.$
$f(x, p, \mathrm{Ceiling}) = \lceil q \rceil.$
$$ f(x, p, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd}. \end{cases} $$
$f(x, p, \mathrm{Exact}) = q$, but panics if $q \notin \Z$.
Worst-case complexity
Constant time and additional memory.
Panics
Panics if bits
is positive and rm
is RoundingMode::Exact
but self
is
not divisible by $2^b$.
Examples
See here.
type Output = isize
sourceimpl ShrRound<i128> for isize
impl ShrRound<i128> for isize
sourcefn shr_round(self, bits: i128, rm: RoundingMode) -> isize
fn shr_round(self, bits: i128, rm: RoundingMode) -> isize
Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode.
Passing RoundingMode::Floor
or RoundingMode::Down
is equivalent to
using >>
. To test whether RoundingMode::Exact
can be passed, use
self.divisible_by_power_of_2(bits)
. Rounding might only be necessary if
bits
is non-negative.
Let $q = \frac{x}{2^p}$:
$f(x, p, \mathrm{Down}) = \operatorname{sgn}(q) \lfloor |q| \rfloor.$
$f(x, p, \mathrm{Up}) = \operatorname{sgn}(q) \lceil |q| \rceil.$
$f(x, p, \mathrm{Floor}) = \lfloor q \rfloor.$
$f(x, p, \mathrm{Ceiling}) = \lceil q \rceil.$
$$ f(x, p, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd}. \end{cases} $$
$f(x, p, \mathrm{Exact}) = q$, but panics if $q \notin \Z$.
Worst-case complexity
Constant time and additional memory.
Panics
Panics if bits
is positive and rm
is RoundingMode::Exact
but self
is
not divisible by $2^b$.
Examples
See here.
type Output = isize
sourceimpl ShrRound<isize> for isize
impl ShrRound<isize> for isize
sourcefn shr_round(self, bits: isize, rm: RoundingMode) -> isize
fn shr_round(self, bits: isize, rm: RoundingMode) -> isize
Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode.
Passing RoundingMode::Floor
or RoundingMode::Down
is equivalent to
using >>
. To test whether RoundingMode::Exact
can be passed, use
self.divisible_by_power_of_2(bits)
. Rounding might only be necessary if
bits
is non-negative.
Let $q = \frac{x}{2^p}$:
$f(x, p, \mathrm{Down}) = \operatorname{sgn}(q) \lfloor |q| \rfloor.$
$f(x, p, \mathrm{Up}) = \operatorname{sgn}(q) \lceil |q| \rceil.$
$f(x, p, \mathrm{Floor}) = \lfloor q \rfloor.$
$f(x, p, \mathrm{Ceiling}) = \lceil q \rceil.$
$$ f(x, p, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd}. \end{cases} $$
$f(x, p, \mathrm{Exact}) = q$, but panics if $q \notin \Z$.
Worst-case complexity
Constant time and additional memory.
Panics
Panics if bits
is positive and rm
is RoundingMode::Exact
but self
is
not divisible by $2^b$.
Examples
See here.