Trait malachite_base::num::arithmetic::traits::ShrRound

source ·
pub trait ShrRound<RHS> {
    type Output;

    // Required method
    fn shr_round(self, other: RHS, rm: RoundingMode) -> (Self::Output, Ordering);
}
Expand description

Right-shifts a number (divides it by a power of 2), rounding the result according to a specified rounding mode. An Ordering is also returned, indicating whether the returned value is less than, equal to, or greater than the exact value.

Rounding might only be necessary if other is positive.

Required Associated Types§

Required Methods§

source

fn shr_round(self, other: RHS, rm: RoundingMode) -> (Self::Output, Ordering)

Implementations on Foreign Types§

source§

impl ShrRound<i8> for i8

source§

fn shr_round(self, bits: i8, rm: RoundingMode) -> (i8, Ordering)

Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode. An Ordering is also returned, indicating whether the returned value is less than, equal to, or greater than the exact value. If bits is negative, then the returned Ordering is always Equal, even if the higher bits of the result are lost.

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^k}$, and let $g$ be the function that just returns the first element of the pair, without the Ordering:

$g(x, k, \mathrm{Down}) = \operatorname{sgn}(q) \lfloor |q| \rfloor.$

$g(x, k, \mathrm{Up}) = \operatorname{sgn}(q) \lceil |q| \rceil.$

$g(x, k, \mathrm{Floor}) = \lfloor q \rfloor.$

$g(x, k, \mathrm{Ceiling}) = \lceil q \rceil.$

$$ g(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} $$

$g(x, k, \mathrm{Exact}) = q$, but panics if $q \notin \Z$.

Then

$f(x, k, r) = (g(x, k, r), \operatorname{cmp}(g(x, k, r), q))$.

§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

source§

impl ShrRound<i8> for i16

source§

fn shr_round(self, bits: i8, rm: RoundingMode) -> (i16, Ordering)

Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode. An Ordering is also returned, indicating whether the returned value is less than, equal to, or greater than the exact value. If bits is negative, then the returned Ordering is always Equal, even if the higher bits of the result are lost.

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^k}$, and let $g$ be the function that just returns the first element of the pair, without the Ordering:

$g(x, k, \mathrm{Down}) = \operatorname{sgn}(q) \lfloor |q| \rfloor.$

$g(x, k, \mathrm{Up}) = \operatorname{sgn}(q) \lceil |q| \rceil.$

$g(x, k, \mathrm{Floor}) = \lfloor q \rfloor.$

$g(x, k, \mathrm{Ceiling}) = \lceil q \rceil.$

$$ g(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} $$

$g(x, k, \mathrm{Exact}) = q$, but panics if $q \notin \Z$.

Then

$f(x, k, r) = (g(x, k, r), \operatorname{cmp}(g(x, k, r), q))$.

§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

source§

impl ShrRound<i8> for i32

source§

fn shr_round(self, bits: i8, rm: RoundingMode) -> (i32, Ordering)

Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode. An Ordering is also returned, indicating whether the returned value is less than, equal to, or greater than the exact value. If bits is negative, then the returned Ordering is always Equal, even if the higher bits of the result are lost.

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^k}$, and let $g$ be the function that just returns the first element of the pair, without the Ordering:

$g(x, k, \mathrm{Down}) = \operatorname{sgn}(q) \lfloor |q| \rfloor.$

$g(x, k, \mathrm{Up}) = \operatorname{sgn}(q) \lceil |q| \rceil.$

$g(x, k, \mathrm{Floor}) = \lfloor q \rfloor.$

$g(x, k, \mathrm{Ceiling}) = \lceil q \rceil.$

$$ g(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} $$

$g(x, k, \mathrm{Exact}) = q$, but panics if $q \notin \Z$.

Then

$f(x, k, r) = (g(x, k, r), \operatorname{cmp}(g(x, k, r), q))$.

§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

source§

impl ShrRound<i8> for i64

source§

fn shr_round(self, bits: i8, rm: RoundingMode) -> (i64, Ordering)

Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode. An Ordering is also returned, indicating whether the returned value is less than, equal to, or greater than the exact value. If bits is negative, then the returned Ordering is always Equal, even if the higher bits of the result are lost.

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^k}$, and let $g$ be the function that just returns the first element of the pair, without the Ordering:

$g(x, k, \mathrm{Down}) = \operatorname{sgn}(q) \lfloor |q| \rfloor.$

$g(x, k, \mathrm{Up}) = \operatorname{sgn}(q) \lceil |q| \rceil.$

$g(x, k, \mathrm{Floor}) = \lfloor q \rfloor.$

$g(x, k, \mathrm{Ceiling}) = \lceil q \rceil.$

$$ g(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} $$

$g(x, k, \mathrm{Exact}) = q$, but panics if $q \notin \Z$.

Then

$f(x, k, r) = (g(x, k, r), \operatorname{cmp}(g(x, k, r), q))$.

§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

source§

impl ShrRound<i8> for i128

source§

fn shr_round(self, bits: i8, rm: RoundingMode) -> (i128, Ordering)

Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode. An Ordering is also returned, indicating whether the returned value is less than, equal to, or greater than the exact value. If bits is negative, then the returned Ordering is always Equal, even if the higher bits of the result are lost.

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^k}$, and let $g$ be the function that just returns the first element of the pair, without the Ordering:

$g(x, k, \mathrm{Down}) = \operatorname{sgn}(q) \lfloor |q| \rfloor.$

$g(x, k, \mathrm{Up}) = \operatorname{sgn}(q) \lceil |q| \rceil.$

$g(x, k, \mathrm{Floor}) = \lfloor q \rfloor.$

$g(x, k, \mathrm{Ceiling}) = \lceil q \rceil.$

$$ g(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} $$

$g(x, k, \mathrm{Exact}) = q$, but panics if $q \notin \Z$.

Then

$f(x, k, r) = (g(x, k, r), \operatorname{cmp}(g(x, k, r), q))$.

§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

source§

impl ShrRound<i8> for isize

source§

fn shr_round(self, bits: i8, rm: RoundingMode) -> (isize, Ordering)

Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode. An Ordering is also returned, indicating whether the returned value is less than, equal to, or greater than the exact value. If bits is negative, then the returned Ordering is always Equal, even if the higher bits of the result are lost.

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^k}$, and let $g$ be the function that just returns the first element of the pair, without the Ordering:

$g(x, k, \mathrm{Down}) = \operatorname{sgn}(q) \lfloor |q| \rfloor.$

$g(x, k, \mathrm{Up}) = \operatorname{sgn}(q) \lceil |q| \rceil.$

$g(x, k, \mathrm{Floor}) = \lfloor q \rfloor.$

$g(x, k, \mathrm{Ceiling}) = \lceil q \rceil.$

$$ g(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} $$

$g(x, k, \mathrm{Exact}) = q$, but panics if $q \notin \Z$.

Then

$f(x, k, r) = (g(x, k, r), \operatorname{cmp}(g(x, k, r), q))$.

§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

source§

impl ShrRound<i8> for u8

source§

fn shr_round(self, bits: i8, rm: RoundingMode) -> (u8, Ordering)

Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode. An Ordering is also returned, indicating whether the returned value is less than, equal to, or greater than the exact value. If bits is negative, then the returned Ordering is always Equal, even if the higher bits of the result are lost.

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^k}$, and let $g$ be the function that just returns the first element of the pair, without the Ordering:

$g(x, k, \mathrm{Down}) = \operatorname{sgn}(q) \lfloor |q| \rfloor.$

$g(x, k, \mathrm{Up}) = \operatorname{sgn}(q) \lceil |q| \rceil.$

$g(x, k, \mathrm{Floor}) = \lfloor q \rfloor.$

$g(x, k, \mathrm{Ceiling}) = \lceil q \rceil.$

$$ g(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} $$

$g(x, k, \mathrm{Exact}) = q$, but panics if $q \notin \Z$.

Then

$f(x, k, r) = (g(x, k, r), \operatorname{cmp}(g(x, k, r), q))$.

§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

source§

impl ShrRound<i8> for u16

source§

fn shr_round(self, bits: i8, rm: RoundingMode) -> (u16, Ordering)

Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode. An Ordering is also returned, indicating whether the returned value is less than, equal to, or greater than the exact value. If bits is negative, then the returned Ordering is always Equal, even if the higher bits of the result are lost.

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^k}$, and let $g$ be the function that just returns the first element of the pair, without the Ordering:

$g(x, k, \mathrm{Down}) = \operatorname{sgn}(q) \lfloor |q| \rfloor.$

$g(x, k, \mathrm{Up}) = \operatorname{sgn}(q) \lceil |q| \rceil.$

$g(x, k, \mathrm{Floor}) = \lfloor q \rfloor.$

$g(x, k, \mathrm{Ceiling}) = \lceil q \rceil.$

$$ g(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} $$

$g(x, k, \mathrm{Exact}) = q$, but panics if $q \notin \Z$.

Then

$f(x, k, r) = (g(x, k, r), \operatorname{cmp}(g(x, k, r), q))$.

§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

source§

impl ShrRound<i8> for u32

source§

fn shr_round(self, bits: i8, rm: RoundingMode) -> (u32, Ordering)

Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode. An Ordering is also returned, indicating whether the returned value is less than, equal to, or greater than the exact value. If bits is negative, then the returned Ordering is always Equal, even if the higher bits of the result are lost.

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^k}$, and let $g$ be the function that just returns the first element of the pair, without the Ordering:

$g(x, k, \mathrm{Down}) = \operatorname{sgn}(q) \lfloor |q| \rfloor.$

$g(x, k, \mathrm{Up}) = \operatorname{sgn}(q) \lceil |q| \rceil.$

$g(x, k, \mathrm{Floor}) = \lfloor q \rfloor.$

$g(x, k, \mathrm{Ceiling}) = \lceil q \rceil.$

$$ g(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} $$

$g(x, k, \mathrm{Exact}) = q$, but panics if $q \notin \Z$.

Then

$f(x, k, r) = (g(x, k, r), \operatorname{cmp}(g(x, k, r), q))$.

§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

source§

impl ShrRound<i8> for u64

source§

fn shr_round(self, bits: i8, rm: RoundingMode) -> (u64, Ordering)

Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode. An Ordering is also returned, indicating whether the returned value is less than, equal to, or greater than the exact value. If bits is negative, then the returned Ordering is always Equal, even if the higher bits of the result are lost.

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^k}$, and let $g$ be the function that just returns the first element of the pair, without the Ordering:

$g(x, k, \mathrm{Down}) = \operatorname{sgn}(q) \lfloor |q| \rfloor.$

$g(x, k, \mathrm{Up}) = \operatorname{sgn}(q) \lceil |q| \rceil.$

$g(x, k, \mathrm{Floor}) = \lfloor q \rfloor.$

$g(x, k, \mathrm{Ceiling}) = \lceil q \rceil.$

$$ g(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} $$

$g(x, k, \mathrm{Exact}) = q$, but panics if $q \notin \Z$.

Then

$f(x, k, r) = (g(x, k, r), \operatorname{cmp}(g(x, k, r), q))$.

§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

source§

impl ShrRound<i8> for u128

source§

fn shr_round(self, bits: i8, rm: RoundingMode) -> (u128, Ordering)

Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode. An Ordering is also returned, indicating whether the returned value is less than, equal to, or greater than the exact value. If bits is negative, then the returned Ordering is always Equal, even if the higher bits of the result are lost.

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^k}$, and let $g$ be the function that just returns the first element of the pair, without the Ordering:

$g(x, k, \mathrm{Down}) = \operatorname{sgn}(q) \lfloor |q| \rfloor.$

$g(x, k, \mathrm{Up}) = \operatorname{sgn}(q) \lceil |q| \rceil.$

$g(x, k, \mathrm{Floor}) = \lfloor q \rfloor.$

$g(x, k, \mathrm{Ceiling}) = \lceil q \rceil.$

$$ g(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} $$

$g(x, k, \mathrm{Exact}) = q$, but panics if $q \notin \Z$.

Then

$f(x, k, r) = (g(x, k, r), \operatorname{cmp}(g(x, k, r), q))$.

§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

source§

impl ShrRound<i8> for usize

source§

fn shr_round(self, bits: i8, rm: RoundingMode) -> (usize, Ordering)

Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode. An Ordering is also returned, indicating whether the returned value is less than, equal to, or greater than the exact value. If bits is negative, then the returned Ordering is always Equal, even if the higher bits of the result are lost.

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^k}$, and let $g$ be the function that just returns the first element of the pair, without the Ordering:

$g(x, k, \mathrm{Down}) = \operatorname{sgn}(q) \lfloor |q| \rfloor.$

$g(x, k, \mathrm{Up}) = \operatorname{sgn}(q) \lceil |q| \rceil.$

$g(x, k, \mathrm{Floor}) = \lfloor q \rfloor.$

$g(x, k, \mathrm{Ceiling}) = \lceil q \rceil.$

$$ g(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} $$

$g(x, k, \mathrm{Exact}) = q$, but panics if $q \notin \Z$.

Then

$f(x, k, r) = (g(x, k, r), \operatorname{cmp}(g(x, k, r), q))$.

§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

source§

impl ShrRound<i16> for i8

source§

fn shr_round(self, bits: i16, rm: RoundingMode) -> (i8, Ordering)

Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode. An Ordering is also returned, indicating whether the returned value is less than, equal to, or greater than the exact value. If bits is negative, then the returned Ordering is always Equal, even if the higher bits of the result are lost.

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^k}$, and let $g$ be the function that just returns the first element of the pair, without the Ordering:

$g(x, k, \mathrm{Down}) = \operatorname{sgn}(q) \lfloor |q| \rfloor.$

$g(x, k, \mathrm{Up}) = \operatorname{sgn}(q) \lceil |q| \rceil.$

$g(x, k, \mathrm{Floor}) = \lfloor q \rfloor.$

$g(x, k, \mathrm{Ceiling}) = \lceil q \rceil.$

$$ g(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} $$

$g(x, k, \mathrm{Exact}) = q$, but panics if $q \notin \Z$.

Then

$f(x, k, r) = (g(x, k, r), \operatorname{cmp}(g(x, k, r), q))$.

§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

source§

impl ShrRound<i16> for i16

source§

fn shr_round(self, bits: i16, rm: RoundingMode) -> (i16, Ordering)

Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode. An Ordering is also returned, indicating whether the returned value is less than, equal to, or greater than the exact value. If bits is negative, then the returned Ordering is always Equal, even if the higher bits of the result are lost.

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^k}$, and let $g$ be the function that just returns the first element of the pair, without the Ordering:

$g(x, k, \mathrm{Down}) = \operatorname{sgn}(q) \lfloor |q| \rfloor.$

$g(x, k, \mathrm{Up}) = \operatorname{sgn}(q) \lceil |q| \rceil.$

$g(x, k, \mathrm{Floor}) = \lfloor q \rfloor.$

$g(x, k, \mathrm{Ceiling}) = \lceil q \rceil.$

$$ g(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} $$

$g(x, k, \mathrm{Exact}) = q$, but panics if $q \notin \Z$.

Then

$f(x, k, r) = (g(x, k, r), \operatorname{cmp}(g(x, k, r), q))$.

§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

source§

impl ShrRound<i16> for i32

source§

fn shr_round(self, bits: i16, rm: RoundingMode) -> (i32, Ordering)

Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode. An Ordering is also returned, indicating whether the returned value is less than, equal to, or greater than the exact value. If bits is negative, then the returned Ordering is always Equal, even if the higher bits of the result are lost.

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^k}$, and let $g$ be the function that just returns the first element of the pair, without the Ordering:

$g(x, k, \mathrm{Down}) = \operatorname{sgn}(q) \lfloor |q| \rfloor.$

$g(x, k, \mathrm{Up}) = \operatorname{sgn}(q) \lceil |q| \rceil.$

$g(x, k, \mathrm{Floor}) = \lfloor q \rfloor.$

$g(x, k, \mathrm{Ceiling}) = \lceil q \rceil.$

$$ g(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} $$

$g(x, k, \mathrm{Exact}) = q$, but panics if $q \notin \Z$.

Then

$f(x, k, r) = (g(x, k, r), \operatorname{cmp}(g(x, k, r), q))$.

§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

source§

impl ShrRound<i16> for i64

source§

fn shr_round(self, bits: i16, rm: RoundingMode) -> (i64, Ordering)

Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode. An Ordering is also returned, indicating whether the returned value is less than, equal to, or greater than the exact value. If bits is negative, then the returned Ordering is always Equal, even if the higher bits of the result are lost.

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^k}$, and let $g$ be the function that just returns the first element of the pair, without the Ordering:

$g(x, k, \mathrm{Down}) = \operatorname{sgn}(q) \lfloor |q| \rfloor.$

$g(x, k, \mathrm{Up}) = \operatorname{sgn}(q) \lceil |q| \rceil.$

$g(x, k, \mathrm{Floor}) = \lfloor q \rfloor.$

$g(x, k, \mathrm{Ceiling}) = \lceil q \rceil.$

$$ g(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} $$

$g(x, k, \mathrm{Exact}) = q$, but panics if $q \notin \Z$.

Then

$f(x, k, r) = (g(x, k, r), \operatorname{cmp}(g(x, k, r), q))$.

§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

source§

impl ShrRound<i16> for i128

source§

fn shr_round(self, bits: i16, rm: RoundingMode) -> (i128, Ordering)

Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode. An Ordering is also returned, indicating whether the returned value is less than, equal to, or greater than the exact value. If bits is negative, then the returned Ordering is always Equal, even if the higher bits of the result are lost.

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^k}$, and let $g$ be the function that just returns the first element of the pair, without the Ordering:

$g(x, k, \mathrm{Down}) = \operatorname{sgn}(q) \lfloor |q| \rfloor.$

$g(x, k, \mathrm{Up}) = \operatorname{sgn}(q) \lceil |q| \rceil.$

$g(x, k, \mathrm{Floor}) = \lfloor q \rfloor.$

$g(x, k, \mathrm{Ceiling}) = \lceil q \rceil.$

$$ g(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} $$

$g(x, k, \mathrm{Exact}) = q$, but panics if $q \notin \Z$.

Then

$f(x, k, r) = (g(x, k, r), \operatorname{cmp}(g(x, k, r), q))$.

§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

source§

impl ShrRound<i16> for isize

source§

fn shr_round(self, bits: i16, rm: RoundingMode) -> (isize, Ordering)

Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode. An Ordering is also returned, indicating whether the returned value is less than, equal to, or greater than the exact value. If bits is negative, then the returned Ordering is always Equal, even if the higher bits of the result are lost.

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^k}$, and let $g$ be the function that just returns the first element of the pair, without the Ordering:

$g(x, k, \mathrm{Down}) = \operatorname{sgn}(q) \lfloor |q| \rfloor.$

$g(x, k, \mathrm{Up}) = \operatorname{sgn}(q) \lceil |q| \rceil.$

$g(x, k, \mathrm{Floor}) = \lfloor q \rfloor.$

$g(x, k, \mathrm{Ceiling}) = \lceil q \rceil.$

$$ g(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} $$

$g(x, k, \mathrm{Exact}) = q$, but panics if $q \notin \Z$.

Then

$f(x, k, r) = (g(x, k, r), \operatorname{cmp}(g(x, k, r), q))$.

§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

source§

impl ShrRound<i16> for u8

source§

fn shr_round(self, bits: i16, rm: RoundingMode) -> (u8, Ordering)

Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode. An Ordering is also returned, indicating whether the returned value is less than, equal to, or greater than the exact value. If bits is negative, then the returned Ordering is always Equal, even if the higher bits of the result are lost.

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^k}$, and let $g$ be the function that just returns the first element of the pair, without the Ordering:

$g(x, k, \mathrm{Down}) = \operatorname{sgn}(q) \lfloor |q| \rfloor.$

$g(x, k, \mathrm{Up}) = \operatorname{sgn}(q) \lceil |q| \rceil.$

$g(x, k, \mathrm{Floor}) = \lfloor q \rfloor.$

$g(x, k, \mathrm{Ceiling}) = \lceil q \rceil.$

$$ g(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} $$

$g(x, k, \mathrm{Exact}) = q$, but panics if $q \notin \Z$.

Then

$f(x, k, r) = (g(x, k, r), \operatorname{cmp}(g(x, k, r), q))$.

§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

source§

impl ShrRound<i16> for u16

source§

fn shr_round(self, bits: i16, rm: RoundingMode) -> (u16, Ordering)

Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode. An Ordering is also returned, indicating whether the returned value is less than, equal to, or greater than the exact value. If bits is negative, then the returned Ordering is always Equal, even if the higher bits of the result are lost.

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^k}$, and let $g$ be the function that just returns the first element of the pair, without the Ordering:

$g(x, k, \mathrm{Down}) = \operatorname{sgn}(q) \lfloor |q| \rfloor.$

$g(x, k, \mathrm{Up}) = \operatorname{sgn}(q) \lceil |q| \rceil.$

$g(x, k, \mathrm{Floor}) = \lfloor q \rfloor.$

$g(x, k, \mathrm{Ceiling}) = \lceil q \rceil.$

$$ g(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} $$

$g(x, k, \mathrm{Exact}) = q$, but panics if $q \notin \Z$.

Then

$f(x, k, r) = (g(x, k, r), \operatorname{cmp}(g(x, k, r), q))$.

§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

source§

impl ShrRound<i16> for u32

source§

fn shr_round(self, bits: i16, rm: RoundingMode) -> (u32, Ordering)

Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode. An Ordering is also returned, indicating whether the returned value is less than, equal to, or greater than the exact value. If bits is negative, then the returned Ordering is always Equal, even if the higher bits of the result are lost.

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^k}$, and let $g$ be the function that just returns the first element of the pair, without the Ordering:

$g(x, k, \mathrm{Down}) = \operatorname{sgn}(q) \lfloor |q| \rfloor.$

$g(x, k, \mathrm{Up}) = \operatorname{sgn}(q) \lceil |q| \rceil.$

$g(x, k, \mathrm{Floor}) = \lfloor q \rfloor.$

$g(x, k, \mathrm{Ceiling}) = \lceil q \rceil.$

$$ g(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} $$

$g(x, k, \mathrm{Exact}) = q$, but panics if $q \notin \Z$.

Then

$f(x, k, r) = (g(x, k, r), \operatorname{cmp}(g(x, k, r), q))$.

§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

source§

impl ShrRound<i16> for u64

source§

fn shr_round(self, bits: i16, rm: RoundingMode) -> (u64, Ordering)

Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode. An Ordering is also returned, indicating whether the returned value is less than, equal to, or greater than the exact value. If bits is negative, then the returned Ordering is always Equal, even if the higher bits of the result are lost.

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^k}$, and let $g$ be the function that just returns the first element of the pair, without the Ordering:

$g(x, k, \mathrm{Down}) = \operatorname{sgn}(q) \lfloor |q| \rfloor.$

$g(x, k, \mathrm{Up}) = \operatorname{sgn}(q) \lceil |q| \rceil.$

$g(x, k, \mathrm{Floor}) = \lfloor q \rfloor.$

$g(x, k, \mathrm{Ceiling}) = \lceil q \rceil.$

$$ g(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} $$

$g(x, k, \mathrm{Exact}) = q$, but panics if $q \notin \Z$.

Then

$f(x, k, r) = (g(x, k, r), \operatorname{cmp}(g(x, k, r), q))$.

§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

source§

impl ShrRound<i16> for u128

source§

fn shr_round(self, bits: i16, rm: RoundingMode) -> (u128, Ordering)

Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode. An Ordering is also returned, indicating whether the returned value is less than, equal to, or greater than the exact value. If bits is negative, then the returned Ordering is always Equal, even if the higher bits of the result are lost.

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^k}$, and let $g$ be the function that just returns the first element of the pair, without the Ordering:

$g(x, k, \mathrm{Down}) = \operatorname{sgn}(q) \lfloor |q| \rfloor.$

$g(x, k, \mathrm{Up}) = \operatorname{sgn}(q) \lceil |q| \rceil.$

$g(x, k, \mathrm{Floor}) = \lfloor q \rfloor.$

$g(x, k, \mathrm{Ceiling}) = \lceil q \rceil.$

$$ g(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} $$

$g(x, k, \mathrm{Exact}) = q$, but panics if $q \notin \Z$.

Then

$f(x, k, r) = (g(x, k, r), \operatorname{cmp}(g(x, k, r), q))$.

§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

source§

impl ShrRound<i16> for usize

source§

fn shr_round(self, bits: i16, rm: RoundingMode) -> (usize, Ordering)

Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode. An Ordering is also returned, indicating whether the returned value is less than, equal to, or greater than the exact value. If bits is negative, then the returned Ordering is always Equal, even if the higher bits of the result are lost.

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^k}$, and let $g$ be the function that just returns the first element of the pair, without the Ordering:

$g(x, k, \mathrm{Down}) = \operatorname{sgn}(q) \lfloor |q| \rfloor.$

$g(x, k, \mathrm{Up}) = \operatorname{sgn}(q) \lceil |q| \rceil.$

$g(x, k, \mathrm{Floor}) = \lfloor q \rfloor.$

$g(x, k, \mathrm{Ceiling}) = \lceil q \rceil.$

$$ g(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} $$

$g(x, k, \mathrm{Exact}) = q$, but panics if $q \notin \Z$.

Then

$f(x, k, r) = (g(x, k, r), \operatorname{cmp}(g(x, k, r), q))$.

§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

source§

impl ShrRound<i32> for i8

source§

fn shr_round(self, bits: i32, rm: RoundingMode) -> (i8, Ordering)

Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode. An Ordering is also returned, indicating whether the returned value is less than, equal to, or greater than the exact value. If bits is negative, then the returned Ordering is always Equal, even if the higher bits of the result are lost.

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^k}$, and let $g$ be the function that just returns the first element of the pair, without the Ordering:

$g(x, k, \mathrm{Down}) = \operatorname{sgn}(q) \lfloor |q| \rfloor.$

$g(x, k, \mathrm{Up}) = \operatorname{sgn}(q) \lceil |q| \rceil.$

$g(x, k, \mathrm{Floor}) = \lfloor q \rfloor.$

$g(x, k, \mathrm{Ceiling}) = \lceil q \rceil.$

$$ g(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} $$

$g(x, k, \mathrm{Exact}) = q$, but panics if $q \notin \Z$.

Then

$f(x, k, r) = (g(x, k, r), \operatorname{cmp}(g(x, k, r), q))$.

§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

source§

impl ShrRound<i32> for i16

source§

fn shr_round(self, bits: i32, rm: RoundingMode) -> (i16, Ordering)

Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode. An Ordering is also returned, indicating whether the returned value is less than, equal to, or greater than the exact value. If bits is negative, then the returned Ordering is always Equal, even if the higher bits of the result are lost.

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^k}$, and let $g$ be the function that just returns the first element of the pair, without the Ordering:

$g(x, k, \mathrm{Down}) = \operatorname{sgn}(q) \lfloor |q| \rfloor.$

$g(x, k, \mathrm{Up}) = \operatorname{sgn}(q) \lceil |q| \rceil.$

$g(x, k, \mathrm{Floor}) = \lfloor q \rfloor.$

$g(x, k, \mathrm{Ceiling}) = \lceil q \rceil.$

$$ g(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} $$

$g(x, k, \mathrm{Exact}) = q$, but panics if $q \notin \Z$.

Then

$f(x, k, r) = (g(x, k, r), \operatorname{cmp}(g(x, k, r), q))$.

§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

source§

impl ShrRound<i32> for i32

source§

fn shr_round(self, bits: i32, rm: RoundingMode) -> (i32, Ordering)

Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode. An Ordering is also returned, indicating whether the returned value is less than, equal to, or greater than the exact value. If bits is negative, then the returned Ordering is always Equal, even if the higher bits of the result are lost.

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^k}$, and let $g$ be the function that just returns the first element of the pair, without the Ordering:

$g(x, k, \mathrm{Down}) = \operatorname{sgn}(q) \lfloor |q| \rfloor.$

$g(x, k, \mathrm{Up}) = \operatorname{sgn}(q) \lceil |q| \rceil.$

$g(x, k, \mathrm{Floor}) = \lfloor q \rfloor.$

$g(x, k, \mathrm{Ceiling}) = \lceil q \rceil.$

$$ g(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} $$

$g(x, k, \mathrm{Exact}) = q$, but panics if $q \notin \Z$.

Then

$f(x, k, r) = (g(x, k, r), \operatorname{cmp}(g(x, k, r), q))$.

§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

source§

impl ShrRound<i32> for i64

source§

fn shr_round(self, bits: i32, rm: RoundingMode) -> (i64, Ordering)

Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode. An Ordering is also returned, indicating whether the returned value is less than, equal to, or greater than the exact value. If bits is negative, then the returned Ordering is always Equal, even if the higher bits of the result are lost.

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^k}$, and let $g$ be the function that just returns the first element of the pair, without the Ordering:

$g(x, k, \mathrm{Down}) = \operatorname{sgn}(q) \lfloor |q| \rfloor.$

$g(x, k, \mathrm{Up}) = \operatorname{sgn}(q) \lceil |q| \rceil.$

$g(x, k, \mathrm{Floor}) = \lfloor q \rfloor.$

$g(x, k, \mathrm{Ceiling}) = \lceil q \rceil.$

$$ g(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} $$

$g(x, k, \mathrm{Exact}) = q$, but panics if $q \notin \Z$.

Then

$f(x, k, r) = (g(x, k, r), \operatorname{cmp}(g(x, k, r), q))$.

§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

source§

impl ShrRound<i32> for i128

source§

fn shr_round(self, bits: i32, rm: RoundingMode) -> (i128, Ordering)

Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode. An Ordering is also returned, indicating whether the returned value is less than, equal to, or greater than the exact value. If bits is negative, then the returned Ordering is always Equal, even if the higher bits of the result are lost.

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^k}$, and let $g$ be the function that just returns the first element of the pair, without the Ordering:

$g(x, k, \mathrm{Down}) = \operatorname{sgn}(q) \lfloor |q| \rfloor.$

$g(x, k, \mathrm{Up}) = \operatorname{sgn}(q) \lceil |q| \rceil.$

$g(x, k, \mathrm{Floor}) = \lfloor q \rfloor.$

$g(x, k, \mathrm{Ceiling}) = \lceil q \rceil.$

$$ g(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} $$

$g(x, k, \mathrm{Exact}) = q$, but panics if $q \notin \Z$.

Then

$f(x, k, r) = (g(x, k, r), \operatorname{cmp}(g(x, k, r), q))$.

§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

source§

impl ShrRound<i32> for isize

source§

fn shr_round(self, bits: i32, rm: RoundingMode) -> (isize, Ordering)

Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode. An Ordering is also returned, indicating whether the returned value is less than, equal to, or greater than the exact value. If bits is negative, then the returned Ordering is always Equal, even if the higher bits of the result are lost.

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^k}$, and let $g$ be the function that just returns the first element of the pair, without the Ordering:

$g(x, k, \mathrm{Down}) = \operatorname{sgn}(q) \lfloor |q| \rfloor.$

$g(x, k, \mathrm{Up}) = \operatorname{sgn}(q) \lceil |q| \rceil.$

$g(x, k, \mathrm{Floor}) = \lfloor q \rfloor.$

$g(x, k, \mathrm{Ceiling}) = \lceil q \rceil.$

$$ g(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} $$

$g(x, k, \mathrm{Exact}) = q$, but panics if $q \notin \Z$.

Then

$f(x, k, r) = (g(x, k, r), \operatorname{cmp}(g(x, k, r), q))$.

§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

source§

impl ShrRound<i32> for u8

source§

fn shr_round(self, bits: i32, rm: RoundingMode) -> (u8, Ordering)

Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode. An Ordering is also returned, indicating whether the returned value is less than, equal to, or greater than the exact value. If bits is negative, then the returned Ordering is always Equal, even if the higher bits of the result are lost.

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^k}$, and let $g$ be the function that just returns the first element of the pair, without the Ordering:

$g(x, k, \mathrm{Down}) = \operatorname{sgn}(q) \lfloor |q| \rfloor.$

$g(x, k, \mathrm{Up}) = \operatorname{sgn}(q) \lceil |q| \rceil.$

$g(x, k, \mathrm{Floor}) = \lfloor q \rfloor.$

$g(x, k, \mathrm{Ceiling}) = \lceil q \rceil.$

$$ g(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} $$

$g(x, k, \mathrm{Exact}) = q$, but panics if $q \notin \Z$.

Then

$f(x, k, r) = (g(x, k, r), \operatorname{cmp}(g(x, k, r), q))$.

§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

source§

impl ShrRound<i32> for u16

source§

fn shr_round(self, bits: i32, rm: RoundingMode) -> (u16, Ordering)

Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode. An Ordering is also returned, indicating whether the returned value is less than, equal to, or greater than the exact value. If bits is negative, then the returned Ordering is always Equal, even if the higher bits of the result are lost.

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^k}$, and let $g$ be the function that just returns the first element of the pair, without the Ordering:

$g(x, k, \mathrm{Down}) = \operatorname{sgn}(q) \lfloor |q| \rfloor.$

$g(x, k, \mathrm{Up}) = \operatorname{sgn}(q) \lceil |q| \rceil.$

$g(x, k, \mathrm{Floor}) = \lfloor q \rfloor.$

$g(x, k, \mathrm{Ceiling}) = \lceil q \rceil.$

$$ g(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} $$

$g(x, k, \mathrm{Exact}) = q$, but panics if $q \notin \Z$.

Then

$f(x, k, r) = (g(x, k, r), \operatorname{cmp}(g(x, k, r), q))$.

§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

source§

impl ShrRound<i32> for u32

source§

fn shr_round(self, bits: i32, rm: RoundingMode) -> (u32, Ordering)

Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode. An Ordering is also returned, indicating whether the returned value is less than, equal to, or greater than the exact value. If bits is negative, then the returned Ordering is always Equal, even if the higher bits of the result are lost.

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^k}$, and let $g$ be the function that just returns the first element of the pair, without the Ordering:

$g(x, k, \mathrm{Down}) = \operatorname{sgn}(q) \lfloor |q| \rfloor.$

$g(x, k, \mathrm{Up}) = \operatorname{sgn}(q) \lceil |q| \rceil.$

$g(x, k, \mathrm{Floor}) = \lfloor q \rfloor.$

$g(x, k, \mathrm{Ceiling}) = \lceil q \rceil.$

$$ g(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} $$

$g(x, k, \mathrm{Exact}) = q$, but panics if $q \notin \Z$.

Then

$f(x, k, r) = (g(x, k, r), \operatorname{cmp}(g(x, k, r), q))$.

§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

source§

impl ShrRound<i32> for u64

source§

fn shr_round(self, bits: i32, rm: RoundingMode) -> (u64, Ordering)

Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode. An Ordering is also returned, indicating whether the returned value is less than, equal to, or greater than the exact value. If bits is negative, then the returned Ordering is always Equal, even if the higher bits of the result are lost.

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^k}$, and let $g$ be the function that just returns the first element of the pair, without the Ordering:

$g(x, k, \mathrm{Down}) = \operatorname{sgn}(q) \lfloor |q| \rfloor.$

$g(x, k, \mathrm{Up}) = \operatorname{sgn}(q) \lceil |q| \rceil.$

$g(x, k, \mathrm{Floor}) = \lfloor q \rfloor.$

$g(x, k, \mathrm{Ceiling}) = \lceil q \rceil.$

$$ g(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} $$

$g(x, k, \mathrm{Exact}) = q$, but panics if $q \notin \Z$.

Then

$f(x, k, r) = (g(x, k, r), \operatorname{cmp}(g(x, k, r), q))$.

§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

source§

impl ShrRound<i32> for u128

source§

fn shr_round(self, bits: i32, rm: RoundingMode) -> (u128, Ordering)

Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode. An Ordering is also returned, indicating whether the returned value is less than, equal to, or greater than the exact value. If bits is negative, then the returned Ordering is always Equal, even if the higher bits of the result are lost.

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^k}$, and let $g$ be the function that just returns the first element of the pair, without the Ordering:

$g(x, k, \mathrm{Down}) = \operatorname{sgn}(q) \lfloor |q| \rfloor.$

$g(x, k, \mathrm{Up}) = \operatorname{sgn}(q) \lceil |q| \rceil.$

$g(x, k, \mathrm{Floor}) = \lfloor q \rfloor.$

$g(x, k, \mathrm{Ceiling}) = \lceil q \rceil.$

$$ g(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} $$

$g(x, k, \mathrm{Exact}) = q$, but panics if $q \notin \Z$.

Then

$f(x, k, r) = (g(x, k, r), \operatorname{cmp}(g(x, k, r), q))$.

§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

source§

impl ShrRound<i32> for usize

source§

fn shr_round(self, bits: i32, rm: RoundingMode) -> (usize, Ordering)

Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode. An Ordering is also returned, indicating whether the returned value is less than, equal to, or greater than the exact value. If bits is negative, then the returned Ordering is always Equal, even if the higher bits of the result are lost.

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^k}$, and let $g$ be the function that just returns the first element of the pair, without the Ordering:

$g(x, k, \mathrm{Down}) = \operatorname{sgn}(q) \lfloor |q| \rfloor.$

$g(x, k, \mathrm{Up}) = \operatorname{sgn}(q) \lceil |q| \rceil.$

$g(x, k, \mathrm{Floor}) = \lfloor q \rfloor.$

$g(x, k, \mathrm{Ceiling}) = \lceil q \rceil.$

$$ g(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} $$

$g(x, k, \mathrm{Exact}) = q$, but panics if $q \notin \Z$.

Then

$f(x, k, r) = (g(x, k, r), \operatorname{cmp}(g(x, k, r), q))$.

§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

source§

impl ShrRound<i64> for i8

source§

fn shr_round(self, bits: i64, rm: RoundingMode) -> (i8, Ordering)

Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode. An Ordering is also returned, indicating whether the returned value is less than, equal to, or greater than the exact value. If bits is negative, then the returned Ordering is always Equal, even if the higher bits of the result are lost.

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^k}$, and let $g$ be the function that just returns the first element of the pair, without the Ordering:

$g(x, k, \mathrm{Down}) = \operatorname{sgn}(q) \lfloor |q| \rfloor.$

$g(x, k, \mathrm{Up}) = \operatorname{sgn}(q) \lceil |q| \rceil.$

$g(x, k, \mathrm{Floor}) = \lfloor q \rfloor.$

$g(x, k, \mathrm{Ceiling}) = \lceil q \rceil.$

$$ g(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} $$

$g(x, k, \mathrm{Exact}) = q$, but panics if $q \notin \Z$.

Then

$f(x, k, r) = (g(x, k, r), \operatorname{cmp}(g(x, k, r), q))$.

§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

source§

impl ShrRound<i64> for i16

source§

fn shr_round(self, bits: i64, rm: RoundingMode) -> (i16, Ordering)

Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode. An Ordering is also returned, indicating whether the returned value is less than, equal to, or greater than the exact value. If bits is negative, then the returned Ordering is always Equal, even if the higher bits of the result are lost.

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^k}$, and let $g$ be the function that just returns the first element of the pair, without the Ordering:

$g(x, k, \mathrm{Down}) = \operatorname{sgn}(q) \lfloor |q| \rfloor.$

$g(x, k, \mathrm{Up}) = \operatorname{sgn}(q) \lceil |q| \rceil.$

$g(x, k, \mathrm{Floor}) = \lfloor q \rfloor.$

$g(x, k, \mathrm{Ceiling}) = \lceil q \rceil.$

$$ g(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} $$

$g(x, k, \mathrm{Exact}) = q$, but panics if $q \notin \Z$.

Then

$f(x, k, r) = (g(x, k, r), \operatorname{cmp}(g(x, k, r), q))$.

§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

source§

impl ShrRound<i64> for i32

source§

fn shr_round(self, bits: i64, rm: RoundingMode) -> (i32, Ordering)

Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode. An Ordering is also returned, indicating whether the returned value is less than, equal to, or greater than the exact value. If bits is negative, then the returned Ordering is always Equal, even if the higher bits of the result are lost.

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^k}$, and let $g$ be the function that just returns the first element of the pair, without the Ordering:

$g(x, k, \mathrm{Down}) = \operatorname{sgn}(q) \lfloor |q| \rfloor.$

$g(x, k, \mathrm{Up}) = \operatorname{sgn}(q) \lceil |q| \rceil.$

$g(x, k, \mathrm{Floor}) = \lfloor q \rfloor.$

$g(x, k, \mathrm{Ceiling}) = \lceil q \rceil.$

$$ g(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} $$

$g(x, k, \mathrm{Exact}) = q$, but panics if $q \notin \Z$.

Then

$f(x, k, r) = (g(x, k, r), \operatorname{cmp}(g(x, k, r), q))$.

§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

source§

impl ShrRound<i64> for i64

source§

fn shr_round(self, bits: i64, rm: RoundingMode) -> (i64, Ordering)

Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode. An Ordering is also returned, indicating whether the returned value is less than, equal to, or greater than the exact value. If bits is negative, then the returned Ordering is always Equal, even if the higher bits of the result are lost.

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^k}$, and let $g$ be the function that just returns the first element of the pair, without the Ordering:

$g(x, k, \mathrm{Down}) = \operatorname{sgn}(q) \lfloor |q| \rfloor.$

$g(x, k, \mathrm{Up}) = \operatorname{sgn}(q) \lceil |q| \rceil.$

$g(x, k, \mathrm{Floor}) = \lfloor q \rfloor.$

$g(x, k, \mathrm{Ceiling}) = \lceil q \rceil.$

$$ g(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} $$

$g(x, k, \mathrm{Exact}) = q$, but panics if $q \notin \Z$.

Then

$f(x, k, r) = (g(x, k, r), \operatorname{cmp}(g(x, k, r), q))$.

§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

source§

impl ShrRound<i64> for i128

source§

fn shr_round(self, bits: i64, rm: RoundingMode) -> (i128, Ordering)

Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode. An Ordering is also returned, indicating whether the returned value is less than, equal to, or greater than the exact value. If bits is negative, then the returned Ordering is always Equal, even if the higher bits of the result are lost.

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^k}$, and let $g$ be the function that just returns the first element of the pair, without the Ordering:

$g(x, k, \mathrm{Down}) = \operatorname{sgn}(q) \lfloor |q| \rfloor.$

$g(x, k, \mathrm{Up}) = \operatorname{sgn}(q) \lceil |q| \rceil.$

$g(x, k, \mathrm{Floor}) = \lfloor q \rfloor.$

$g(x, k, \mathrm{Ceiling}) = \lceil q \rceil.$

$$ g(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} $$

$g(x, k, \mathrm{Exact}) = q$, but panics if $q \notin \Z$.

Then

$f(x, k, r) = (g(x, k, r), \operatorname{cmp}(g(x, k, r), q))$.

§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

source§

impl ShrRound<i64> for isize

source§

fn shr_round(self, bits: i64, rm: RoundingMode) -> (isize, Ordering)

Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode. An Ordering is also returned, indicating whether the returned value is less than, equal to, or greater than the exact value. If bits is negative, then the returned Ordering is always Equal, even if the higher bits of the result are lost.

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^k}$, and let $g$ be the function that just returns the first element of the pair, without the Ordering:

$g(x, k, \mathrm{Down}) = \operatorname{sgn}(q) \lfloor |q| \rfloor.$

$g(x, k, \mathrm{Up}) = \operatorname{sgn}(q) \lceil |q| \rceil.$

$g(x, k, \mathrm{Floor}) = \lfloor q \rfloor.$

$g(x, k, \mathrm{Ceiling}) = \lceil q \rceil.$

$$ g(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} $$

$g(x, k, \mathrm{Exact}) = q$, but panics if $q \notin \Z$.

Then

$f(x, k, r) = (g(x, k, r), \operatorname{cmp}(g(x, k, r), q))$.

§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

source§

impl ShrRound<i64> for u8

source§

fn shr_round(self, bits: i64, rm: RoundingMode) -> (u8, Ordering)

Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode. An Ordering is also returned, indicating whether the returned value is less than, equal to, or greater than the exact value. If bits is negative, then the returned Ordering is always Equal, even if the higher bits of the result are lost.

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^k}$, and let $g$ be the function that just returns the first element of the pair, without the Ordering:

$g(x, k, \mathrm{Down}) = \operatorname{sgn}(q) \lfloor |q| \rfloor.$

$g(x, k, \mathrm{Up}) = \operatorname{sgn}(q) \lceil |q| \rceil.$

$g(x, k, \mathrm{Floor}) = \lfloor q \rfloor.$

$g(x, k, \mathrm{Ceiling}) = \lceil q \rceil.$

$$ g(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} $$

$g(x, k, \mathrm{Exact}) = q$, but panics if $q \notin \Z$.

Then

$f(x, k, r) = (g(x, k, r), \operatorname{cmp}(g(x, k, r), q))$.

§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

source§

impl ShrRound<i64> for u16

source§

fn shr_round(self, bits: i64, rm: RoundingMode) -> (u16, Ordering)

Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode. An Ordering is also returned, indicating whether the returned value is less than, equal to, or greater than the exact value. If bits is negative, then the returned Ordering is always Equal, even if the higher bits of the result are lost.

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^k}$, and let $g$ be the function that just returns the first element of the pair, without the Ordering:

$g(x, k, \mathrm{Down}) = \operatorname{sgn}(q) \lfloor |q| \rfloor.$

$g(x, k, \mathrm{Up}) = \operatorname{sgn}(q) \lceil |q| \rceil.$

$g(x, k, \mathrm{Floor}) = \lfloor q \rfloor.$

$g(x, k, \mathrm{Ceiling}) = \lceil q \rceil.$

$$ g(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} $$

$g(x, k, \mathrm{Exact}) = q$, but panics if $q \notin \Z$.

Then

$f(x, k, r) = (g(x, k, r), \operatorname{cmp}(g(x, k, r), q))$.

§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

source§

impl ShrRound<i64> for u32

source§

fn shr_round(self, bits: i64, rm: RoundingMode) -> (u32, Ordering)

Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode. An Ordering is also returned, indicating whether the returned value is less than, equal to, or greater than the exact value. If bits is negative, then the returned Ordering is always Equal, even if the higher bits of the result are lost.

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^k}$, and let $g$ be the function that just returns the first element of the pair, without the Ordering:

$g(x, k, \mathrm{Down}) = \operatorname{sgn}(q) \lfloor |q| \rfloor.$

$g(x, k, \mathrm{Up}) = \operatorname{sgn}(q) \lceil |q| \rceil.$

$g(x, k, \mathrm{Floor}) = \lfloor q \rfloor.$

$g(x, k, \mathrm{Ceiling}) = \lceil q \rceil.$

$$ g(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} $$

$g(x, k, \mathrm{Exact}) = q$, but panics if $q \notin \Z$.

Then

$f(x, k, r) = (g(x, k, r), \operatorname{cmp}(g(x, k, r), q))$.

§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

source§

impl ShrRound<i64> for u64

source§

fn shr_round(self, bits: i64, rm: RoundingMode) -> (u64, Ordering)

Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode. An Ordering is also returned, indicating whether the returned value is less than, equal to, or greater than the exact value. If bits is negative, then the returned Ordering is always Equal, even if the higher bits of the result are lost.

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^k}$, and let $g$ be the function that just returns the first element of the pair, without the Ordering:

$g(x, k, \mathrm{Down}) = \operatorname{sgn}(q) \lfloor |q| \rfloor.$

$g(x, k, \mathrm{Up}) = \operatorname{sgn}(q) \lceil |q| \rceil.$

$g(x, k, \mathrm{Floor}) = \lfloor q \rfloor.$

$g(x, k, \mathrm{Ceiling}) = \lceil q \rceil.$

$$ g(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} $$

$g(x, k, \mathrm{Exact}) = q$, but panics if $q \notin \Z$.

Then

$f(x, k, r) = (g(x, k, r), \operatorname{cmp}(g(x, k, r), q))$.

§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

source§

impl ShrRound<i64> for u128

source§

fn shr_round(self, bits: i64, rm: RoundingMode) -> (u128, Ordering)

Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode. An Ordering is also returned, indicating whether the returned value is less than, equal to, or greater than the exact value. If bits is negative, then the returned Ordering is always Equal, even if the higher bits of the result are lost.

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^k}$, and let $g$ be the function that just returns the first element of the pair, without the Ordering:

$g(x, k, \mathrm{Down}) = \operatorname{sgn}(q) \lfloor |q| \rfloor.$

$g(x, k, \mathrm{Up}) = \operatorname{sgn}(q) \lceil |q| \rceil.$

$g(x, k, \mathrm{Floor}) = \lfloor q \rfloor.$

$g(x, k, \mathrm{Ceiling}) = \lceil q \rceil.$

$$ g(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} $$

$g(x, k, \mathrm{Exact}) = q$, but panics if $q \notin \Z$.

Then

$f(x, k, r) = (g(x, k, r), \operatorname{cmp}(g(x, k, r), q))$.

§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

source§

impl ShrRound<i64> for usize

source§

fn shr_round(self, bits: i64, rm: RoundingMode) -> (usize, Ordering)

Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode. An Ordering is also returned, indicating whether the returned value is less than, equal to, or greater than the exact value. If bits is negative, then the returned Ordering is always Equal, even if the higher bits of the result are lost.

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^k}$, and let $g$ be the function that just returns the first element of the pair, without the Ordering:

$g(x, k, \mathrm{Down}) = \operatorname{sgn}(q) \lfloor |q| \rfloor.$

$g(x, k, \mathrm{Up}) = \operatorname{sgn}(q) \lceil |q| \rceil.$

$g(x, k, \mathrm{Floor}) = \lfloor q \rfloor.$

$g(x, k, \mathrm{Ceiling}) = \lceil q \rceil.$

$$ g(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} $$

$g(x, k, \mathrm{Exact}) = q$, but panics if $q \notin \Z$.

Then

$f(x, k, r) = (g(x, k, r), \operatorname{cmp}(g(x, k, r), q))$.

§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

source§

impl ShrRound<i128> for i8

source§

fn shr_round(self, bits: i128, rm: RoundingMode) -> (i8, Ordering)

Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode. An Ordering is also returned, indicating whether the returned value is less than, equal to, or greater than the exact value. If bits is negative, then the returned Ordering is always Equal, even if the higher bits of the result are lost.

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^k}$, and let $g$ be the function that just returns the first element of the pair, without the Ordering:

$g(x, k, \mathrm{Down}) = \operatorname{sgn}(q) \lfloor |q| \rfloor.$

$g(x, k, \mathrm{Up}) = \operatorname{sgn}(q) \lceil |q| \rceil.$

$g(x, k, \mathrm{Floor}) = \lfloor q \rfloor.$

$g(x, k, \mathrm{Ceiling}) = \lceil q \rceil.$

$$ g(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} $$

$g(x, k, \mathrm{Exact}) = q$, but panics if $q \notin \Z$.

Then

$f(x, k, r) = (g(x, k, r), \operatorname{cmp}(g(x, k, r), q))$.

§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

source§

impl ShrRound<i128> for i16

source§

fn shr_round(self, bits: i128, rm: RoundingMode) -> (i16, Ordering)

Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode. An Ordering is also returned, indicating whether the returned value is less than, equal to, or greater than the exact value. If bits is negative, then the returned Ordering is always Equal, even if the higher bits of the result are lost.

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^k}$, and let $g$ be the function that just returns the first element of the pair, without the Ordering:

$g(x, k, \mathrm{Down}) = \operatorname{sgn}(q) \lfloor |q| \rfloor.$

$g(x, k, \mathrm{Up}) = \operatorname{sgn}(q) \lceil |q| \rceil.$

$g(x, k, \mathrm{Floor}) = \lfloor q \rfloor.$

$g(x, k, \mathrm{Ceiling}) = \lceil q \rceil.$

$$ g(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} $$

$g(x, k, \mathrm{Exact}) = q$, but panics if $q \notin \Z$.

Then

$f(x, k, r) = (g(x, k, r), \operatorname{cmp}(g(x, k, r), q))$.

§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

source§

impl ShrRound<i128> for i32

source§

fn shr_round(self, bits: i128, rm: RoundingMode) -> (i32, Ordering)

Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode. An Ordering is also returned, indicating whether the returned value is less than, equal to, or greater than the exact value. If bits is negative, then the returned Ordering is always Equal, even if the higher bits of the result are lost.

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^k}$, and let $g$ be the function that just returns the first element of the pair, without the Ordering:

$g(x, k, \mathrm{Down}) = \operatorname{sgn}(q) \lfloor |q| \rfloor.$

$g(x, k, \mathrm{Up}) = \operatorname{sgn}(q) \lceil |q| \rceil.$

$g(x, k, \mathrm{Floor}) = \lfloor q \rfloor.$

$g(x, k, \mathrm{Ceiling}) = \lceil q \rceil.$

$$ g(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} $$

$g(x, k, \mathrm{Exact}) = q$, but panics if $q \notin \Z$.

Then

$f(x, k, r) = (g(x, k, r), \operatorname{cmp}(g(x, k, r), q))$.

§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

source§

impl ShrRound<i128> for i64

source§

fn shr_round(self, bits: i128, rm: RoundingMode) -> (i64, Ordering)

Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode. An Ordering is also returned, indicating whether the returned value is less than, equal to, or greater than the exact value. If bits is negative, then the returned Ordering is always Equal, even if the higher bits of the result are lost.

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^k}$, and let $g$ be the function that just returns the first element of the pair, without the Ordering:

$g(x, k, \mathrm{Down}) = \operatorname{sgn}(q) \lfloor |q| \rfloor.$

$g(x, k, \mathrm{Up}) = \operatorname{sgn}(q) \lceil |q| \rceil.$

$g(x, k, \mathrm{Floor}) = \lfloor q \rfloor.$

$g(x, k, \mathrm{Ceiling}) = \lceil q \rceil.$

$$ g(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} $$

$g(x, k, \mathrm{Exact}) = q$, but panics if $q \notin \Z$.

Then

$f(x, k, r) = (g(x, k, r), \operatorname{cmp}(g(x, k, r), q))$.

§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

source§

impl ShrRound<i128> for i128

source§

fn shr_round(self, bits: i128, rm: RoundingMode) -> (i128, Ordering)

Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode. An Ordering is also returned, indicating whether the returned value is less than, equal to, or greater than the exact value. If bits is negative, then the returned Ordering is always Equal, even if the higher bits of the result are lost.

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^k}$, and let $g$ be the function that just returns the first element of the pair, without the Ordering:

$g(x, k, \mathrm{Down}) = \operatorname{sgn}(q) \lfloor |q| \rfloor.$

$g(x, k, \mathrm{Up}) = \operatorname{sgn}(q) \lceil |q| \rceil.$

$g(x, k, \mathrm{Floor}) = \lfloor q \rfloor.$

$g(x, k, \mathrm{Ceiling}) = \lceil q \rceil.$

$$ g(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} $$

$g(x, k, \mathrm{Exact}) = q$, but panics if $q \notin \Z$.

Then

$f(x, k, r) = (g(x, k, r), \operatorname{cmp}(g(x, k, r), q))$.

§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

source§

impl ShrRound<i128> for isize

source§

fn shr_round(self, bits: i128, rm: RoundingMode) -> (isize, Ordering)

Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode. An Ordering is also returned, indicating whether the returned value is less than, equal to, or greater than the exact value. If bits is negative, then the returned Ordering is always Equal, even if the higher bits of the result are lost.

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^k}$, and let $g$ be the function that just returns the first element of the pair, without the Ordering:

$g(x, k, \mathrm{Down}) = \operatorname{sgn}(q) \lfloor |q| \rfloor.$

$g(x, k, \mathrm{Up}) = \operatorname{sgn}(q) \lceil |q| \rceil.$

$g(x, k, \mathrm{Floor}) = \lfloor q \rfloor.$

$g(x, k, \mathrm{Ceiling}) = \lceil q \rceil.$

$$ g(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} $$

$g(x, k, \mathrm{Exact}) = q$, but panics if $q \notin \Z$.

Then

$f(x, k, r) = (g(x, k, r), \operatorname{cmp}(g(x, k, r), q))$.

§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

source§

impl ShrRound<i128> for u8

source§

fn shr_round(self, bits: i128, rm: RoundingMode) -> (u8, Ordering)

Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode. An Ordering is also returned, indicating whether the returned value is less than, equal to, or greater than the exact value. If bits is negative, then the returned Ordering is always Equal, even if the higher bits of the result are lost.

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^k}$, and let $g$ be the function that just returns the first element of the pair, without the Ordering:

$g(x, k, \mathrm{Down}) = \operatorname{sgn}(q) \lfloor |q| \rfloor.$

$g(x, k, \mathrm{Up}) = \operatorname{sgn}(q) \lceil |q| \rceil.$

$g(x, k, \mathrm{Floor}) = \lfloor q \rfloor.$

$g(x, k, \mathrm{Ceiling}) = \lceil q \rceil.$

$$ g(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} $$

$g(x, k, \mathrm{Exact}) = q$, but panics if $q \notin \Z$.

Then

$f(x, k, r) = (g(x, k, r), \operatorname{cmp}(g(x, k, r), q))$.

§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

source§

impl ShrRound<i128> for u16

source§

fn shr_round(self, bits: i128, rm: RoundingMode) -> (u16, Ordering)

Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode. An Ordering is also returned, indicating whether the returned value is less than, equal to, or greater than the exact value. If bits is negative, then the returned Ordering is always Equal, even if the higher bits of the result are lost.

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^k}$, and let $g$ be the function that just returns the first element of the pair, without the Ordering:

$g(x, k, \mathrm{Down}) = \operatorname{sgn}(q) \lfloor |q| \rfloor.$

$g(x, k, \mathrm{Up}) = \operatorname{sgn}(q) \lceil |q| \rceil.$

$g(x, k, \mathrm{Floor}) = \lfloor q \rfloor.$

$g(x, k, \mathrm{Ceiling}) = \lceil q \rceil.$

$$ g(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} $$

$g(x, k, \mathrm{Exact}) = q$, but panics if $q \notin \Z$.

Then

$f(x, k, r) = (g(x, k, r), \operatorname{cmp}(g(x, k, r), q))$.

§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

source§

impl ShrRound<i128> for u32

source§

fn shr_round(self, bits: i128, rm: RoundingMode) -> (u32, Ordering)

Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode. An Ordering is also returned, indicating whether the returned value is less than, equal to, or greater than the exact value. If bits is negative, then the returned Ordering is always Equal, even if the higher bits of the result are lost.

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^k}$, and let $g$ be the function that just returns the first element of the pair, without the Ordering:

$g(x, k, \mathrm{Down}) = \operatorname{sgn}(q) \lfloor |q| \rfloor.$

$g(x, k, \mathrm{Up}) = \operatorname{sgn}(q) \lceil |q| \rceil.$

$g(x, k, \mathrm{Floor}) = \lfloor q \rfloor.$

$g(x, k, \mathrm{Ceiling}) = \lceil q \rceil.$

$$ g(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} $$

$g(x, k, \mathrm{Exact}) = q$, but panics if $q \notin \Z$.

Then

$f(x, k, r) = (g(x, k, r), \operatorname{cmp}(g(x, k, r), q))$.

§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

source§

impl ShrRound<i128> for u64

source§

fn shr_round(self, bits: i128, rm: RoundingMode) -> (u64, Ordering)

Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode. An Ordering is also returned, indicating whether the returned value is less than, equal to, or greater than the exact value. If bits is negative, then the returned Ordering is always Equal, even if the higher bits of the result are lost.

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^k}$, and let $g$ be the function that just returns the first element of the pair, without the Ordering:

$g(x, k, \mathrm{Down}) = \operatorname{sgn}(q) \lfloor |q| \rfloor.$

$g(x, k, \mathrm{Up}) = \operatorname{sgn}(q) \lceil |q| \rceil.$

$g(x, k, \mathrm{Floor}) = \lfloor q \rfloor.$

$g(x, k, \mathrm{Ceiling}) = \lceil q \rceil.$

$$ g(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} $$

$g(x, k, \mathrm{Exact}) = q$, but panics if $q \notin \Z$.

Then

$f(x, k, r) = (g(x, k, r), \operatorname{cmp}(g(x, k, r), q))$.

§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

source§

impl ShrRound<i128> for u128

source§

fn shr_round(self, bits: i128, rm: RoundingMode) -> (u128, Ordering)

Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode. An Ordering is also returned, indicating whether the returned value is less than, equal to, or greater than the exact value. If bits is negative, then the returned Ordering is always Equal, even if the higher bits of the result are lost.

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^k}$, and let $g$ be the function that just returns the first element of the pair, without the Ordering:

$g(x, k, \mathrm{Down}) = \operatorname{sgn}(q) \lfloor |q| \rfloor.$

$g(x, k, \mathrm{Up}) = \operatorname{sgn}(q) \lceil |q| \rceil.$

$g(x, k, \mathrm{Floor}) = \lfloor q \rfloor.$

$g(x, k, \mathrm{Ceiling}) = \lceil q \rceil.$

$$ g(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} $$

$g(x, k, \mathrm{Exact}) = q$, but panics if $q \notin \Z$.

Then

$f(x, k, r) = (g(x, k, r), \operatorname{cmp}(g(x, k, r), q))$.

§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

source§

impl ShrRound<i128> for usize

source§

fn shr_round(self, bits: i128, rm: RoundingMode) -> (usize, Ordering)

Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode. An Ordering is also returned, indicating whether the returned value is less than, equal to, or greater than the exact value. If bits is negative, then the returned Ordering is always Equal, even if the higher bits of the result are lost.

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^k}$, and let $g$ be the function that just returns the first element of the pair, without the Ordering:

$g(x, k, \mathrm{Down}) = \operatorname{sgn}(q) \lfloor |q| \rfloor.$

$g(x, k, \mathrm{Up}) = \operatorname{sgn}(q) \lceil |q| \rceil.$

$g(x, k, \mathrm{Floor}) = \lfloor q \rfloor.$

$g(x, k, \mathrm{Ceiling}) = \lceil q \rceil.$

$$ g(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} $$

$g(x, k, \mathrm{Exact}) = q$, but panics if $q \notin \Z$.

Then

$f(x, k, r) = (g(x, k, r), \operatorname{cmp}(g(x, k, r), q))$.

§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

source§

impl ShrRound<isize> for i8

source§

fn shr_round(self, bits: isize, rm: RoundingMode) -> (i8, Ordering)

Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode. An Ordering is also returned, indicating whether the returned value is less than, equal to, or greater than the exact value. If bits is negative, then the returned Ordering is always Equal, even if the higher bits of the result are lost.

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^k}$, and let $g$ be the function that just returns the first element of the pair, without the Ordering:

$g(x, k, \mathrm{Down}) = \operatorname{sgn}(q) \lfloor |q| \rfloor.$

$g(x, k, \mathrm{Up}) = \operatorname{sgn}(q) \lceil |q| \rceil.$

$g(x, k, \mathrm{Floor}) = \lfloor q \rfloor.$

$g(x, k, \mathrm{Ceiling}) = \lceil q \rceil.$

$$ g(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} $$

$g(x, k, \mathrm{Exact}) = q$, but panics if $q \notin \Z$.

Then

$f(x, k, r) = (g(x, k, r), \operatorname{cmp}(g(x, k, r), q))$.

§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

source§

impl ShrRound<isize> for i16

source§

fn shr_round(self, bits: isize, rm: RoundingMode) -> (i16, Ordering)

Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode. An Ordering is also returned, indicating whether the returned value is less than, equal to, or greater than the exact value. If bits is negative, then the returned Ordering is always Equal, even if the higher bits of the result are lost.

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^k}$, and let $g$ be the function that just returns the first element of the pair, without the Ordering:

$g(x, k, \mathrm{Down}) = \operatorname{sgn}(q) \lfloor |q| \rfloor.$

$g(x, k, \mathrm{Up}) = \operatorname{sgn}(q) \lceil |q| \rceil.$

$g(x, k, \mathrm{Floor}) = \lfloor q \rfloor.$

$g(x, k, \mathrm{Ceiling}) = \lceil q \rceil.$

$$ g(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} $$

$g(x, k, \mathrm{Exact}) = q$, but panics if $q \notin \Z$.

Then

$f(x, k, r) = (g(x, k, r), \operatorname{cmp}(g(x, k, r), q))$.

§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

source§

impl ShrRound<isize> for i32

source§

fn shr_round(self, bits: isize, rm: RoundingMode) -> (i32, Ordering)

Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode. An Ordering is also returned, indicating whether the returned value is less than, equal to, or greater than the exact value. If bits is negative, then the returned Ordering is always Equal, even if the higher bits of the result are lost.

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^k}$, and let $g$ be the function that just returns the first element of the pair, without the Ordering:

$g(x, k, \mathrm{Down}) = \operatorname{sgn}(q) \lfloor |q| \rfloor.$

$g(x, k, \mathrm{Up}) = \operatorname{sgn}(q) \lceil |q| \rceil.$

$g(x, k, \mathrm{Floor}) = \lfloor q \rfloor.$

$g(x, k, \mathrm{Ceiling}) = \lceil q \rceil.$

$$ g(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} $$

$g(x, k, \mathrm{Exact}) = q$, but panics if $q \notin \Z$.

Then

$f(x, k, r) = (g(x, k, r), \operatorname{cmp}(g(x, k, r), q))$.

§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

source§

impl ShrRound<isize> for i64

source§

fn shr_round(self, bits: isize, rm: RoundingMode) -> (i64, Ordering)

Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode. An Ordering is also returned, indicating whether the returned value is less than, equal to, or greater than the exact value. If bits is negative, then the returned Ordering is always Equal, even if the higher bits of the result are lost.

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^k}$, and let $g$ be the function that just returns the first element of the pair, without the Ordering:

$g(x, k, \mathrm{Down}) = \operatorname{sgn}(q) \lfloor |q| \rfloor.$

$g(x, k, \mathrm{Up}) = \operatorname{sgn}(q) \lceil |q| \rceil.$

$g(x, k, \mathrm{Floor}) = \lfloor q \rfloor.$

$g(x, k, \mathrm{Ceiling}) = \lceil q \rceil.$

$$ g(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} $$

$g(x, k, \mathrm{Exact}) = q$, but panics if $q \notin \Z$.

Then

$f(x, k, r) = (g(x, k, r), \operatorname{cmp}(g(x, k, r), q))$.

§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

source§

impl ShrRound<isize> for i128

source§

fn shr_round(self, bits: isize, rm: RoundingMode) -> (i128, Ordering)

Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode. An Ordering is also returned, indicating whether the returned value is less than, equal to, or greater than the exact value. If bits is negative, then the returned Ordering is always Equal, even if the higher bits of the result are lost.

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^k}$, and let $g$ be the function that just returns the first element of the pair, without the Ordering:

$g(x, k, \mathrm{Down}) = \operatorname{sgn}(q) \lfloor |q| \rfloor.$

$g(x, k, \mathrm{Up}) = \operatorname{sgn}(q) \lceil |q| \rceil.$

$g(x, k, \mathrm{Floor}) = \lfloor q \rfloor.$

$g(x, k, \mathrm{Ceiling}) = \lceil q \rceil.$

$$ g(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} $$

$g(x, k, \mathrm{Exact}) = q$, but panics if $q \notin \Z$.

Then

$f(x, k, r) = (g(x, k, r), \operatorname{cmp}(g(x, k, r), q))$.

§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

source§

impl ShrRound<isize> for isize

source§

fn shr_round(self, bits: isize, rm: RoundingMode) -> (isize, Ordering)

Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode. An Ordering is also returned, indicating whether the returned value is less than, equal to, or greater than the exact value. If bits is negative, then the returned Ordering is always Equal, even if the higher bits of the result are lost.

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^k}$, and let $g$ be the function that just returns the first element of the pair, without the Ordering:

$g(x, k, \mathrm{Down}) = \operatorname{sgn}(q) \lfloor |q| \rfloor.$

$g(x, k, \mathrm{Up}) = \operatorname{sgn}(q) \lceil |q| \rceil.$

$g(x, k, \mathrm{Floor}) = \lfloor q \rfloor.$

$g(x, k, \mathrm{Ceiling}) = \lceil q \rceil.$

$$ g(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} $$

$g(x, k, \mathrm{Exact}) = q$, but panics if $q \notin \Z$.

Then

$f(x, k, r) = (g(x, k, r), \operatorname{cmp}(g(x, k, r), q))$.

§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

source§

impl ShrRound<isize> for u8

source§

fn shr_round(self, bits: isize, rm: RoundingMode) -> (u8, Ordering)

Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode. An Ordering is also returned, indicating whether the returned value is less than, equal to, or greater than the exact value. If bits is negative, then the returned Ordering is always Equal, even if the higher bits of the result are lost.

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^k}$, and let $g$ be the function that just returns the first element of the pair, without the Ordering:

$g(x, k, \mathrm{Down}) = \operatorname{sgn}(q) \lfloor |q| \rfloor.$

$g(x, k, \mathrm{Up}) = \operatorname{sgn}(q) \lceil |q| \rceil.$

$g(x, k, \mathrm{Floor}) = \lfloor q \rfloor.$

$g(x, k, \mathrm{Ceiling}) = \lceil q \rceil.$

$$ g(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} $$

$g(x, k, \mathrm{Exact}) = q$, but panics if $q \notin \Z$.

Then

$f(x, k, r) = (g(x, k, r), \operatorname{cmp}(g(x, k, r), q))$.

§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

source§

impl ShrRound<isize> for u16

source§

fn shr_round(self, bits: isize, rm: RoundingMode) -> (u16, Ordering)

Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode. An Ordering is also returned, indicating whether the returned value is less than, equal to, or greater than the exact value. If bits is negative, then the returned Ordering is always Equal, even if the higher bits of the result are lost.

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^k}$, and let $g$ be the function that just returns the first element of the pair, without the Ordering:

$g(x, k, \mathrm{Down}) = \operatorname{sgn}(q) \lfloor |q| \rfloor.$

$g(x, k, \mathrm{Up}) = \operatorname{sgn}(q) \lceil |q| \rceil.$

$g(x, k, \mathrm{Floor}) = \lfloor q \rfloor.$

$g(x, k, \mathrm{Ceiling}) = \lceil q \rceil.$

$$ g(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} $$

$g(x, k, \mathrm{Exact}) = q$, but panics if $q \notin \Z$.

Then

$f(x, k, r) = (g(x, k, r), \operatorname{cmp}(g(x, k, r), q))$.

§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

source§

impl ShrRound<isize> for u32

source§

fn shr_round(self, bits: isize, rm: RoundingMode) -> (u32, Ordering)

Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode. An Ordering is also returned, indicating whether the returned value is less than, equal to, or greater than the exact value. If bits is negative, then the returned Ordering is always Equal, even if the higher bits of the result are lost.

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^k}$, and let $g$ be the function that just returns the first element of the pair, without the Ordering:

$g(x, k, \mathrm{Down}) = \operatorname{sgn}(q) \lfloor |q| \rfloor.$

$g(x, k, \mathrm{Up}) = \operatorname{sgn}(q) \lceil |q| \rceil.$

$g(x, k, \mathrm{Floor}) = \lfloor q \rfloor.$

$g(x, k, \mathrm{Ceiling}) = \lceil q \rceil.$

$$ g(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} $$

$g(x, k, \mathrm{Exact}) = q$, but panics if $q \notin \Z$.

Then

$f(x, k, r) = (g(x, k, r), \operatorname{cmp}(g(x, k, r), q))$.

§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

source§

impl ShrRound<isize> for u64

source§

fn shr_round(self, bits: isize, rm: RoundingMode) -> (u64, Ordering)

Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode. An Ordering is also returned, indicating whether the returned value is less than, equal to, or greater than the exact value. If bits is negative, then the returned Ordering is always Equal, even if the higher bits of the result are lost.

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^k}$, and let $g$ be the function that just returns the first element of the pair, without the Ordering:

$g(x, k, \mathrm{Down}) = \operatorname{sgn}(q) \lfloor |q| \rfloor.$

$g(x, k, \mathrm{Up}) = \operatorname{sgn}(q) \lceil |q| \rceil.$

$g(x, k, \mathrm{Floor}) = \lfloor q \rfloor.$

$g(x, k, \mathrm{Ceiling}) = \lceil q \rceil.$

$$ g(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} $$

$g(x, k, \mathrm{Exact}) = q$, but panics if $q \notin \Z$.

Then

$f(x, k, r) = (g(x, k, r), \operatorname{cmp}(g(x, k, r), q))$.

§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

source§

impl ShrRound<isize> for u128

source§

fn shr_round(self, bits: isize, rm: RoundingMode) -> (u128, Ordering)

Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode. An Ordering is also returned, indicating whether the returned value is less than, equal to, or greater than the exact value. If bits is negative, then the returned Ordering is always Equal, even if the higher bits of the result are lost.

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^k}$, and let $g$ be the function that just returns the first element of the pair, without the Ordering:

$g(x, k, \mathrm{Down}) = \operatorname{sgn}(q) \lfloor |q| \rfloor.$

$g(x, k, \mathrm{Up}) = \operatorname{sgn}(q) \lceil |q| \rceil.$

$g(x, k, \mathrm{Floor}) = \lfloor q \rfloor.$

$g(x, k, \mathrm{Ceiling}) = \lceil q \rceil.$

$$ g(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} $$

$g(x, k, \mathrm{Exact}) = q$, but panics if $q \notin \Z$.

Then

$f(x, k, r) = (g(x, k, r), \operatorname{cmp}(g(x, k, r), q))$.

§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

source§

impl ShrRound<isize> for usize

source§

fn shr_round(self, bits: isize, rm: RoundingMode) -> (usize, Ordering)

Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode. An Ordering is also returned, indicating whether the returned value is less than, equal to, or greater than the exact value. If bits is negative, then the returned Ordering is always Equal, even if the higher bits of the result are lost.

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^k}$, and let $g$ be the function that just returns the first element of the pair, without the Ordering:

$g(x, k, \mathrm{Down}) = \operatorname{sgn}(q) \lfloor |q| \rfloor.$

$g(x, k, \mathrm{Up}) = \operatorname{sgn}(q) \lceil |q| \rceil.$

$g(x, k, \mathrm{Floor}) = \lfloor q \rfloor.$

$g(x, k, \mathrm{Ceiling}) = \lceil q \rceil.$

$$ g(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} $$

$g(x, k, \mathrm{Exact}) = q$, but panics if $q \notin \Z$.

Then

$f(x, k, r) = (g(x, k, r), \operatorname{cmp}(g(x, k, r), q))$.

§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

source§

impl ShrRound<u8> for i8

source§

fn shr_round(self, bits: u8, rm: RoundingMode) -> (i8, Ordering)

Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode. An Ordering is also returned, indicating whether the returned value is less than, equal to, or greater than the exact value.

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}$, and let $g$ be the function that just returns the first element of the pair, without the Ordering:

$g(x, k, \mathrm{Down}) = g(x, y, \mathrm{Floor}) = \lfloor q \rfloor.$

$g(x, k, \mathrm{Up}) = g(x, y, \mathrm{Ceiling}) = \lceil q \rceil.$

$$ g(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} $$

$g(x, k, \mathrm{Exact}) = q$, but panics if $q \notin \N$.

Then

$f(x, k, r) = (g(x, k, r), \operatorname{cmp}(g(x, k, r), q))$.

§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

source§

impl ShrRound<u8> for i16

source§

fn shr_round(self, bits: u8, rm: RoundingMode) -> (i16, Ordering)

Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode. An Ordering is also returned, indicating whether the returned value is less than, equal to, or greater than the exact value.

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}$, and let $g$ be the function that just returns the first element of the pair, without the Ordering:

$g(x, k, \mathrm{Down}) = g(x, y, \mathrm{Floor}) = \lfloor q \rfloor.$

$g(x, k, \mathrm{Up}) = g(x, y, \mathrm{Ceiling}) = \lceil q \rceil.$

$$ g(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} $$

$g(x, k, \mathrm{Exact}) = q$, but panics if $q \notin \N$.

Then

$f(x, k, r) = (g(x, k, r), \operatorname{cmp}(g(x, k, r), q))$.

§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

source§

impl ShrRound<u8> for i32

source§

fn shr_round(self, bits: u8, rm: RoundingMode) -> (i32, Ordering)

Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode. An Ordering is also returned, indicating whether the returned value is less than, equal to, or greater than the exact value.

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}$, and let $g$ be the function that just returns the first element of the pair, without the Ordering:

$g(x, k, \mathrm{Down}) = g(x, y, \mathrm{Floor}) = \lfloor q \rfloor.$

$g(x, k, \mathrm{Up}) = g(x, y, \mathrm{Ceiling}) = \lceil q \rceil.$

$$ g(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} $$

$g(x, k, \mathrm{Exact}) = q$, but panics if $q \notin \N$.

Then

$f(x, k, r) = (g(x, k, r), \operatorname{cmp}(g(x, k, r), q))$.

§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

source§

impl ShrRound<u8> for i64

source§

fn shr_round(self, bits: u8, rm: RoundingMode) -> (i64, Ordering)

Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode. An Ordering is also returned, indicating whether the returned value is less than, equal to, or greater than the exact value.

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}$, and let $g$ be the function that just returns the first element of the pair, without the Ordering:

$g(x, k, \mathrm{Down}) = g(x, y, \mathrm{Floor}) = \lfloor q \rfloor.$

$g(x, k, \mathrm{Up}) = g(x, y, \mathrm{Ceiling}) = \lceil q \rceil.$

$$ g(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} $$

$g(x, k, \mathrm{Exact}) = q$, but panics if $q \notin \N$.

Then

$f(x, k, r) = (g(x, k, r), \operatorname{cmp}(g(x, k, r), q))$.

§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

source§

impl ShrRound<u8> for i128

source§

fn shr_round(self, bits: u8, rm: RoundingMode) -> (i128, Ordering)

Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode. An Ordering is also returned, indicating whether the returned value is less than, equal to, or greater than the exact value.

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}$, and let $g$ be the function that just returns the first element of the pair, without the Ordering:

$g(x, k, \mathrm{Down}) = g(x, y, \mathrm{Floor}) = \lfloor q \rfloor.$

$g(x, k, \mathrm{Up}) = g(x, y, \mathrm{Ceiling}) = \lceil q \rceil.$

$$ g(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} $$

$g(x, k, \mathrm{Exact}) = q$, but panics if $q \notin \N$.

Then

$f(x, k, r) = (g(x, k, r), \operatorname{cmp}(g(x, k, r), q))$.

§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

source§

impl ShrRound<u8> for isize

source§

fn shr_round(self, bits: u8, rm: RoundingMode) -> (isize, Ordering)

Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode. An Ordering is also returned, indicating whether the returned value is less than, equal to, or greater than the exact value.

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}$, and let $g$ be the function that just returns the first element of the pair, without the Ordering:

$g(x, k, \mathrm{Down}) = g(x, y, \mathrm{Floor}) = \lfloor q \rfloor.$

$g(x, k, \mathrm{Up}) = g(x, y, \mathrm{Ceiling}) = \lceil q \rceil.$

$$ g(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} $$

$g(x, k, \mathrm{Exact}) = q$, but panics if $q \notin \N$.

Then

$f(x, k, r) = (g(x, k, r), \operatorname{cmp}(g(x, k, r), q))$.

§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

source§

impl ShrRound<u8> for u8

source§

fn shr_round(self, bits: u8, rm: RoundingMode) -> (u8, Ordering)

Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode. An Ordering is also returned, indicating whether the returned value is less than, equal to, or greater than the exact value.

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}$, and let $g$ be the function that just returns the first element of the pair, without the Ordering:

$g(x, k, \mathrm{Down}) = g(x, y, \mathrm{Floor}) = \lfloor q \rfloor.$

$g(x, k, \mathrm{Up}) = g(x, y, \mathrm{Ceiling}) = \lceil q \rceil.$

$$ g(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} $$

$g(x, k, \mathrm{Exact}) = q$, but panics if $q \notin \N$.

Then

$f(x, k, r) = (g(x, k, r), \operatorname{cmp}(g(x, k, r), q))$.

§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

source§

impl ShrRound<u8> for u16

source§

fn shr_round(self, bits: u8, rm: RoundingMode) -> (u16, Ordering)

Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode. An Ordering is also returned, indicating whether the returned value is less than, equal to, or greater than the exact value.

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}$, and let $g$ be the function that just returns the first element of the pair, without the Ordering:

$g(x, k, \mathrm{Down}) = g(x, y, \mathrm{Floor}) = \lfloor q \rfloor.$

$g(x, k, \mathrm{Up}) = g(x, y, \mathrm{Ceiling}) = \lceil q \rceil.$

$$ g(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} $$

$g(x, k, \mathrm{Exact}) = q$, but panics if $q \notin \N$.

Then

$f(x, k, r) = (g(x, k, r), \operatorname{cmp}(g(x, k, r), q))$.

§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

source§

impl ShrRound<u8> for u32

source§

fn shr_round(self, bits: u8, rm: RoundingMode) -> (u32, Ordering)

Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode. An Ordering is also returned, indicating whether the returned value is less than, equal to, or greater than the exact value.

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}$, and let $g$ be the function that just returns the first element of the pair, without the Ordering:

$g(x, k, \mathrm{Down}) = g(x, y, \mathrm{Floor}) = \lfloor q \rfloor.$

$g(x, k, \mathrm{Up}) = g(x, y, \mathrm{Ceiling}) = \lceil q \rceil.$

$$ g(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} $$

$g(x, k, \mathrm{Exact}) = q$, but panics if $q \notin \N$.

Then

$f(x, k, r) = (g(x, k, r), \operatorname{cmp}(g(x, k, r), q))$.

§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

source§

impl ShrRound<u8> for u64

source§

fn shr_round(self, bits: u8, rm: RoundingMode) -> (u64, Ordering)

Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode. An Ordering is also returned, indicating whether the returned value is less than, equal to, or greater than the exact value.

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}$, and let $g$ be the function that just returns the first element of the pair, without the Ordering:

$g(x, k, \mathrm{Down}) = g(x, y, \mathrm{Floor}) = \lfloor q \rfloor.$

$g(x, k, \mathrm{Up}) = g(x, y, \mathrm{Ceiling}) = \lceil q \rceil.$

$$ g(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} $$

$g(x, k, \mathrm{Exact}) = q$, but panics if $q \notin \N$.

Then

$f(x, k, r) = (g(x, k, r), \operatorname{cmp}(g(x, k, r), q))$.

§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

source§

impl ShrRound<u8> for u128

source§

fn shr_round(self, bits: u8, rm: RoundingMode) -> (u128, Ordering)

Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode. An Ordering is also returned, indicating whether the returned value is less than, equal to, or greater than the exact value.

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}$, and let $g$ be the function that just returns the first element of the pair, without the Ordering:

$g(x, k, \mathrm{Down}) = g(x, y, \mathrm{Floor}) = \lfloor q \rfloor.$

$g(x, k, \mathrm{Up}) = g(x, y, \mathrm{Ceiling}) = \lceil q \rceil.$

$$ g(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} $$

$g(x, k, \mathrm{Exact}) = q$, but panics if $q \notin \N$.

Then

$f(x, k, r) = (g(x, k, r), \operatorname{cmp}(g(x, k, r), q))$.

§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

source§

impl ShrRound<u8> for usize

source§

fn shr_round(self, bits: u8, rm: RoundingMode) -> (usize, Ordering)

Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode. An Ordering is also returned, indicating whether the returned value is less than, equal to, or greater than the exact value.

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}$, and let $g$ be the function that just returns the first element of the pair, without the Ordering:

$g(x, k, \mathrm{Down}) = g(x, y, \mathrm{Floor}) = \lfloor q \rfloor.$

$g(x, k, \mathrm{Up}) = g(x, y, \mathrm{Ceiling}) = \lceil q \rceil.$

$$ g(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} $$

$g(x, k, \mathrm{Exact}) = q$, but panics if $q \notin \N$.

Then

$f(x, k, r) = (g(x, k, r), \operatorname{cmp}(g(x, k, r), q))$.

§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

source§

impl ShrRound<u16> for i8

source§

fn shr_round(self, bits: u16, rm: RoundingMode) -> (i8, Ordering)

Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode. An Ordering is also returned, indicating whether the returned value is less than, equal to, or greater than the exact value.

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}$, and let $g$ be the function that just returns the first element of the pair, without the Ordering:

$g(x, k, \mathrm{Down}) = g(x, y, \mathrm{Floor}) = \lfloor q \rfloor.$

$g(x, k, \mathrm{Up}) = g(x, y, \mathrm{Ceiling}) = \lceil q \rceil.$

$$ g(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} $$

$g(x, k, \mathrm{Exact}) = q$, but panics if $q \notin \N$.

Then

$f(x, k, r) = (g(x, k, r), \operatorname{cmp}(g(x, k, r), q))$.

§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

source§

impl ShrRound<u16> for i16

source§

fn shr_round(self, bits: u16, rm: RoundingMode) -> (i16, Ordering)

Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode. An Ordering is also returned, indicating whether the returned value is less than, equal to, or greater than the exact value.

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}$, and let $g$ be the function that just returns the first element of the pair, without the Ordering:

$g(x, k, \mathrm{Down}) = g(x, y, \mathrm{Floor}) = \lfloor q \rfloor.$

$g(x, k, \mathrm{Up}) = g(x, y, \mathrm{Ceiling}) = \lceil q \rceil.$

$$ g(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} $$

$g(x, k, \mathrm{Exact}) = q$, but panics if $q \notin \N$.

Then

$f(x, k, r) = (g(x, k, r), \operatorname{cmp}(g(x, k, r), q))$.

§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

source§

impl ShrRound<u16> for i32

source§

fn shr_round(self, bits: u16, rm: RoundingMode) -> (i32, Ordering)

Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode. An Ordering is also returned, indicating whether the returned value is less than, equal to, or greater than the exact value.

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}$, and let $g$ be the function that just returns the first element of the pair, without the Ordering:

$g(x, k, \mathrm{Down}) = g(x, y, \mathrm{Floor}) = \lfloor q \rfloor.$

$g(x, k, \mathrm{Up}) = g(x, y, \mathrm{Ceiling}) = \lceil q \rceil.$

$$ g(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} $$

$g(x, k, \mathrm{Exact}) = q$, but panics if $q \notin \N$.

Then

$f(x, k, r) = (g(x, k, r), \operatorname{cmp}(g(x, k, r), q))$.

§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

source§

impl ShrRound<u16> for i64

source§

fn shr_round(self, bits: u16, rm: RoundingMode) -> (i64, Ordering)

Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode. An Ordering is also returned, indicating whether the returned value is less than, equal to, or greater than the exact value.

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}$, and let $g$ be the function that just returns the first element of the pair, without the Ordering:

$g(x, k, \mathrm{Down}) = g(x, y, \mathrm{Floor}) = \lfloor q \rfloor.$

$g(x, k, \mathrm{Up}) = g(x, y, \mathrm{Ceiling}) = \lceil q \rceil.$

$$ g(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} $$

$g(x, k, \mathrm{Exact}) = q$, but panics if $q \notin \N$.

Then

$f(x, k, r) = (g(x, k, r), \operatorname{cmp}(g(x, k, r), q))$.

§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

source§

impl ShrRound<u16> for i128

source§

fn shr_round(self, bits: u16, rm: RoundingMode) -> (i128, Ordering)

Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode. An Ordering is also returned, indicating whether the returned value is less than, equal to, or greater than the exact value.

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}$, and let $g$ be the function that just returns the first element of the pair, without the Ordering:

$g(x, k, \mathrm{Down}) = g(x, y, \mathrm{Floor}) = \lfloor q \rfloor.$

$g(x, k, \mathrm{Up}) = g(x, y, \mathrm{Ceiling}) = \lceil q \rceil.$

$$ g(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} $$

$g(x, k, \mathrm{Exact}) = q$, but panics if $q \notin \N$.

Then

$f(x, k, r) = (g(x, k, r), \operatorname{cmp}(g(x, k, r), q))$.

§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

source§

impl ShrRound<u16> for isize

source§

fn shr_round(self, bits: u16, rm: RoundingMode) -> (isize, Ordering)

Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode. An Ordering is also returned, indicating whether the returned value is less than, equal to, or greater than the exact value.

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}$, and let $g$ be the function that just returns the first element of the pair, without the Ordering:

$g(x, k, \mathrm{Down}) = g(x, y, \mathrm{Floor}) = \lfloor q \rfloor.$

$g(x, k, \mathrm{Up}) = g(x, y, \mathrm{Ceiling}) = \lceil q \rceil.$

$$ g(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} $$

$g(x, k, \mathrm{Exact}) = q$, but panics if $q \notin \N$.

Then

$f(x, k, r) = (g(x, k, r), \operatorname{cmp}(g(x, k, r), q))$.

§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

source§

impl ShrRound<u16> for u8

source§

fn shr_round(self, bits: u16, rm: RoundingMode) -> (u8, Ordering)

Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode. An Ordering is also returned, indicating whether the returned value is less than, equal to, or greater than the exact value.

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}$, and let $g$ be the function that just returns the first element of the pair, without the Ordering:

$g(x, k, \mathrm{Down}) = g(x, y, \mathrm{Floor}) = \lfloor q \rfloor.$

$g(x, k, \mathrm{Up}) = g(x, y, \mathrm{Ceiling}) = \lceil q \rceil.$

$$ g(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} $$

$g(x, k, \mathrm{Exact}) = q$, but panics if $q \notin \N$.

Then

$f(x, k, r) = (g(x, k, r), \operatorname{cmp}(g(x, k, r), q))$.

§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

source§

impl ShrRound<u16> for u16

source§

fn shr_round(self, bits: u16, rm: RoundingMode) -> (u16, Ordering)

Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode. An Ordering is also returned, indicating whether the returned value is less than, equal to, or greater than the exact value.

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}$, and let $g$ be the function that just returns the first element of the pair, without the Ordering:

$g(x, k, \mathrm{Down}) = g(x, y, \mathrm{Floor}) = \lfloor q \rfloor.$

$g(x, k, \mathrm{Up}) = g(x, y, \mathrm{Ceiling}) = \lceil q \rceil.$

$$ g(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} $$

$g(x, k, \mathrm{Exact}) = q$, but panics if $q \notin \N$.

Then

$f(x, k, r) = (g(x, k, r), \operatorname{cmp}(g(x, k, r), q))$.

§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

source§

impl ShrRound<u16> for u32

source§

fn shr_round(self, bits: u16, rm: RoundingMode) -> (u32, Ordering)

Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode. An Ordering is also returned, indicating whether the returned value is less than, equal to, or greater than the exact value.

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}$, and let $g$ be the function that just returns the first element of the pair, without the Ordering:

$g(x, k, \mathrm{Down}) = g(x, y, \mathrm{Floor}) = \lfloor q \rfloor.$

$g(x, k, \mathrm{Up}) = g(x, y, \mathrm{Ceiling}) = \lceil q \rceil.$

$$ g(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} $$

$g(x, k, \mathrm{Exact}) = q$, but panics if $q \notin \N$.

Then

$f(x, k, r) = (g(x, k, r), \operatorname{cmp}(g(x, k, r), q))$.

§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

source§

impl ShrRound<u16> for u64

source§

fn shr_round(self, bits: u16, rm: RoundingMode) -> (u64, Ordering)

Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode. An Ordering is also returned, indicating whether the returned value is less than, equal to, or greater than the exact value.

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}$, and let $g$ be the function that just returns the first element of the pair, without the Ordering:

$g(x, k, \mathrm{Down}) = g(x, y, \mathrm{Floor}) = \lfloor q \rfloor.$

$g(x, k, \mathrm{Up}) = g(x, y, \mathrm{Ceiling}) = \lceil q \rceil.$

$$ g(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} $$

$g(x, k, \mathrm{Exact}) = q$, but panics if $q \notin \N$.

Then

$f(x, k, r) = (g(x, k, r), \operatorname{cmp}(g(x, k, r), q))$.

§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

source§

impl ShrRound<u16> for u128

source§

fn shr_round(self, bits: u16, rm: RoundingMode) -> (u128, Ordering)

Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode. An Ordering is also returned, indicating whether the returned value is less than, equal to, or greater than the exact value.

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}$, and let $g$ be the function that just returns the first element of the pair, without the Ordering:

$g(x, k, \mathrm{Down}) = g(x, y, \mathrm{Floor}) = \lfloor q \rfloor.$

$g(x, k, \mathrm{Up}) = g(x, y, \mathrm{Ceiling}) = \lceil q \rceil.$

$$ g(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} $$

$g(x, k, \mathrm{Exact}) = q$, but panics if $q \notin \N$.

Then

$f(x, k, r) = (g(x, k, r), \operatorname{cmp}(g(x, k, r), q))$.

§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

source§

impl ShrRound<u16> for usize

source§

fn shr_round(self, bits: u16, rm: RoundingMode) -> (usize, Ordering)

Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode. An Ordering is also returned, indicating whether the returned value is less than, equal to, or greater than the exact value.

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}$, and let $g$ be the function that just returns the first element of the pair, without the Ordering:

$g(x, k, \mathrm{Down}) = g(x, y, \mathrm{Floor}) = \lfloor q \rfloor.$

$g(x, k, \mathrm{Up}) = g(x, y, \mathrm{Ceiling}) = \lceil q \rceil.$

$$ g(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} $$

$g(x, k, \mathrm{Exact}) = q$, but panics if $q \notin \N$.

Then

$f(x, k, r) = (g(x, k, r), \operatorname{cmp}(g(x, k, r), q))$.

§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

source§

impl ShrRound<u32> for i8

source§

fn shr_round(self, bits: u32, rm: RoundingMode) -> (i8, Ordering)

Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode. An Ordering is also returned, indicating whether the returned value is less than, equal to, or greater than the exact value.

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}$, and let $g$ be the function that just returns the first element of the pair, without the Ordering:

$g(x, k, \mathrm{Down}) = g(x, y, \mathrm{Floor}) = \lfloor q \rfloor.$

$g(x, k, \mathrm{Up}) = g(x, y, \mathrm{Ceiling}) = \lceil q \rceil.$

$$ g(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} $$

$g(x, k, \mathrm{Exact}) = q$, but panics if $q \notin \N$.

Then

$f(x, k, r) = (g(x, k, r), \operatorname{cmp}(g(x, k, r), q))$.

§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

source§

impl ShrRound<u32> for i16

source§

fn shr_round(self, bits: u32, rm: RoundingMode) -> (i16, Ordering)

Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode. An Ordering is also returned, indicating whether the returned value is less than, equal to, or greater than the exact value.

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}$, and let $g$ be the function that just returns the first element of the pair, without the Ordering:

$g(x, k, \mathrm{Down}) = g(x, y, \mathrm{Floor}) = \lfloor q \rfloor.$

$g(x, k, \mathrm{Up}) = g(x, y, \mathrm{Ceiling}) = \lceil q \rceil.$

$$ g(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} $$

$g(x, k, \mathrm{Exact}) = q$, but panics if $q \notin \N$.

Then

$f(x, k, r) = (g(x, k, r), \operatorname{cmp}(g(x, k, r), q))$.

§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

source§

impl ShrRound<u32> for i32

source§

fn shr_round(self, bits: u32, rm: RoundingMode) -> (i32, Ordering)

Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode. An Ordering is also returned, indicating whether the returned value is less than, equal to, or greater than the exact value.

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}$, and let $g$ be the function that just returns the first element of the pair, without the Ordering:

$g(x, k, \mathrm{Down}) = g(x, y, \mathrm{Floor}) = \lfloor q \rfloor.$

$g(x, k, \mathrm{Up}) = g(x, y, \mathrm{Ceiling}) = \lceil q \rceil.$

$$ g(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} $$

$g(x, k, \mathrm{Exact}) = q$, but panics if $q \notin \N$.

Then

$f(x, k, r) = (g(x, k, r), \operatorname{cmp}(g(x, k, r), q))$.

§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

source§

impl ShrRound<u32> for i64

source§

fn shr_round(self, bits: u32, rm: RoundingMode) -> (i64, Ordering)

Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode. An Ordering is also returned, indicating whether the returned value is less than, equal to, or greater than the exact value.

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}$, and let $g$ be the function that just returns the first element of the pair, without the Ordering:

$g(x, k, \mathrm{Down}) = g(x, y, \mathrm{Floor}) = \lfloor q \rfloor.$

$g(x, k, \mathrm{Up}) = g(x, y, \mathrm{Ceiling}) = \lceil q \rceil.$

$$ g(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} $$

$g(x, k, \mathrm{Exact}) = q$, but panics if $q \notin \N$.

Then

$f(x, k, r) = (g(x, k, r), \operatorname{cmp}(g(x, k, r), q))$.

§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

source§

impl ShrRound<u32> for i128

source§

fn shr_round(self, bits: u32, rm: RoundingMode) -> (i128, Ordering)

Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode. An Ordering is also returned, indicating whether the returned value is less than, equal to, or greater than the exact value.

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}$, and let $g$ be the function that just returns the first element of the pair, without the Ordering:

$g(x, k, \mathrm{Down}) = g(x, y, \mathrm{Floor}) = \lfloor q \rfloor.$

$g(x, k, \mathrm{Up}) = g(x, y, \mathrm{Ceiling}) = \lceil q \rceil.$

$$ g(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} $$

$g(x, k, \mathrm{Exact}) = q$, but panics if $q \notin \N$.

Then

$f(x, k, r) = (g(x, k, r), \operatorname{cmp}(g(x, k, r), q))$.

§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

source§

impl ShrRound<u32> for isize

source§

fn shr_round(self, bits: u32, rm: RoundingMode) -> (isize, Ordering)

Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode. An Ordering is also returned, indicating whether the returned value is less than, equal to, or greater than the exact value.

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}$, and let $g$ be the function that just returns the first element of the pair, without the Ordering:

$g(x, k, \mathrm{Down}) = g(x, y, \mathrm{Floor}) = \lfloor q \rfloor.$

$g(x, k, \mathrm{Up}) = g(x, y, \mathrm{Ceiling}) = \lceil q \rceil.$

$$ g(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} $$

$g(x, k, \mathrm{Exact}) = q$, but panics if $q \notin \N$.

Then

$f(x, k, r) = (g(x, k, r), \operatorname{cmp}(g(x, k, r), q))$.

§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

source§

impl ShrRound<u32> for u8

source§

fn shr_round(self, bits: u32, rm: RoundingMode) -> (u8, Ordering)

Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode. An Ordering is also returned, indicating whether the returned value is less than, equal to, or greater than the exact value.

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}$, and let $g$ be the function that just returns the first element of the pair, without the Ordering:

$g(x, k, \mathrm{Down}) = g(x, y, \mathrm{Floor}) = \lfloor q \rfloor.$

$g(x, k, \mathrm{Up}) = g(x, y, \mathrm{Ceiling}) = \lceil q \rceil.$

$$ g(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} $$

$g(x, k, \mathrm{Exact}) = q$, but panics if $q \notin \N$.

Then

$f(x, k, r) = (g(x, k, r), \operatorname{cmp}(g(x, k, r), q))$.

§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

source§

impl ShrRound<u32> for u16

source§

fn shr_round(self, bits: u32, rm: RoundingMode) -> (u16, Ordering)

Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode. An Ordering is also returned, indicating whether the returned value is less than, equal to, or greater than the exact value.

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}$, and let $g$ be the function that just returns the first element of the pair, without the Ordering:

$g(x, k, \mathrm{Down}) = g(x, y, \mathrm{Floor}) = \lfloor q \rfloor.$

$g(x, k, \mathrm{Up}) = g(x, y, \mathrm{Ceiling}) = \lceil q \rceil.$

$$ g(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} $$

$g(x, k, \mathrm{Exact}) = q$, but panics if $q \notin \N$.

Then

$f(x, k, r) = (g(x, k, r), \operatorname{cmp}(g(x, k, r), q))$.

§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

source§

impl ShrRound<u32> for u32

source§

fn shr_round(self, bits: u32, rm: RoundingMode) -> (u32, Ordering)

Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode. An Ordering is also returned, indicating whether the returned value is less than, equal to, or greater than the exact value.

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}$, and let $g$ be the function that just returns the first element of the pair, without the Ordering:

$g(x, k, \mathrm{Down}) = g(x, y, \mathrm{Floor}) = \lfloor q \rfloor.$

$g(x, k, \mathrm{Up}) = g(x, y, \mathrm{Ceiling}) = \lceil q \rceil.$

$$ g(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} $$

$g(x, k, \mathrm{Exact}) = q$, but panics if $q \notin \N$.

Then

$f(x, k, r) = (g(x, k, r), \operatorname{cmp}(g(x, k, r), q))$.

§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

source§

impl ShrRound<u32> for u64

source§

fn shr_round(self, bits: u32, rm: RoundingMode) -> (u64, Ordering)

Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode. An Ordering is also returned, indicating whether the returned value is less than, equal to, or greater than the exact value.

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}$, and let $g$ be the function that just returns the first element of the pair, without the Ordering:

$g(x, k, \mathrm{Down}) = g(x, y, \mathrm{Floor}) = \lfloor q \rfloor.$

$g(x, k, \mathrm{Up}) = g(x, y, \mathrm{Ceiling}) = \lceil q \rceil.$

$$ g(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} $$

$g(x, k, \mathrm{Exact}) = q$, but panics if $q \notin \N$.

Then

$f(x, k, r) = (g(x, k, r), \operatorname{cmp}(g(x, k, r), q))$.

§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

source§

impl ShrRound<u32> for u128

source§

fn shr_round(self, bits: u32, rm: RoundingMode) -> (u128, Ordering)

Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode. An Ordering is also returned, indicating whether the returned value is less than, equal to, or greater than the exact value.

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}$, and let $g$ be the function that just returns the first element of the pair, without the Ordering:

$g(x, k, \mathrm{Down}) = g(x, y, \mathrm{Floor}) = \lfloor q \rfloor.$

$g(x, k, \mathrm{Up}) = g(x, y, \mathrm{Ceiling}) = \lceil q \rceil.$

$$ g(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} $$

$g(x, k, \mathrm{Exact}) = q$, but panics if $q \notin \N$.

Then

$f(x, k, r) = (g(x, k, r), \operatorname{cmp}(g(x, k, r), q))$.

§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

source§

impl ShrRound<u32> for usize

source§

fn shr_round(self, bits: u32, rm: RoundingMode) -> (usize, Ordering)

Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode. An Ordering is also returned, indicating whether the returned value is less than, equal to, or greater than the exact value.

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}$, and let $g$ be the function that just returns the first element of the pair, without the Ordering:

$g(x, k, \mathrm{Down}) = g(x, y, \mathrm{Floor}) = \lfloor q \rfloor.$

$g(x, k, \mathrm{Up}) = g(x, y, \mathrm{Ceiling}) = \lceil q \rceil.$

$$ g(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} $$

$g(x, k, \mathrm{Exact}) = q$, but panics if $q \notin \N$.

Then

$f(x, k, r) = (g(x, k, r), \operatorname{cmp}(g(x, k, r), q))$.

§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

source§

impl ShrRound<u64> for i8

source§

fn shr_round(self, bits: u64, rm: RoundingMode) -> (i8, Ordering)

Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode. An Ordering is also returned, indicating whether the returned value is less than, equal to, or greater than the exact value.

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}$, and let $g$ be the function that just returns the first element of the pair, without the Ordering:

$g(x, k, \mathrm{Down}) = g(x, y, \mathrm{Floor}) = \lfloor q \rfloor.$

$g(x, k, \mathrm{Up}) = g(x, y, \mathrm{Ceiling}) = \lceil q \rceil.$

$$ g(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} $$

$g(x, k, \mathrm{Exact}) = q$, but panics if $q \notin \N$.

Then

$f(x, k, r) = (g(x, k, r), \operatorname{cmp}(g(x, k, r), q))$.

§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

source§

impl ShrRound<u64> for i16

source§

fn shr_round(self, bits: u64, rm: RoundingMode) -> (i16, Ordering)

Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode. An Ordering is also returned, indicating whether the returned value is less than, equal to, or greater than the exact value.

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}$, and let $g$ be the function that just returns the first element of the pair, without the Ordering:

$g(x, k, \mathrm{Down}) = g(x, y, \mathrm{Floor}) = \lfloor q \rfloor.$

$g(x, k, \mathrm{Up}) = g(x, y, \mathrm{Ceiling}) = \lceil q \rceil.$

$$ g(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} $$

$g(x, k, \mathrm{Exact}) = q$, but panics if $q \notin \N$.

Then

$f(x, k, r) = (g(x, k, r), \operatorname{cmp}(g(x, k, r), q))$.

§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

source§

impl ShrRound<u64> for i32

source§

fn shr_round(self, bits: u64, rm: RoundingMode) -> (i32, Ordering)

Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode. An Ordering is also returned, indicating whether the returned value is less than, equal to, or greater than the exact value.

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}$, and let $g$ be the function that just returns the first element of the pair, without the Ordering:

$g(x, k, \mathrm{Down}) = g(x, y, \mathrm{Floor}) = \lfloor q \rfloor.$

$g(x, k, \mathrm{Up}) = g(x, y, \mathrm{Ceiling}) = \lceil q \rceil.$

$$ g(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} $$

$g(x, k, \mathrm{Exact}) = q$, but panics if $q \notin \N$.

Then

$f(x, k, r) = (g(x, k, r), \operatorname{cmp}(g(x, k, r), q))$.

§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

source§

impl ShrRound<u64> for i64

source§

fn shr_round(self, bits: u64, rm: RoundingMode) -> (i64, Ordering)

Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode. An Ordering is also returned, indicating whether the returned value is less than, equal to, or greater than the exact value.

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}$, and let $g$ be the function that just returns the first element of the pair, without the Ordering:

$g(x, k, \mathrm{Down}) = g(x, y, \mathrm{Floor}) = \lfloor q \rfloor.$

$g(x, k, \mathrm{Up}) = g(x, y, \mathrm{Ceiling}) = \lceil q \rceil.$

$$ g(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} $$

$g(x, k, \mathrm{Exact}) = q$, but panics if $q \notin \N$.

Then

$f(x, k, r) = (g(x, k, r), \operatorname{cmp}(g(x, k, r), q))$.

§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

source§

impl ShrRound<u64> for i128

source§

fn shr_round(self, bits: u64, rm: RoundingMode) -> (i128, Ordering)

Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode. An Ordering is also returned, indicating whether the returned value is less than, equal to, or greater than the exact value.

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}$, and let $g$ be the function that just returns the first element of the pair, without the Ordering:

$g(x, k, \mathrm{Down}) = g(x, y, \mathrm{Floor}) = \lfloor q \rfloor.$

$g(x, k, \mathrm{Up}) = g(x, y, \mathrm{Ceiling}) = \lceil q \rceil.$

$$ g(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} $$

$g(x, k, \mathrm{Exact}) = q$, but panics if $q \notin \N$.

Then

$f(x, k, r) = (g(x, k, r), \operatorname{cmp}(g(x, k, r), q))$.

§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

source§

impl ShrRound<u64> for isize

source§

fn shr_round(self, bits: u64, rm: RoundingMode) -> (isize, Ordering)

Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode. An Ordering is also returned, indicating whether the returned value is less than, equal to, or greater than the exact value.

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}$, and let $g$ be the function that just returns the first element of the pair, without the Ordering:

$g(x, k, \mathrm{Down}) = g(x, y, \mathrm{Floor}) = \lfloor q \rfloor.$

$g(x, k, \mathrm{Up}) = g(x, y, \mathrm{Ceiling}) = \lceil q \rceil.$

$$ g(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} $$

$g(x, k, \mathrm{Exact}) = q$, but panics if $q \notin \N$.

Then

$f(x, k, r) = (g(x, k, r), \operatorname{cmp}(g(x, k, r), q))$.

§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

source§

impl ShrRound<u64> for u8

source§

fn shr_round(self, bits: u64, rm: RoundingMode) -> (u8, Ordering)

Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode. An Ordering is also returned, indicating whether the returned value is less than, equal to, or greater than the exact value.

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}$, and let $g$ be the function that just returns the first element of the pair, without the Ordering:

$g(x, k, \mathrm{Down}) = g(x, y, \mathrm{Floor}) = \lfloor q \rfloor.$

$g(x, k, \mathrm{Up}) = g(x, y, \mathrm{Ceiling}) = \lceil q \rceil.$

$$ g(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} $$

$g(x, k, \mathrm{Exact}) = q$, but panics if $q \notin \N$.

Then

$f(x, k, r) = (g(x, k, r), \operatorname{cmp}(g(x, k, r), q))$.

§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

source§

impl ShrRound<u64> for u16

source§

fn shr_round(self, bits: u64, rm: RoundingMode) -> (u16, Ordering)

Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode. An Ordering is also returned, indicating whether the returned value is less than, equal to, or greater than the exact value.

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}$, and let $g$ be the function that just returns the first element of the pair, without the Ordering:

$g(x, k, \mathrm{Down}) = g(x, y, \mathrm{Floor}) = \lfloor q \rfloor.$

$g(x, k, \mathrm{Up}) = g(x, y, \mathrm{Ceiling}) = \lceil q \rceil.$

$$ g(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} $$

$g(x, k, \mathrm{Exact}) = q$, but panics if $q \notin \N$.

Then

$f(x, k, r) = (g(x, k, r), \operatorname{cmp}(g(x, k, r), q))$.

§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

source§

impl ShrRound<u64> for u32

source§

fn shr_round(self, bits: u64, rm: RoundingMode) -> (u32, Ordering)

Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode. An Ordering is also returned, indicating whether the returned value is less than, equal to, or greater than the exact value.

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}$, and let $g$ be the function that just returns the first element of the pair, without the Ordering:

$g(x, k, \mathrm{Down}) = g(x, y, \mathrm{Floor}) = \lfloor q \rfloor.$

$g(x, k, \mathrm{Up}) = g(x, y, \mathrm{Ceiling}) = \lceil q \rceil.$

$$ g(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} $$

$g(x, k, \mathrm{Exact}) = q$, but panics if $q \notin \N$.

Then

$f(x, k, r) = (g(x, k, r), \operatorname{cmp}(g(x, k, r), q))$.

§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

source§

impl ShrRound<u64> for u64

source§

fn shr_round(self, bits: u64, rm: RoundingMode) -> (u64, Ordering)

Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode. An Ordering is also returned, indicating whether the returned value is less than, equal to, or greater than the exact value.

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}$, and let $g$ be the function that just returns the first element of the pair, without the Ordering:

$g(x, k, \mathrm{Down}) = g(x, y, \mathrm{Floor}) = \lfloor q \rfloor.$

$g(x, k, \mathrm{Up}) = g(x, y, \mathrm{Ceiling}) = \lceil q \rceil.$

$$ g(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} $$

$g(x, k, \mathrm{Exact}) = q$, but panics if $q \notin \N$.

Then

$f(x, k, r) = (g(x, k, r), \operatorname{cmp}(g(x, k, r), q))$.

§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

source§

impl ShrRound<u64> for u128

source§

fn shr_round(self, bits: u64, rm: RoundingMode) -> (u128, Ordering)

Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode. An Ordering is also returned, indicating whether the returned value is less than, equal to, or greater than the exact value.

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}$, and let $g$ be the function that just returns the first element of the pair, without the Ordering:

$g(x, k, \mathrm{Down}) = g(x, y, \mathrm{Floor}) = \lfloor q \rfloor.$

$g(x, k, \mathrm{Up}) = g(x, y, \mathrm{Ceiling}) = \lceil q \rceil.$

$$ g(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} $$

$g(x, k, \mathrm{Exact}) = q$, but panics if $q \notin \N$.

Then

$f(x, k, r) = (g(x, k, r), \operatorname{cmp}(g(x, k, r), q))$.

§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

source§

impl ShrRound<u64> for usize

source§

fn shr_round(self, bits: u64, rm: RoundingMode) -> (usize, Ordering)

Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode. An Ordering is also returned, indicating whether the returned value is less than, equal to, or greater than the exact value.

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}$, and let $g$ be the function that just returns the first element of the pair, without the Ordering:

$g(x, k, \mathrm{Down}) = g(x, y, \mathrm{Floor}) = \lfloor q \rfloor.$

$g(x, k, \mathrm{Up}) = g(x, y, \mathrm{Ceiling}) = \lceil q \rceil.$

$$ g(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} $$

$g(x, k, \mathrm{Exact}) = q$, but panics if $q \notin \N$.

Then

$f(x, k, r) = (g(x, k, r), \operatorname{cmp}(g(x, k, r), q))$.

§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

source§

impl ShrRound<u128> for i8

source§

fn shr_round(self, bits: u128, rm: RoundingMode) -> (i8, Ordering)

Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode. An Ordering is also returned, indicating whether the returned value is less than, equal to, or greater than the exact value.

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}$, and let $g$ be the function that just returns the first element of the pair, without the Ordering:

$g(x, k, \mathrm{Down}) = g(x, y, \mathrm{Floor}) = \lfloor q \rfloor.$

$g(x, k, \mathrm{Up}) = g(x, y, \mathrm{Ceiling}) = \lceil q \rceil.$

$$ g(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} $$

$g(x, k, \mathrm{Exact}) = q$, but panics if $q \notin \N$.

Then

$f(x, k, r) = (g(x, k, r), \operatorname{cmp}(g(x, k, r), q))$.

§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

source§

impl ShrRound<u128> for i16

source§

fn shr_round(self, bits: u128, rm: RoundingMode) -> (i16, Ordering)

Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode. An Ordering is also returned, indicating whether the returned value is less than, equal to, or greater than the exact value.

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}$, and let $g$ be the function that just returns the first element of the pair, without the Ordering:

$g(x, k, \mathrm{Down}) = g(x, y, \mathrm{Floor}) = \lfloor q \rfloor.$

$g(x, k, \mathrm{Up}) = g(x, y, \mathrm{Ceiling}) = \lceil q \rceil.$

$$ g(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} $$

$g(x, k, \mathrm{Exact}) = q$, but panics if $q \notin \N$.

Then

$f(x, k, r) = (g(x, k, r), \operatorname{cmp}(g(x, k, r), q))$.

§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

source§

impl ShrRound<u128> for i32

source§

fn shr_round(self, bits: u128, rm: RoundingMode) -> (i32, Ordering)

Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode. An Ordering is also returned, indicating whether the returned value is less than, equal to, or greater than the exact value.

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}$, and let $g$ be the function that just returns the first element of the pair, without the Ordering:

$g(x, k, \mathrm{Down}) = g(x, y, \mathrm{Floor}) = \lfloor q \rfloor.$

$g(x, k, \mathrm{Up}) = g(x, y, \mathrm{Ceiling}) = \lceil q \rceil.$

$$ g(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} $$

$g(x, k, \mathrm{Exact}) = q$, but panics if $q \notin \N$.

Then

$f(x, k, r) = (g(x, k, r), \operatorname{cmp}(g(x, k, r), q))$.

§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

source§

impl ShrRound<u128> for i64

source§

fn shr_round(self, bits: u128, rm: RoundingMode) -> (i64, Ordering)

Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode. An Ordering is also returned, indicating whether the returned value is less than, equal to, or greater than the exact value.

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}$, and let $g$ be the function that just returns the first element of the pair, without the Ordering:

$g(x, k, \mathrm{Down}) = g(x, y, \mathrm{Floor}) = \lfloor q \rfloor.$

$g(x, k, \mathrm{Up}) = g(x, y, \mathrm{Ceiling}) = \lceil q \rceil.$

$$ g(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} $$

$g(x, k, \mathrm{Exact}) = q$, but panics if $q \notin \N$.

Then

$f(x, k, r) = (g(x, k, r), \operatorname{cmp}(g(x, k, r), q))$.

§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

source§

impl ShrRound<u128> for i128

source§

fn shr_round(self, bits: u128, rm: RoundingMode) -> (i128, Ordering)

Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode. An Ordering is also returned, indicating whether the returned value is less than, equal to, or greater than the exact value.

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}$, and let $g$ be the function that just returns the first element of the pair, without the Ordering:

$g(x, k, \mathrm{Down}) = g(x, y, \mathrm{Floor}) = \lfloor q \rfloor.$

$g(x, k, \mathrm{Up}) = g(x, y, \mathrm{Ceiling}) = \lceil q \rceil.$

$$ g(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} $$

$g(x, k, \mathrm{Exact}) = q$, but panics if $q \notin \N$.

Then

$f(x, k, r) = (g(x, k, r), \operatorname{cmp}(g(x, k, r), q))$.

§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

source§

impl ShrRound<u128> for isize

source§

fn shr_round(self, bits: u128, rm: RoundingMode) -> (isize, Ordering)

Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode. An Ordering is also returned, indicating whether the returned value is less than, equal to, or greater than the exact value.

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}$, and let $g$ be the function that just returns the first element of the pair, without the Ordering:

$g(x, k, \mathrm{Down}) = g(x, y, \mathrm{Floor}) = \lfloor q \rfloor.$

$g(x, k, \mathrm{Up}) = g(x, y, \mathrm{Ceiling}) = \lceil q \rceil.$

$$ g(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} $$

$g(x, k, \mathrm{Exact}) = q$, but panics if $q \notin \N$.

Then

$f(x, k, r) = (g(x, k, r), \operatorname{cmp}(g(x, k, r), q))$.

§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

source§

impl ShrRound<u128> for u8

source§

fn shr_round(self, bits: u128, rm: RoundingMode) -> (u8, Ordering)

Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode. An Ordering is also returned, indicating whether the returned value is less than, equal to, or greater than the exact value.

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}$, and let $g$ be the function that just returns the first element of the pair, without the Ordering:

$g(x, k, \mathrm{Down}) = g(x, y, \mathrm{Floor}) = \lfloor q \rfloor.$

$g(x, k, \mathrm{Up}) = g(x, y, \mathrm{Ceiling}) = \lceil q \rceil.$

$$ g(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} $$

$g(x, k, \mathrm{Exact}) = q$, but panics if $q \notin \N$.

Then

$f(x, k, r) = (g(x, k, r), \operatorname{cmp}(g(x, k, r), q))$.

§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

source§

impl ShrRound<u128> for u16

source§

fn shr_round(self, bits: u128, rm: RoundingMode) -> (u16, Ordering)

Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode. An Ordering is also returned, indicating whether the returned value is less than, equal to, or greater than the exact value.

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}$, and let $g$ be the function that just returns the first element of the pair, without the Ordering:

$g(x, k, \mathrm{Down}) = g(x, y, \mathrm{Floor}) = \lfloor q \rfloor.$

$g(x, k, \mathrm{Up}) = g(x, y, \mathrm{Ceiling}) = \lceil q \rceil.$

$$ g(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} $$

$g(x, k, \mathrm{Exact}) = q$, but panics if $q \notin \N$.

Then

$f(x, k, r) = (g(x, k, r), \operatorname{cmp}(g(x, k, r), q))$.

§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

source§

impl ShrRound<u128> for u32

source§

fn shr_round(self, bits: u128, rm: RoundingMode) -> (u32, Ordering)

Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode. An Ordering is also returned, indicating whether the returned value is less than, equal to, or greater than the exact value.

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}$, and let $g$ be the function that just returns the first element of the pair, without the Ordering:

$g(x, k, \mathrm{Down}) = g(x, y, \mathrm{Floor}) = \lfloor q \rfloor.$

$g(x, k, \mathrm{Up}) = g(x, y, \mathrm{Ceiling}) = \lceil q \rceil.$

$$ g(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} $$

$g(x, k, \mathrm{Exact}) = q$, but panics if $q \notin \N$.

Then

$f(x, k, r) = (g(x, k, r), \operatorname{cmp}(g(x, k, r), q))$.

§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

source§

impl ShrRound<u128> for u64

source§

fn shr_round(self, bits: u128, rm: RoundingMode) -> (u64, Ordering)

Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode. An Ordering is also returned, indicating whether the returned value is less than, equal to, or greater than the exact value.

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}$, and let $g$ be the function that just returns the first element of the pair, without the Ordering:

$g(x, k, \mathrm{Down}) = g(x, y, \mathrm{Floor}) = \lfloor q \rfloor.$

$g(x, k, \mathrm{Up}) = g(x, y, \mathrm{Ceiling}) = \lceil q \rceil.$

$$ g(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} $$

$g(x, k, \mathrm{Exact}) = q$, but panics if $q \notin \N$.

Then

$f(x, k, r) = (g(x, k, r), \operatorname{cmp}(g(x, k, r), q))$.

§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

source§

impl ShrRound<u128> for u128

source§

fn shr_round(self, bits: u128, rm: RoundingMode) -> (u128, Ordering)

Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode. An Ordering is also returned, indicating whether the returned value is less than, equal to, or greater than the exact value.

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}$, and let $g$ be the function that just returns the first element of the pair, without the Ordering:

$g(x, k, \mathrm{Down}) = g(x, y, \mathrm{Floor}) = \lfloor q \rfloor.$

$g(x, k, \mathrm{Up}) = g(x, y, \mathrm{Ceiling}) = \lceil q \rceil.$

$$ g(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} $$

$g(x, k, \mathrm{Exact}) = q$, but panics if $q \notin \N$.

Then

$f(x, k, r) = (g(x, k, r), \operatorname{cmp}(g(x, k, r), q))$.

§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

source§

impl ShrRound<u128> for usize

source§

fn shr_round(self, bits: u128, rm: RoundingMode) -> (usize, Ordering)

Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode. An Ordering is also returned, indicating whether the returned value is less than, equal to, or greater than the exact value.

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}$, and let $g$ be the function that just returns the first element of the pair, without the Ordering:

$g(x, k, \mathrm{Down}) = g(x, y, \mathrm{Floor}) = \lfloor q \rfloor.$

$g(x, k, \mathrm{Up}) = g(x, y, \mathrm{Ceiling}) = \lceil q \rceil.$

$$ g(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} $$

$g(x, k, \mathrm{Exact}) = q$, but panics if $q \notin \N$.

Then

$f(x, k, r) = (g(x, k, r), \operatorname{cmp}(g(x, k, r), q))$.

§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

source§

impl ShrRound<usize> for i8

source§

fn shr_round(self, bits: usize, rm: RoundingMode) -> (i8, Ordering)

Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode. An Ordering is also returned, indicating whether the returned value is less than, equal to, or greater than the exact value.

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}$, and let $g$ be the function that just returns the first element of the pair, without the Ordering:

$g(x, k, \mathrm{Down}) = g(x, y, \mathrm{Floor}) = \lfloor q \rfloor.$

$g(x, k, \mathrm{Up}) = g(x, y, \mathrm{Ceiling}) = \lceil q \rceil.$

$$ g(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} $$

$g(x, k, \mathrm{Exact}) = q$, but panics if $q \notin \N$.

Then

$f(x, k, r) = (g(x, k, r), \operatorname{cmp}(g(x, k, r), q))$.

§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

source§

impl ShrRound<usize> for i16

source§

fn shr_round(self, bits: usize, rm: RoundingMode) -> (i16, Ordering)

Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode. An Ordering is also returned, indicating whether the returned value is less than, equal to, or greater than the exact value.

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}$, and let $g$ be the function that just returns the first element of the pair, without the Ordering:

$g(x, k, \mathrm{Down}) = g(x, y, \mathrm{Floor}) = \lfloor q \rfloor.$

$g(x, k, \mathrm{Up}) = g(x, y, \mathrm{Ceiling}) = \lceil q \rceil.$

$$ g(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} $$

$g(x, k, \mathrm{Exact}) = q$, but panics if $q \notin \N$.

Then

$f(x, k, r) = (g(x, k, r), \operatorname{cmp}(g(x, k, r), q))$.

§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

source§

impl ShrRound<usize> for i32

source§

fn shr_round(self, bits: usize, rm: RoundingMode) -> (i32, Ordering)

Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode. An Ordering is also returned, indicating whether the returned value is less than, equal to, or greater than the exact value.

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}$, and let $g$ be the function that just returns the first element of the pair, without the Ordering:

$g(x, k, \mathrm{Down}) = g(x, y, \mathrm{Floor}) = \lfloor q \rfloor.$

$g(x, k, \mathrm{Up}) = g(x, y, \mathrm{Ceiling}) = \lceil q \rceil.$

$$ g(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} $$

$g(x, k, \mathrm{Exact}) = q$, but panics if $q \notin \N$.

Then

$f(x, k, r) = (g(x, k, r), \operatorname{cmp}(g(x, k, r), q))$.

§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

source§

impl ShrRound<usize> for i64

source§

fn shr_round(self, bits: usize, rm: RoundingMode) -> (i64, Ordering)

Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode. An Ordering is also returned, indicating whether the returned value is less than, equal to, or greater than the exact value.

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}$, and let $g$ be the function that just returns the first element of the pair, without the Ordering:

$g(x, k, \mathrm{Down}) = g(x, y, \mathrm{Floor}) = \lfloor q \rfloor.$

$g(x, k, \mathrm{Up}) = g(x, y, \mathrm{Ceiling}) = \lceil q \rceil.$

$$ g(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} $$

$g(x, k, \mathrm{Exact}) = q$, but panics if $q \notin \N$.

Then

$f(x, k, r) = (g(x, k, r), \operatorname{cmp}(g(x, k, r), q))$.

§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

source§

impl ShrRound<usize> for i128

source§

fn shr_round(self, bits: usize, rm: RoundingMode) -> (i128, Ordering)

Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode. An Ordering is also returned, indicating whether the returned value is less than, equal to, or greater than the exact value.

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}$, and let $g$ be the function that just returns the first element of the pair, without the Ordering:

$g(x, k, \mathrm{Down}) = g(x, y, \mathrm{Floor}) = \lfloor q \rfloor.$

$g(x, k, \mathrm{Up}) = g(x, y, \mathrm{Ceiling}) = \lceil q \rceil.$

$$ g(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} $$

$g(x, k, \mathrm{Exact}) = q$, but panics if $q \notin \N$.

Then

$f(x, k, r) = (g(x, k, r), \operatorname{cmp}(g(x, k, r), q))$.

§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

source§

impl ShrRound<usize> for isize

source§

fn shr_round(self, bits: usize, rm: RoundingMode) -> (isize, Ordering)

Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode. An Ordering is also returned, indicating whether the returned value is less than, equal to, or greater than the exact value.

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}$, and let $g$ be the function that just returns the first element of the pair, without the Ordering:

$g(x, k, \mathrm{Down}) = g(x, y, \mathrm{Floor}) = \lfloor q \rfloor.$

$g(x, k, \mathrm{Up}) = g(x, y, \mathrm{Ceiling}) = \lceil q \rceil.$

$$ g(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} $$

$g(x, k, \mathrm{Exact}) = q$, but panics if $q \notin \N$.

Then

$f(x, k, r) = (g(x, k, r), \operatorname{cmp}(g(x, k, r), q))$.

§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

source§

impl ShrRound<usize> for u8

source§

fn shr_round(self, bits: usize, rm: RoundingMode) -> (u8, Ordering)

Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode. An Ordering is also returned, indicating whether the returned value is less than, equal to, or greater than the exact value.

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}$, and let $g$ be the function that just returns the first element of the pair, without the Ordering:

$g(x, k, \mathrm{Down}) = g(x, y, \mathrm{Floor}) = \lfloor q \rfloor.$

$g(x, k, \mathrm{Up}) = g(x, y, \mathrm{Ceiling}) = \lceil q \rceil.$

$$ g(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} $$

$g(x, k, \mathrm{Exact}) = q$, but panics if $q \notin \N$.

Then

$f(x, k, r) = (g(x, k, r), \operatorname{cmp}(g(x, k, r), q))$.

§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

source§

impl ShrRound<usize> for u16

source§

fn shr_round(self, bits: usize, rm: RoundingMode) -> (u16, Ordering)

Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode. An Ordering is also returned, indicating whether the returned value is less than, equal to, or greater than the exact value.

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}$, and let $g$ be the function that just returns the first element of the pair, without the Ordering:

$g(x, k, \mathrm{Down}) = g(x, y, \mathrm{Floor}) = \lfloor q \rfloor.$

$g(x, k, \mathrm{Up}) = g(x, y, \mathrm{Ceiling}) = \lceil q \rceil.$

$$ g(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} $$

$g(x, k, \mathrm{Exact}) = q$, but panics if $q \notin \N$.

Then

$f(x, k, r) = (g(x, k, r), \operatorname{cmp}(g(x, k, r), q))$.

§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

source§

impl ShrRound<usize> for u32

source§

fn shr_round(self, bits: usize, rm: RoundingMode) -> (u32, Ordering)

Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode. An Ordering is also returned, indicating whether the returned value is less than, equal to, or greater than the exact value.

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}$, and let $g$ be the function that just returns the first element of the pair, without the Ordering:

$g(x, k, \mathrm{Down}) = g(x, y, \mathrm{Floor}) = \lfloor q \rfloor.$

$g(x, k, \mathrm{Up}) = g(x, y, \mathrm{Ceiling}) = \lceil q \rceil.$

$$ g(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} $$

$g(x, k, \mathrm{Exact}) = q$, but panics if $q \notin \N$.

Then

$f(x, k, r) = (g(x, k, r), \operatorname{cmp}(g(x, k, r), q))$.

§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

source§

impl ShrRound<usize> for u64

source§

fn shr_round(self, bits: usize, rm: RoundingMode) -> (u64, Ordering)

Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode. An Ordering is also returned, indicating whether the returned value is less than, equal to, or greater than the exact value.

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}$, and let $g$ be the function that just returns the first element of the pair, without the Ordering:

$g(x, k, \mathrm{Down}) = g(x, y, \mathrm{Floor}) = \lfloor q \rfloor.$

$g(x, k, \mathrm{Up}) = g(x, y, \mathrm{Ceiling}) = \lceil q \rceil.$

$$ g(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} $$

$g(x, k, \mathrm{Exact}) = q$, but panics if $q \notin \N$.

Then

$f(x, k, r) = (g(x, k, r), \operatorname{cmp}(g(x, k, r), q))$.

§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

source§

impl ShrRound<usize> for u128

source§

fn shr_round(self, bits: usize, rm: RoundingMode) -> (u128, Ordering)

Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode. An Ordering is also returned, indicating whether the returned value is less than, equal to, or greater than the exact value.

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}$, and let $g$ be the function that just returns the first element of the pair, without the Ordering:

$g(x, k, \mathrm{Down}) = g(x, y, \mathrm{Floor}) = \lfloor q \rfloor.$

$g(x, k, \mathrm{Up}) = g(x, y, \mathrm{Ceiling}) = \lceil q \rceil.$

$$ g(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} $$

$g(x, k, \mathrm{Exact}) = q$, but panics if $q \notin \N$.

Then

$f(x, k, r) = (g(x, k, r), \operatorname{cmp}(g(x, k, r), q))$.

§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

source§

impl ShrRound<usize> for usize

source§

fn shr_round(self, bits: usize, rm: RoundingMode) -> (usize, Ordering)

Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode. An Ordering is also returned, indicating whether the returned value is less than, equal to, or greater than the exact value.

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}$, and let $g$ be the function that just returns the first element of the pair, without the Ordering:

$g(x, k, \mathrm{Down}) = g(x, y, \mathrm{Floor}) = \lfloor q \rfloor.$

$g(x, k, \mathrm{Up}) = g(x, y, \mathrm{Ceiling}) = \lceil q \rceil.$

$$ g(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} $$

$g(x, k, \mathrm{Exact}) = q$, but panics if $q \notin \N$.

Then

$f(x, k, r) = (g(x, k, r), \operatorname{cmp}(g(x, k, r), q))$.

§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

Implementors§