Trait malachite_base::num::arithmetic::traits::ShlRound
source · pub trait ShlRound<RHS> {
type Output;
// Required method
fn shl_round(self, other: RHS, rm: RoundingMode) -> (Self::Output, Ordering);
}
Expand description
Left-shifts a number (multiplies 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 negative.
Required Associated Types§
Required Methods§
fn shl_round(self, other: RHS, rm: RoundingMode) -> (Self::Output, Ordering)
Implementations on Foreign Types§
source§impl ShlRound<i8> for i8
impl ShlRound<i8> for i8
source§fn shl_round(self, bits: i8, rm: RoundingMode) -> (i8, Ordering)
fn shl_round(self, bits: i8, rm: RoundingMode) -> (i8, Ordering)
Left-shifts a number (multiplies it by a power of 2 or divides it by a power
of 2 and takes the floor) 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
non-negative, then the returned Ordering
is always Equal
, even if the
higher bits of the result are lost.
Passing Floor
or Down
is equivalent to using >>
. To test whether
Exact
can be passed, use bits > 0 || self.divisible_by_power_of_2(bits)
.
Rounding might only be necessary if bits
is negative.
Let $q = x2^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 bits
is positive and rm
is Exact
but self
is not divisible
by $2^b$.
§Examples
See here.
type Output = i8
source§impl ShlRound<i8> for i16
impl ShlRound<i8> for i16
source§fn shl_round(self, bits: i8, rm: RoundingMode) -> (i16, Ordering)
fn shl_round(self, bits: i8, rm: RoundingMode) -> (i16, Ordering)
Left-shifts a number (multiplies it by a power of 2 or divides it by a power
of 2 and takes the floor) 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
non-negative, then the returned Ordering
is always Equal
, even if the
higher bits of the result are lost.
Passing Floor
or Down
is equivalent to using >>
. To test whether
Exact
can be passed, use bits > 0 || self.divisible_by_power_of_2(bits)
.
Rounding might only be necessary if bits
is negative.
Let $q = x2^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 bits
is positive and rm
is Exact
but self
is not divisible
by $2^b$.
§Examples
See here.
type Output = i16
source§impl ShlRound<i8> for i32
impl ShlRound<i8> for i32
source§fn shl_round(self, bits: i8, rm: RoundingMode) -> (i32, Ordering)
fn shl_round(self, bits: i8, rm: RoundingMode) -> (i32, Ordering)
Left-shifts a number (multiplies it by a power of 2 or divides it by a power
of 2 and takes the floor) 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
non-negative, then the returned Ordering
is always Equal
, even if the
higher bits of the result are lost.
Passing Floor
or Down
is equivalent to using >>
. To test whether
Exact
can be passed, use bits > 0 || self.divisible_by_power_of_2(bits)
.
Rounding might only be necessary if bits
is negative.
Let $q = x2^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 bits
is positive and rm
is Exact
but self
is not divisible
by $2^b$.
§Examples
See here.
type Output = i32
source§impl ShlRound<i8> for i64
impl ShlRound<i8> for i64
source§fn shl_round(self, bits: i8, rm: RoundingMode) -> (i64, Ordering)
fn shl_round(self, bits: i8, rm: RoundingMode) -> (i64, Ordering)
Left-shifts a number (multiplies it by a power of 2 or divides it by a power
of 2 and takes the floor) 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
non-negative, then the returned Ordering
is always Equal
, even if the
higher bits of the result are lost.
Passing Floor
or Down
is equivalent to using >>
. To test whether
Exact
can be passed, use bits > 0 || self.divisible_by_power_of_2(bits)
.
Rounding might only be necessary if bits
is negative.
Let $q = x2^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 bits
is positive and rm
is Exact
but self
is not divisible
by $2^b$.
§Examples
See here.
type Output = i64
source§impl ShlRound<i8> for i128
impl ShlRound<i8> for i128
source§fn shl_round(self, bits: i8, rm: RoundingMode) -> (i128, Ordering)
fn shl_round(self, bits: i8, rm: RoundingMode) -> (i128, Ordering)
Left-shifts a number (multiplies it by a power of 2 or divides it by a power
of 2 and takes the floor) 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
non-negative, then the returned Ordering
is always Equal
, even if the
higher bits of the result are lost.
Passing Floor
or Down
is equivalent to using >>
. To test whether
Exact
can be passed, use bits > 0 || self.divisible_by_power_of_2(bits)
.
Rounding might only be necessary if bits
is negative.
Let $q = x2^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 bits
is positive and rm
is Exact
but self
is not divisible
by $2^b$.
§Examples
See here.
type Output = i128
source§impl ShlRound<i8> for isize
impl ShlRound<i8> for isize
source§fn shl_round(self, bits: i8, rm: RoundingMode) -> (isize, Ordering)
fn shl_round(self, bits: i8, rm: RoundingMode) -> (isize, Ordering)
Left-shifts a number (multiplies it by a power of 2 or divides it by a power
of 2 and takes the floor) 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
non-negative, then the returned Ordering
is always Equal
, even if the
higher bits of the result are lost.
Passing Floor
or Down
is equivalent to using >>
. To test whether
Exact
can be passed, use bits > 0 || self.divisible_by_power_of_2(bits)
.
Rounding might only be necessary if bits
is negative.
Let $q = x2^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 bits
is positive and rm
is Exact
but self
is not divisible
by $2^b$.
§Examples
See here.
type Output = isize
source§impl ShlRound<i8> for u8
impl ShlRound<i8> for u8
source§fn shl_round(self, bits: i8, rm: RoundingMode) -> (u8, Ordering)
fn shl_round(self, bits: i8, rm: RoundingMode) -> (u8, Ordering)
Left-shifts a number (multiplies it by a power of 2 or divides it by a power
of 2 and takes the floor) 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
non-negative, then the returned Ordering
is always Equal
, even if the
higher bits of the result are lost.
Passing Floor
or Down
is equivalent to using >>
. To test whether
Exact
can be passed, use bits > 0 || self.divisible_by_power_of_2(bits)
.
Rounding might only be necessary if bits
is negative.
Let $q = x2^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 bits
is positive and rm
is Exact
but self
is not divisible
by $2^b$.
§Examples
See here.
type Output = u8
source§impl ShlRound<i8> for u16
impl ShlRound<i8> for u16
source§fn shl_round(self, bits: i8, rm: RoundingMode) -> (u16, Ordering)
fn shl_round(self, bits: i8, rm: RoundingMode) -> (u16, Ordering)
Left-shifts a number (multiplies it by a power of 2 or divides it by a power
of 2 and takes the floor) 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
non-negative, then the returned Ordering
is always Equal
, even if the
higher bits of the result are lost.
Passing Floor
or Down
is equivalent to using >>
. To test whether
Exact
can be passed, use bits > 0 || self.divisible_by_power_of_2(bits)
.
Rounding might only be necessary if bits
is negative.
Let $q = x2^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 bits
is positive and rm
is Exact
but self
is not divisible
by $2^b$.
§Examples
See here.
type Output = u16
source§impl ShlRound<i8> for u32
impl ShlRound<i8> for u32
source§fn shl_round(self, bits: i8, rm: RoundingMode) -> (u32, Ordering)
fn shl_round(self, bits: i8, rm: RoundingMode) -> (u32, Ordering)
Left-shifts a number (multiplies it by a power of 2 or divides it by a power
of 2 and takes the floor) 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
non-negative, then the returned Ordering
is always Equal
, even if the
higher bits of the result are lost.
Passing Floor
or Down
is equivalent to using >>
. To test whether
Exact
can be passed, use bits > 0 || self.divisible_by_power_of_2(bits)
.
Rounding might only be necessary if bits
is negative.
Let $q = x2^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 bits
is positive and rm
is Exact
but self
is not divisible
by $2^b$.
§Examples
See here.
type Output = u32
source§impl ShlRound<i8> for u64
impl ShlRound<i8> for u64
source§fn shl_round(self, bits: i8, rm: RoundingMode) -> (u64, Ordering)
fn shl_round(self, bits: i8, rm: RoundingMode) -> (u64, Ordering)
Left-shifts a number (multiplies it by a power of 2 or divides it by a power
of 2 and takes the floor) 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
non-negative, then the returned Ordering
is always Equal
, even if the
higher bits of the result are lost.
Passing Floor
or Down
is equivalent to using >>
. To test whether
Exact
can be passed, use bits > 0 || self.divisible_by_power_of_2(bits)
.
Rounding might only be necessary if bits
is negative.
Let $q = x2^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 bits
is positive and rm
is Exact
but self
is not divisible
by $2^b$.
§Examples
See here.
type Output = u64
source§impl ShlRound<i8> for u128
impl ShlRound<i8> for u128
source§fn shl_round(self, bits: i8, rm: RoundingMode) -> (u128, Ordering)
fn shl_round(self, bits: i8, rm: RoundingMode) -> (u128, Ordering)
Left-shifts a number (multiplies it by a power of 2 or divides it by a power
of 2 and takes the floor) 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
non-negative, then the returned Ordering
is always Equal
, even if the
higher bits of the result are lost.
Passing Floor
or Down
is equivalent to using >>
. To test whether
Exact
can be passed, use bits > 0 || self.divisible_by_power_of_2(bits)
.
Rounding might only be necessary if bits
is negative.
Let $q = x2^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 bits
is positive and rm
is Exact
but self
is not divisible
by $2^b$.
§Examples
See here.
type Output = u128
source§impl ShlRound<i8> for usize
impl ShlRound<i8> for usize
source§fn shl_round(self, bits: i8, rm: RoundingMode) -> (usize, Ordering)
fn shl_round(self, bits: i8, rm: RoundingMode) -> (usize, Ordering)
Left-shifts a number (multiplies it by a power of 2 or divides it by a power
of 2 and takes the floor) 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
non-negative, then the returned Ordering
is always Equal
, even if the
higher bits of the result are lost.
Passing Floor
or Down
is equivalent to using >>
. To test whether
Exact
can be passed, use bits > 0 || self.divisible_by_power_of_2(bits)
.
Rounding might only be necessary if bits
is negative.
Let $q = x2^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 bits
is positive and rm
is Exact
but self
is not divisible
by $2^b$.
§Examples
See here.
type Output = usize
source§impl ShlRound<i16> for i8
impl ShlRound<i16> for i8
source§fn shl_round(self, bits: i16, rm: RoundingMode) -> (i8, Ordering)
fn shl_round(self, bits: i16, rm: RoundingMode) -> (i8, Ordering)
Left-shifts a number (multiplies it by a power of 2 or divides it by a power
of 2 and takes the floor) 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
non-negative, then the returned Ordering
is always Equal
, even if the
higher bits of the result are lost.
Passing Floor
or Down
is equivalent to using >>
. To test whether
Exact
can be passed, use bits > 0 || self.divisible_by_power_of_2(bits)
.
Rounding might only be necessary if bits
is negative.
Let $q = x2^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 bits
is positive and rm
is Exact
but self
is not divisible
by $2^b$.
§Examples
See here.
type Output = i8
source§impl ShlRound<i16> for i16
impl ShlRound<i16> for i16
source§fn shl_round(self, bits: i16, rm: RoundingMode) -> (i16, Ordering)
fn shl_round(self, bits: i16, rm: RoundingMode) -> (i16, Ordering)
Left-shifts a number (multiplies it by a power of 2 or divides it by a power
of 2 and takes the floor) 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
non-negative, then the returned Ordering
is always Equal
, even if the
higher bits of the result are lost.
Passing Floor
or Down
is equivalent to using >>
. To test whether
Exact
can be passed, use bits > 0 || self.divisible_by_power_of_2(bits)
.
Rounding might only be necessary if bits
is negative.
Let $q = x2^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 bits
is positive and rm
is Exact
but self
is not divisible
by $2^b$.
§Examples
See here.
type Output = i16
source§impl ShlRound<i16> for i32
impl ShlRound<i16> for i32
source§fn shl_round(self, bits: i16, rm: RoundingMode) -> (i32, Ordering)
fn shl_round(self, bits: i16, rm: RoundingMode) -> (i32, Ordering)
Left-shifts a number (multiplies it by a power of 2 or divides it by a power
of 2 and takes the floor) 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
non-negative, then the returned Ordering
is always Equal
, even if the
higher bits of the result are lost.
Passing Floor
or Down
is equivalent to using >>
. To test whether
Exact
can be passed, use bits > 0 || self.divisible_by_power_of_2(bits)
.
Rounding might only be necessary if bits
is negative.
Let $q = x2^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 bits
is positive and rm
is Exact
but self
is not divisible
by $2^b$.
§Examples
See here.
type Output = i32
source§impl ShlRound<i16> for i64
impl ShlRound<i16> for i64
source§fn shl_round(self, bits: i16, rm: RoundingMode) -> (i64, Ordering)
fn shl_round(self, bits: i16, rm: RoundingMode) -> (i64, Ordering)
Left-shifts a number (multiplies it by a power of 2 or divides it by a power
of 2 and takes the floor) 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
non-negative, then the returned Ordering
is always Equal
, even if the
higher bits of the result are lost.
Passing Floor
or Down
is equivalent to using >>
. To test whether
Exact
can be passed, use bits > 0 || self.divisible_by_power_of_2(bits)
.
Rounding might only be necessary if bits
is negative.
Let $q = x2^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 bits
is positive and rm
is Exact
but self
is not divisible
by $2^b$.
§Examples
See here.
type Output = i64
source§impl ShlRound<i16> for i128
impl ShlRound<i16> for i128
source§fn shl_round(self, bits: i16, rm: RoundingMode) -> (i128, Ordering)
fn shl_round(self, bits: i16, rm: RoundingMode) -> (i128, Ordering)
Left-shifts a number (multiplies it by a power of 2 or divides it by a power
of 2 and takes the floor) 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
non-negative, then the returned Ordering
is always Equal
, even if the
higher bits of the result are lost.
Passing Floor
or Down
is equivalent to using >>
. To test whether
Exact
can be passed, use bits > 0 || self.divisible_by_power_of_2(bits)
.
Rounding might only be necessary if bits
is negative.
Let $q = x2^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 bits
is positive and rm
is Exact
but self
is not divisible
by $2^b$.
§Examples
See here.
type Output = i128
source§impl ShlRound<i16> for isize
impl ShlRound<i16> for isize
source§fn shl_round(self, bits: i16, rm: RoundingMode) -> (isize, Ordering)
fn shl_round(self, bits: i16, rm: RoundingMode) -> (isize, Ordering)
Left-shifts a number (multiplies it by a power of 2 or divides it by a power
of 2 and takes the floor) 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
non-negative, then the returned Ordering
is always Equal
, even if the
higher bits of the result are lost.
Passing Floor
or Down
is equivalent to using >>
. To test whether
Exact
can be passed, use bits > 0 || self.divisible_by_power_of_2(bits)
.
Rounding might only be necessary if bits
is negative.
Let $q = x2^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 bits
is positive and rm
is Exact
but self
is not divisible
by $2^b$.
§Examples
See here.
type Output = isize
source§impl ShlRound<i16> for u8
impl ShlRound<i16> for u8
source§fn shl_round(self, bits: i16, rm: RoundingMode) -> (u8, Ordering)
fn shl_round(self, bits: i16, rm: RoundingMode) -> (u8, Ordering)
Left-shifts a number (multiplies it by a power of 2 or divides it by a power
of 2 and takes the floor) 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
non-negative, then the returned Ordering
is always Equal
, even if the
higher bits of the result are lost.
Passing Floor
or Down
is equivalent to using >>
. To test whether
Exact
can be passed, use bits > 0 || self.divisible_by_power_of_2(bits)
.
Rounding might only be necessary if bits
is negative.
Let $q = x2^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 bits
is positive and rm
is Exact
but self
is not divisible
by $2^b$.
§Examples
See here.
type Output = u8
source§impl ShlRound<i16> for u16
impl ShlRound<i16> for u16
source§fn shl_round(self, bits: i16, rm: RoundingMode) -> (u16, Ordering)
fn shl_round(self, bits: i16, rm: RoundingMode) -> (u16, Ordering)
Left-shifts a number (multiplies it by a power of 2 or divides it by a power
of 2 and takes the floor) 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
non-negative, then the returned Ordering
is always Equal
, even if the
higher bits of the result are lost.
Passing Floor
or Down
is equivalent to using >>
. To test whether
Exact
can be passed, use bits > 0 || self.divisible_by_power_of_2(bits)
.
Rounding might only be necessary if bits
is negative.
Let $q = x2^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 bits
is positive and rm
is Exact
but self
is not divisible
by $2^b$.
§Examples
See here.
type Output = u16
source§impl ShlRound<i16> for u32
impl ShlRound<i16> for u32
source§fn shl_round(self, bits: i16, rm: RoundingMode) -> (u32, Ordering)
fn shl_round(self, bits: i16, rm: RoundingMode) -> (u32, Ordering)
Left-shifts a number (multiplies it by a power of 2 or divides it by a power
of 2 and takes the floor) 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
non-negative, then the returned Ordering
is always Equal
, even if the
higher bits of the result are lost.
Passing Floor
or Down
is equivalent to using >>
. To test whether
Exact
can be passed, use bits > 0 || self.divisible_by_power_of_2(bits)
.
Rounding might only be necessary if bits
is negative.
Let $q = x2^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 bits
is positive and rm
is Exact
but self
is not divisible
by $2^b$.
§Examples
See here.
type Output = u32
source§impl ShlRound<i16> for u64
impl ShlRound<i16> for u64
source§fn shl_round(self, bits: i16, rm: RoundingMode) -> (u64, Ordering)
fn shl_round(self, bits: i16, rm: RoundingMode) -> (u64, Ordering)
Left-shifts a number (multiplies it by a power of 2 or divides it by a power
of 2 and takes the floor) 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
non-negative, then the returned Ordering
is always Equal
, even if the
higher bits of the result are lost.
Passing Floor
or Down
is equivalent to using >>
. To test whether
Exact
can be passed, use bits > 0 || self.divisible_by_power_of_2(bits)
.
Rounding might only be necessary if bits
is negative.
Let $q = x2^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 bits
is positive and rm
is Exact
but self
is not divisible
by $2^b$.
§Examples
See here.
type Output = u64
source§impl ShlRound<i16> for u128
impl ShlRound<i16> for u128
source§fn shl_round(self, bits: i16, rm: RoundingMode) -> (u128, Ordering)
fn shl_round(self, bits: i16, rm: RoundingMode) -> (u128, Ordering)
Left-shifts a number (multiplies it by a power of 2 or divides it by a power
of 2 and takes the floor) 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
non-negative, then the returned Ordering
is always Equal
, even if the
higher bits of the result are lost.
Passing Floor
or Down
is equivalent to using >>
. To test whether
Exact
can be passed, use bits > 0 || self.divisible_by_power_of_2(bits)
.
Rounding might only be necessary if bits
is negative.
Let $q = x2^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 bits
is positive and rm
is Exact
but self
is not divisible
by $2^b$.
§Examples
See here.
type Output = u128
source§impl ShlRound<i16> for usize
impl ShlRound<i16> for usize
source§fn shl_round(self, bits: i16, rm: RoundingMode) -> (usize, Ordering)
fn shl_round(self, bits: i16, rm: RoundingMode) -> (usize, Ordering)
Left-shifts a number (multiplies it by a power of 2 or divides it by a power
of 2 and takes the floor) 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
non-negative, then the returned Ordering
is always Equal
, even if the
higher bits of the result are lost.
Passing Floor
or Down
is equivalent to using >>
. To test whether
Exact
can be passed, use bits > 0 || self.divisible_by_power_of_2(bits)
.
Rounding might only be necessary if bits
is negative.
Let $q = x2^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 bits
is positive and rm
is Exact
but self
is not divisible
by $2^b$.
§Examples
See here.
type Output = usize
source§impl ShlRound<i32> for i8
impl ShlRound<i32> for i8
source§fn shl_round(self, bits: i32, rm: RoundingMode) -> (i8, Ordering)
fn shl_round(self, bits: i32, rm: RoundingMode) -> (i8, Ordering)
Left-shifts a number (multiplies it by a power of 2 or divides it by a power
of 2 and takes the floor) 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
non-negative, then the returned Ordering
is always Equal
, even if the
higher bits of the result are lost.
Passing Floor
or Down
is equivalent to using >>
. To test whether
Exact
can be passed, use bits > 0 || self.divisible_by_power_of_2(bits)
.
Rounding might only be necessary if bits
is negative.
Let $q = x2^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 bits
is positive and rm
is Exact
but self
is not divisible
by $2^b$.
§Examples
See here.
type Output = i8
source§impl ShlRound<i32> for i16
impl ShlRound<i32> for i16
source§fn shl_round(self, bits: i32, rm: RoundingMode) -> (i16, Ordering)
fn shl_round(self, bits: i32, rm: RoundingMode) -> (i16, Ordering)
Left-shifts a number (multiplies it by a power of 2 or divides it by a power
of 2 and takes the floor) 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
non-negative, then the returned Ordering
is always Equal
, even if the
higher bits of the result are lost.
Passing Floor
or Down
is equivalent to using >>
. To test whether
Exact
can be passed, use bits > 0 || self.divisible_by_power_of_2(bits)
.
Rounding might only be necessary if bits
is negative.
Let $q = x2^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 bits
is positive and rm
is Exact
but self
is not divisible
by $2^b$.
§Examples
See here.
type Output = i16
source§impl ShlRound<i32> for i32
impl ShlRound<i32> for i32
source§fn shl_round(self, bits: i32, rm: RoundingMode) -> (i32, Ordering)
fn shl_round(self, bits: i32, rm: RoundingMode) -> (i32, Ordering)
Left-shifts a number (multiplies it by a power of 2 or divides it by a power
of 2 and takes the floor) 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
non-negative, then the returned Ordering
is always Equal
, even if the
higher bits of the result are lost.
Passing Floor
or Down
is equivalent to using >>
. To test whether
Exact
can be passed, use bits > 0 || self.divisible_by_power_of_2(bits)
.
Rounding might only be necessary if bits
is negative.
Let $q = x2^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 bits
is positive and rm
is Exact
but self
is not divisible
by $2^b$.
§Examples
See here.
type Output = i32
source§impl ShlRound<i32> for i64
impl ShlRound<i32> for i64
source§fn shl_round(self, bits: i32, rm: RoundingMode) -> (i64, Ordering)
fn shl_round(self, bits: i32, rm: RoundingMode) -> (i64, Ordering)
Left-shifts a number (multiplies it by a power of 2 or divides it by a power
of 2 and takes the floor) 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
non-negative, then the returned Ordering
is always Equal
, even if the
higher bits of the result are lost.
Passing Floor
or Down
is equivalent to using >>
. To test whether
Exact
can be passed, use bits > 0 || self.divisible_by_power_of_2(bits)
.
Rounding might only be necessary if bits
is negative.
Let $q = x2^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 bits
is positive and rm
is Exact
but self
is not divisible
by $2^b$.
§Examples
See here.
type Output = i64
source§impl ShlRound<i32> for i128
impl ShlRound<i32> for i128
source§fn shl_round(self, bits: i32, rm: RoundingMode) -> (i128, Ordering)
fn shl_round(self, bits: i32, rm: RoundingMode) -> (i128, Ordering)
Left-shifts a number (multiplies it by a power of 2 or divides it by a power
of 2 and takes the floor) 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
non-negative, then the returned Ordering
is always Equal
, even if the
higher bits of the result are lost.
Passing Floor
or Down
is equivalent to using >>
. To test whether
Exact
can be passed, use bits > 0 || self.divisible_by_power_of_2(bits)
.
Rounding might only be necessary if bits
is negative.
Let $q = x2^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 bits
is positive and rm
is Exact
but self
is not divisible
by $2^b$.
§Examples
See here.
type Output = i128
source§impl ShlRound<i32> for isize
impl ShlRound<i32> for isize
source§fn shl_round(self, bits: i32, rm: RoundingMode) -> (isize, Ordering)
fn shl_round(self, bits: i32, rm: RoundingMode) -> (isize, Ordering)
Left-shifts a number (multiplies it by a power of 2 or divides it by a power
of 2 and takes the floor) 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
non-negative, then the returned Ordering
is always Equal
, even if the
higher bits of the result are lost.
Passing Floor
or Down
is equivalent to using >>
. To test whether
Exact
can be passed, use bits > 0 || self.divisible_by_power_of_2(bits)
.
Rounding might only be necessary if bits
is negative.
Let $q = x2^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 bits
is positive and rm
is Exact
but self
is not divisible
by $2^b$.
§Examples
See here.
type Output = isize
source§impl ShlRound<i32> for u8
impl ShlRound<i32> for u8
source§fn shl_round(self, bits: i32, rm: RoundingMode) -> (u8, Ordering)
fn shl_round(self, bits: i32, rm: RoundingMode) -> (u8, Ordering)
Left-shifts a number (multiplies it by a power of 2 or divides it by a power
of 2 and takes the floor) 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
non-negative, then the returned Ordering
is always Equal
, even if the
higher bits of the result are lost.
Passing Floor
or Down
is equivalent to using >>
. To test whether
Exact
can be passed, use bits > 0 || self.divisible_by_power_of_2(bits)
.
Rounding might only be necessary if bits
is negative.
Let $q = x2^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 bits
is positive and rm
is Exact
but self
is not divisible
by $2^b$.
§Examples
See here.
type Output = u8
source§impl ShlRound<i32> for u16
impl ShlRound<i32> for u16
source§fn shl_round(self, bits: i32, rm: RoundingMode) -> (u16, Ordering)
fn shl_round(self, bits: i32, rm: RoundingMode) -> (u16, Ordering)
Left-shifts a number (multiplies it by a power of 2 or divides it by a power
of 2 and takes the floor) 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
non-negative, then the returned Ordering
is always Equal
, even if the
higher bits of the result are lost.
Passing Floor
or Down
is equivalent to using >>
. To test whether
Exact
can be passed, use bits > 0 || self.divisible_by_power_of_2(bits)
.
Rounding might only be necessary if bits
is negative.
Let $q = x2^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 bits
is positive and rm
is Exact
but self
is not divisible
by $2^b$.
§Examples
See here.
type Output = u16
source§impl ShlRound<i32> for u32
impl ShlRound<i32> for u32
source§fn shl_round(self, bits: i32, rm: RoundingMode) -> (u32, Ordering)
fn shl_round(self, bits: i32, rm: RoundingMode) -> (u32, Ordering)
Left-shifts a number (multiplies it by a power of 2 or divides it by a power
of 2 and takes the floor) 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
non-negative, then the returned Ordering
is always Equal
, even if the
higher bits of the result are lost.
Passing Floor
or Down
is equivalent to using >>
. To test whether
Exact
can be passed, use bits > 0 || self.divisible_by_power_of_2(bits)
.
Rounding might only be necessary if bits
is negative.
Let $q = x2^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 bits
is positive and rm
is Exact
but self
is not divisible
by $2^b$.
§Examples
See here.
type Output = u32
source§impl ShlRound<i32> for u64
impl ShlRound<i32> for u64
source§fn shl_round(self, bits: i32, rm: RoundingMode) -> (u64, Ordering)
fn shl_round(self, bits: i32, rm: RoundingMode) -> (u64, Ordering)
Left-shifts a number (multiplies it by a power of 2 or divides it by a power
of 2 and takes the floor) 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
non-negative, then the returned Ordering
is always Equal
, even if the
higher bits of the result are lost.
Passing Floor
or Down
is equivalent to using >>
. To test whether
Exact
can be passed, use bits > 0 || self.divisible_by_power_of_2(bits)
.
Rounding might only be necessary if bits
is negative.
Let $q = x2^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 bits
is positive and rm
is Exact
but self
is not divisible
by $2^b$.
§Examples
See here.
type Output = u64
source§impl ShlRound<i32> for u128
impl ShlRound<i32> for u128
source§fn shl_round(self, bits: i32, rm: RoundingMode) -> (u128, Ordering)
fn shl_round(self, bits: i32, rm: RoundingMode) -> (u128, Ordering)
Left-shifts a number (multiplies it by a power of 2 or divides it by a power
of 2 and takes the floor) 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
non-negative, then the returned Ordering
is always Equal
, even if the
higher bits of the result are lost.
Passing Floor
or Down
is equivalent to using >>
. To test whether
Exact
can be passed, use bits > 0 || self.divisible_by_power_of_2(bits)
.
Rounding might only be necessary if bits
is negative.
Let $q = x2^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 bits
is positive and rm
is Exact
but self
is not divisible
by $2^b$.
§Examples
See here.
type Output = u128
source§impl ShlRound<i32> for usize
impl ShlRound<i32> for usize
source§fn shl_round(self, bits: i32, rm: RoundingMode) -> (usize, Ordering)
fn shl_round(self, bits: i32, rm: RoundingMode) -> (usize, Ordering)
Left-shifts a number (multiplies it by a power of 2 or divides it by a power
of 2 and takes the floor) 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
non-negative, then the returned Ordering
is always Equal
, even if the
higher bits of the result are lost.
Passing Floor
or Down
is equivalent to using >>
. To test whether
Exact
can be passed, use bits > 0 || self.divisible_by_power_of_2(bits)
.
Rounding might only be necessary if bits
is negative.
Let $q = x2^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 bits
is positive and rm
is Exact
but self
is not divisible
by $2^b$.
§Examples
See here.
type Output = usize
source§impl ShlRound<i64> for i8
impl ShlRound<i64> for i8
source§fn shl_round(self, bits: i64, rm: RoundingMode) -> (i8, Ordering)
fn shl_round(self, bits: i64, rm: RoundingMode) -> (i8, Ordering)
Left-shifts a number (multiplies it by a power of 2 or divides it by a power
of 2 and takes the floor) 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
non-negative, then the returned Ordering
is always Equal
, even if the
higher bits of the result are lost.
Passing Floor
or Down
is equivalent to using >>
. To test whether
Exact
can be passed, use bits > 0 || self.divisible_by_power_of_2(bits)
.
Rounding might only be necessary if bits
is negative.
Let $q = x2^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 bits
is positive and rm
is Exact
but self
is not divisible
by $2^b$.
§Examples
See here.
type Output = i8
source§impl ShlRound<i64> for i16
impl ShlRound<i64> for i16
source§fn shl_round(self, bits: i64, rm: RoundingMode) -> (i16, Ordering)
fn shl_round(self, bits: i64, rm: RoundingMode) -> (i16, Ordering)
Left-shifts a number (multiplies it by a power of 2 or divides it by a power
of 2 and takes the floor) 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
non-negative, then the returned Ordering
is always Equal
, even if the
higher bits of the result are lost.
Passing Floor
or Down
is equivalent to using >>
. To test whether
Exact
can be passed, use bits > 0 || self.divisible_by_power_of_2(bits)
.
Rounding might only be necessary if bits
is negative.
Let $q = x2^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 bits
is positive and rm
is Exact
but self
is not divisible
by $2^b$.
§Examples
See here.
type Output = i16
source§impl ShlRound<i64> for i32
impl ShlRound<i64> for i32
source§fn shl_round(self, bits: i64, rm: RoundingMode) -> (i32, Ordering)
fn shl_round(self, bits: i64, rm: RoundingMode) -> (i32, Ordering)
Left-shifts a number (multiplies it by a power of 2 or divides it by a power
of 2 and takes the floor) 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
non-negative, then the returned Ordering
is always Equal
, even if the
higher bits of the result are lost.
Passing Floor
or Down
is equivalent to using >>
. To test whether
Exact
can be passed, use bits > 0 || self.divisible_by_power_of_2(bits)
.
Rounding might only be necessary if bits
is negative.
Let $q = x2^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 bits
is positive and rm
is Exact
but self
is not divisible
by $2^b$.
§Examples
See here.
type Output = i32
source§impl ShlRound<i64> for i64
impl ShlRound<i64> for i64
source§fn shl_round(self, bits: i64, rm: RoundingMode) -> (i64, Ordering)
fn shl_round(self, bits: i64, rm: RoundingMode) -> (i64, Ordering)
Left-shifts a number (multiplies it by a power of 2 or divides it by a power
of 2 and takes the floor) 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
non-negative, then the returned Ordering
is always Equal
, even if the
higher bits of the result are lost.
Passing Floor
or Down
is equivalent to using >>
. To test whether
Exact
can be passed, use bits > 0 || self.divisible_by_power_of_2(bits)
.
Rounding might only be necessary if bits
is negative.
Let $q = x2^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 bits
is positive and rm
is Exact
but self
is not divisible
by $2^b$.
§Examples
See here.
type Output = i64
source§impl ShlRound<i64> for i128
impl ShlRound<i64> for i128
source§fn shl_round(self, bits: i64, rm: RoundingMode) -> (i128, Ordering)
fn shl_round(self, bits: i64, rm: RoundingMode) -> (i128, Ordering)
Left-shifts a number (multiplies it by a power of 2 or divides it by a power
of 2 and takes the floor) 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
non-negative, then the returned Ordering
is always Equal
, even if the
higher bits of the result are lost.
Passing Floor
or Down
is equivalent to using >>
. To test whether
Exact
can be passed, use bits > 0 || self.divisible_by_power_of_2(bits)
.
Rounding might only be necessary if bits
is negative.
Let $q = x2^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 bits
is positive and rm
is Exact
but self
is not divisible
by $2^b$.
§Examples
See here.
type Output = i128
source§impl ShlRound<i64> for isize
impl ShlRound<i64> for isize
source§fn shl_round(self, bits: i64, rm: RoundingMode) -> (isize, Ordering)
fn shl_round(self, bits: i64, rm: RoundingMode) -> (isize, Ordering)
Left-shifts a number (multiplies it by a power of 2 or divides it by a power
of 2 and takes the floor) 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
non-negative, then the returned Ordering
is always Equal
, even if the
higher bits of the result are lost.
Passing Floor
or Down
is equivalent to using >>
. To test whether
Exact
can be passed, use bits > 0 || self.divisible_by_power_of_2(bits)
.
Rounding might only be necessary if bits
is negative.
Let $q = x2^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 bits
is positive and rm
is Exact
but self
is not divisible
by $2^b$.
§Examples
See here.
type Output = isize
source§impl ShlRound<i64> for u8
impl ShlRound<i64> for u8
source§fn shl_round(self, bits: i64, rm: RoundingMode) -> (u8, Ordering)
fn shl_round(self, bits: i64, rm: RoundingMode) -> (u8, Ordering)
Left-shifts a number (multiplies it by a power of 2 or divides it by a power
of 2 and takes the floor) 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
non-negative, then the returned Ordering
is always Equal
, even if the
higher bits of the result are lost.
Passing Floor
or Down
is equivalent to using >>
. To test whether
Exact
can be passed, use bits > 0 || self.divisible_by_power_of_2(bits)
.
Rounding might only be necessary if bits
is negative.
Let $q = x2^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 bits
is positive and rm
is Exact
but self
is not divisible
by $2^b$.
§Examples
See here.
type Output = u8
source§impl ShlRound<i64> for u16
impl ShlRound<i64> for u16
source§fn shl_round(self, bits: i64, rm: RoundingMode) -> (u16, Ordering)
fn shl_round(self, bits: i64, rm: RoundingMode) -> (u16, Ordering)
Left-shifts a number (multiplies it by a power of 2 or divides it by a power
of 2 and takes the floor) 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
non-negative, then the returned Ordering
is always Equal
, even if the
higher bits of the result are lost.
Passing Floor
or Down
is equivalent to using >>
. To test whether
Exact
can be passed, use bits > 0 || self.divisible_by_power_of_2(bits)
.
Rounding might only be necessary if bits
is negative.
Let $q = x2^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 bits
is positive and rm
is Exact
but self
is not divisible
by $2^b$.
§Examples
See here.
type Output = u16
source§impl ShlRound<i64> for u32
impl ShlRound<i64> for u32
source§fn shl_round(self, bits: i64, rm: RoundingMode) -> (u32, Ordering)
fn shl_round(self, bits: i64, rm: RoundingMode) -> (u32, Ordering)
Left-shifts a number (multiplies it by a power of 2 or divides it by a power
of 2 and takes the floor) 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
non-negative, then the returned Ordering
is always Equal
, even if the
higher bits of the result are lost.
Passing Floor
or Down
is equivalent to using >>
. To test whether
Exact
can be passed, use bits > 0 || self.divisible_by_power_of_2(bits)
.
Rounding might only be necessary if bits
is negative.
Let $q = x2^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 bits
is positive and rm
is Exact
but self
is not divisible
by $2^b$.
§Examples
See here.
type Output = u32
source§impl ShlRound<i64> for u64
impl ShlRound<i64> for u64
source§fn shl_round(self, bits: i64, rm: RoundingMode) -> (u64, Ordering)
fn shl_round(self, bits: i64, rm: RoundingMode) -> (u64, Ordering)
Left-shifts a number (multiplies it by a power of 2 or divides it by a power
of 2 and takes the floor) 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
non-negative, then the returned Ordering
is always Equal
, even if the
higher bits of the result are lost.
Passing Floor
or Down
is equivalent to using >>
. To test whether
Exact
can be passed, use bits > 0 || self.divisible_by_power_of_2(bits)
.
Rounding might only be necessary if bits
is negative.
Let $q = x2^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 bits
is positive and rm
is Exact
but self
is not divisible
by $2^b$.
§Examples
See here.
type Output = u64
source§impl ShlRound<i64> for u128
impl ShlRound<i64> for u128
source§fn shl_round(self, bits: i64, rm: RoundingMode) -> (u128, Ordering)
fn shl_round(self, bits: i64, rm: RoundingMode) -> (u128, Ordering)
Left-shifts a number (multiplies it by a power of 2 or divides it by a power
of 2 and takes the floor) 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
non-negative, then the returned Ordering
is always Equal
, even if the
higher bits of the result are lost.
Passing Floor
or Down
is equivalent to using >>
. To test whether
Exact
can be passed, use bits > 0 || self.divisible_by_power_of_2(bits)
.
Rounding might only be necessary if bits
is negative.
Let $q = x2^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 bits
is positive and rm
is Exact
but self
is not divisible
by $2^b$.
§Examples
See here.
type Output = u128
source§impl ShlRound<i64> for usize
impl ShlRound<i64> for usize
source§fn shl_round(self, bits: i64, rm: RoundingMode) -> (usize, Ordering)
fn shl_round(self, bits: i64, rm: RoundingMode) -> (usize, Ordering)
Left-shifts a number (multiplies it by a power of 2 or divides it by a power
of 2 and takes the floor) 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
non-negative, then the returned Ordering
is always Equal
, even if the
higher bits of the result are lost.
Passing Floor
or Down
is equivalent to using >>
. To test whether
Exact
can be passed, use bits > 0 || self.divisible_by_power_of_2(bits)
.
Rounding might only be necessary if bits
is negative.
Let $q = x2^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 bits
is positive and rm
is Exact
but self
is not divisible
by $2^b$.
§Examples
See here.
type Output = usize
source§impl ShlRound<i128> for i8
impl ShlRound<i128> for i8
source§fn shl_round(self, bits: i128, rm: RoundingMode) -> (i8, Ordering)
fn shl_round(self, bits: i128, rm: RoundingMode) -> (i8, Ordering)
Left-shifts a number (multiplies it by a power of 2 or divides it by a power
of 2 and takes the floor) 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
non-negative, then the returned Ordering
is always Equal
, even if the
higher bits of the result are lost.
Passing Floor
or Down
is equivalent to using >>
. To test whether
Exact
can be passed, use bits > 0 || self.divisible_by_power_of_2(bits)
.
Rounding might only be necessary if bits
is negative.
Let $q = x2^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 bits
is positive and rm
is Exact
but self
is not divisible
by $2^b$.
§Examples
See here.
type Output = i8
source§impl ShlRound<i128> for i16
impl ShlRound<i128> for i16
source§fn shl_round(self, bits: i128, rm: RoundingMode) -> (i16, Ordering)
fn shl_round(self, bits: i128, rm: RoundingMode) -> (i16, Ordering)
Left-shifts a number (multiplies it by a power of 2 or divides it by a power
of 2 and takes the floor) 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
non-negative, then the returned Ordering
is always Equal
, even if the
higher bits of the result are lost.
Passing Floor
or Down
is equivalent to using >>
. To test whether
Exact
can be passed, use bits > 0 || self.divisible_by_power_of_2(bits)
.
Rounding might only be necessary if bits
is negative.
Let $q = x2^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 bits
is positive and rm
is Exact
but self
is not divisible
by $2^b$.
§Examples
See here.
type Output = i16
source§impl ShlRound<i128> for i32
impl ShlRound<i128> for i32
source§fn shl_round(self, bits: i128, rm: RoundingMode) -> (i32, Ordering)
fn shl_round(self, bits: i128, rm: RoundingMode) -> (i32, Ordering)
Left-shifts a number (multiplies it by a power of 2 or divides it by a power
of 2 and takes the floor) 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
non-negative, then the returned Ordering
is always Equal
, even if the
higher bits of the result are lost.
Passing Floor
or Down
is equivalent to using >>
. To test whether
Exact
can be passed, use bits > 0 || self.divisible_by_power_of_2(bits)
.
Rounding might only be necessary if bits
is negative.
Let $q = x2^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 bits
is positive and rm
is Exact
but self
is not divisible
by $2^b$.
§Examples
See here.
type Output = i32
source§impl ShlRound<i128> for i64
impl ShlRound<i128> for i64
source§fn shl_round(self, bits: i128, rm: RoundingMode) -> (i64, Ordering)
fn shl_round(self, bits: i128, rm: RoundingMode) -> (i64, Ordering)
Left-shifts a number (multiplies it by a power of 2 or divides it by a power
of 2 and takes the floor) 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
non-negative, then the returned Ordering
is always Equal
, even if the
higher bits of the result are lost.
Passing Floor
or Down
is equivalent to using >>
. To test whether
Exact
can be passed, use bits > 0 || self.divisible_by_power_of_2(bits)
.
Rounding might only be necessary if bits
is negative.
Let $q = x2^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 bits
is positive and rm
is Exact
but self
is not divisible
by $2^b$.
§Examples
See here.
type Output = i64
source§impl ShlRound<i128> for i128
impl ShlRound<i128> for i128
source§fn shl_round(self, bits: i128, rm: RoundingMode) -> (i128, Ordering)
fn shl_round(self, bits: i128, rm: RoundingMode) -> (i128, Ordering)
Left-shifts a number (multiplies it by a power of 2 or divides it by a power
of 2 and takes the floor) 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
non-negative, then the returned Ordering
is always Equal
, even if the
higher bits of the result are lost.
Passing Floor
or Down
is equivalent to using >>
. To test whether
Exact
can be passed, use bits > 0 || self.divisible_by_power_of_2(bits)
.
Rounding might only be necessary if bits
is negative.
Let $q = x2^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 bits
is positive and rm
is Exact
but self
is not divisible
by $2^b$.
§Examples
See here.
type Output = i128
source§impl ShlRound<i128> for isize
impl ShlRound<i128> for isize
source§fn shl_round(self, bits: i128, rm: RoundingMode) -> (isize, Ordering)
fn shl_round(self, bits: i128, rm: RoundingMode) -> (isize, Ordering)
Left-shifts a number (multiplies it by a power of 2 or divides it by a power
of 2 and takes the floor) 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
non-negative, then the returned Ordering
is always Equal
, even if the
higher bits of the result are lost.
Passing Floor
or Down
is equivalent to using >>
. To test whether
Exact
can be passed, use bits > 0 || self.divisible_by_power_of_2(bits)
.
Rounding might only be necessary if bits
is negative.
Let $q = x2^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 bits
is positive and rm
is Exact
but self
is not divisible
by $2^b$.
§Examples
See here.
type Output = isize
source§impl ShlRound<i128> for u8
impl ShlRound<i128> for u8
source§fn shl_round(self, bits: i128, rm: RoundingMode) -> (u8, Ordering)
fn shl_round(self, bits: i128, rm: RoundingMode) -> (u8, Ordering)
Left-shifts a number (multiplies it by a power of 2 or divides it by a power
of 2 and takes the floor) 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
non-negative, then the returned Ordering
is always Equal
, even if the
higher bits of the result are lost.
Passing Floor
or Down
is equivalent to using >>
. To test whether
Exact
can be passed, use bits > 0 || self.divisible_by_power_of_2(bits)
.
Rounding might only be necessary if bits
is negative.
Let $q = x2^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 bits
is positive and rm
is Exact
but self
is not divisible
by $2^b$.
§Examples
See here.
type Output = u8
source§impl ShlRound<i128> for u16
impl ShlRound<i128> for u16
source§fn shl_round(self, bits: i128, rm: RoundingMode) -> (u16, Ordering)
fn shl_round(self, bits: i128, rm: RoundingMode) -> (u16, Ordering)
Left-shifts a number (multiplies it by a power of 2 or divides it by a power
of 2 and takes the floor) 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
non-negative, then the returned Ordering
is always Equal
, even if the
higher bits of the result are lost.
Passing Floor
or Down
is equivalent to using >>
. To test whether
Exact
can be passed, use bits > 0 || self.divisible_by_power_of_2(bits)
.
Rounding might only be necessary if bits
is negative.
Let $q = x2^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 bits
is positive and rm
is Exact
but self
is not divisible
by $2^b$.
§Examples
See here.
type Output = u16
source§impl ShlRound<i128> for u32
impl ShlRound<i128> for u32
source§fn shl_round(self, bits: i128, rm: RoundingMode) -> (u32, Ordering)
fn shl_round(self, bits: i128, rm: RoundingMode) -> (u32, Ordering)
Left-shifts a number (multiplies it by a power of 2 or divides it by a power
of 2 and takes the floor) 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
non-negative, then the returned Ordering
is always Equal
, even if the
higher bits of the result are lost.
Passing Floor
or Down
is equivalent to using >>
. To test whether
Exact
can be passed, use bits > 0 || self.divisible_by_power_of_2(bits)
.
Rounding might only be necessary if bits
is negative.
Let $q = x2^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 bits
is positive and rm
is Exact
but self
is not divisible
by $2^b$.
§Examples
See here.
type Output = u32
source§impl ShlRound<i128> for u64
impl ShlRound<i128> for u64
source§fn shl_round(self, bits: i128, rm: RoundingMode) -> (u64, Ordering)
fn shl_round(self, bits: i128, rm: RoundingMode) -> (u64, Ordering)
Left-shifts a number (multiplies it by a power of 2 or divides it by a power
of 2 and takes the floor) 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
non-negative, then the returned Ordering
is always Equal
, even if the
higher bits of the result are lost.
Passing Floor
or Down
is equivalent to using >>
. To test whether
Exact
can be passed, use bits > 0 || self.divisible_by_power_of_2(bits)
.
Rounding might only be necessary if bits
is negative.
Let $q = x2^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 bits
is positive and rm
is Exact
but self
is not divisible
by $2^b$.
§Examples
See here.
type Output = u64
source§impl ShlRound<i128> for u128
impl ShlRound<i128> for u128
source§fn shl_round(self, bits: i128, rm: RoundingMode) -> (u128, Ordering)
fn shl_round(self, bits: i128, rm: RoundingMode) -> (u128, Ordering)
Left-shifts a number (multiplies it by a power of 2 or divides it by a power
of 2 and takes the floor) 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
non-negative, then the returned Ordering
is always Equal
, even if the
higher bits of the result are lost.
Passing Floor
or Down
is equivalent to using >>
. To test whether
Exact
can be passed, use bits > 0 || self.divisible_by_power_of_2(bits)
.
Rounding might only be necessary if bits
is negative.
Let $q = x2^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 bits
is positive and rm
is Exact
but self
is not divisible
by $2^b$.
§Examples
See here.
type Output = u128
source§impl ShlRound<i128> for usize
impl ShlRound<i128> for usize
source§fn shl_round(self, bits: i128, rm: RoundingMode) -> (usize, Ordering)
fn shl_round(self, bits: i128, rm: RoundingMode) -> (usize, Ordering)
Left-shifts a number (multiplies it by a power of 2 or divides it by a power
of 2 and takes the floor) 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
non-negative, then the returned Ordering
is always Equal
, even if the
higher bits of the result are lost.
Passing Floor
or Down
is equivalent to using >>
. To test whether
Exact
can be passed, use bits > 0 || self.divisible_by_power_of_2(bits)
.
Rounding might only be necessary if bits
is negative.
Let $q = x2^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 bits
is positive and rm
is Exact
but self
is not divisible
by $2^b$.
§Examples
See here.
type Output = usize
source§impl ShlRound<isize> for i8
impl ShlRound<isize> for i8
source§fn shl_round(self, bits: isize, rm: RoundingMode) -> (i8, Ordering)
fn shl_round(self, bits: isize, rm: RoundingMode) -> (i8, Ordering)
Left-shifts a number (multiplies it by a power of 2 or divides it by a power
of 2 and takes the floor) 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
non-negative, then the returned Ordering
is always Equal
, even if the
higher bits of the result are lost.
Passing Floor
or Down
is equivalent to using >>
. To test whether
Exact
can be passed, use bits > 0 || self.divisible_by_power_of_2(bits)
.
Rounding might only be necessary if bits
is negative.
Let $q = x2^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 bits
is positive and rm
is Exact
but self
is not divisible
by $2^b$.
§Examples
See here.
type Output = i8
source§impl ShlRound<isize> for i16
impl ShlRound<isize> for i16
source§fn shl_round(self, bits: isize, rm: RoundingMode) -> (i16, Ordering)
fn shl_round(self, bits: isize, rm: RoundingMode) -> (i16, Ordering)
Left-shifts a number (multiplies it by a power of 2 or divides it by a power
of 2 and takes the floor) 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
non-negative, then the returned Ordering
is always Equal
, even if the
higher bits of the result are lost.
Passing Floor
or Down
is equivalent to using >>
. To test whether
Exact
can be passed, use bits > 0 || self.divisible_by_power_of_2(bits)
.
Rounding might only be necessary if bits
is negative.
Let $q = x2^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 bits
is positive and rm
is Exact
but self
is not divisible
by $2^b$.
§Examples
See here.
type Output = i16
source§impl ShlRound<isize> for i32
impl ShlRound<isize> for i32
source§fn shl_round(self, bits: isize, rm: RoundingMode) -> (i32, Ordering)
fn shl_round(self, bits: isize, rm: RoundingMode) -> (i32, Ordering)
Left-shifts a number (multiplies it by a power of 2 or divides it by a power
of 2 and takes the floor) 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
non-negative, then the returned Ordering
is always Equal
, even if the
higher bits of the result are lost.
Passing Floor
or Down
is equivalent to using >>
. To test whether
Exact
can be passed, use bits > 0 || self.divisible_by_power_of_2(bits)
.
Rounding might only be necessary if bits
is negative.
Let $q = x2^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 bits
is positive and rm
is Exact
but self
is not divisible
by $2^b$.
§Examples
See here.
type Output = i32
source§impl ShlRound<isize> for i64
impl ShlRound<isize> for i64
source§fn shl_round(self, bits: isize, rm: RoundingMode) -> (i64, Ordering)
fn shl_round(self, bits: isize, rm: RoundingMode) -> (i64, Ordering)
Left-shifts a number (multiplies it by a power of 2 or divides it by a power
of 2 and takes the floor) 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
non-negative, then the returned Ordering
is always Equal
, even if the
higher bits of the result are lost.
Passing Floor
or Down
is equivalent to using >>
. To test whether
Exact
can be passed, use bits > 0 || self.divisible_by_power_of_2(bits)
.
Rounding might only be necessary if bits
is negative.
Let $q = x2^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 bits
is positive and rm
is Exact
but self
is not divisible
by $2^b$.
§Examples
See here.
type Output = i64
source§impl ShlRound<isize> for i128
impl ShlRound<isize> for i128
source§fn shl_round(self, bits: isize, rm: RoundingMode) -> (i128, Ordering)
fn shl_round(self, bits: isize, rm: RoundingMode) -> (i128, Ordering)
Left-shifts a number (multiplies it by a power of 2 or divides it by a power
of 2 and takes the floor) 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
non-negative, then the returned Ordering
is always Equal
, even if the
higher bits of the result are lost.
Passing Floor
or Down
is equivalent to using >>
. To test whether
Exact
can be passed, use bits > 0 || self.divisible_by_power_of_2(bits)
.
Rounding might only be necessary if bits
is negative.
Let $q = x2^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 bits
is positive and rm
is Exact
but self
is not divisible
by $2^b$.
§Examples
See here.
type Output = i128
source§impl ShlRound<isize> for isize
impl ShlRound<isize> for isize
source§fn shl_round(self, bits: isize, rm: RoundingMode) -> (isize, Ordering)
fn shl_round(self, bits: isize, rm: RoundingMode) -> (isize, Ordering)
Left-shifts a number (multiplies it by a power of 2 or divides it by a power
of 2 and takes the floor) 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
non-negative, then the returned Ordering
is always Equal
, even if the
higher bits of the result are lost.
Passing Floor
or Down
is equivalent to using >>
. To test whether
Exact
can be passed, use bits > 0 || self.divisible_by_power_of_2(bits)
.
Rounding might only be necessary if bits
is negative.
Let $q = x2^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 bits
is positive and rm
is Exact
but self
is not divisible
by $2^b$.
§Examples
See here.
type Output = isize
source§impl ShlRound<isize> for u8
impl ShlRound<isize> for u8
source§fn shl_round(self, bits: isize, rm: RoundingMode) -> (u8, Ordering)
fn shl_round(self, bits: isize, rm: RoundingMode) -> (u8, Ordering)
Left-shifts a number (multiplies it by a power of 2 or divides it by a power
of 2 and takes the floor) 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
non-negative, then the returned Ordering
is always Equal
, even if the
higher bits of the result are lost.
Passing Floor
or Down
is equivalent to using >>
. To test whether
Exact
can be passed, use bits > 0 || self.divisible_by_power_of_2(bits)
.
Rounding might only be necessary if bits
is negative.
Let $q = x2^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 bits
is positive and rm
is Exact
but self
is not divisible
by $2^b$.
§Examples
See here.
type Output = u8
source§impl ShlRound<isize> for u16
impl ShlRound<isize> for u16
source§fn shl_round(self, bits: isize, rm: RoundingMode) -> (u16, Ordering)
fn shl_round(self, bits: isize, rm: RoundingMode) -> (u16, Ordering)
Left-shifts a number (multiplies it by a power of 2 or divides it by a power
of 2 and takes the floor) 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
non-negative, then the returned Ordering
is always Equal
, even if the
higher bits of the result are lost.
Passing Floor
or Down
is equivalent to using >>
. To test whether
Exact
can be passed, use bits > 0 || self.divisible_by_power_of_2(bits)
.
Rounding might only be necessary if bits
is negative.
Let $q = x2^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 bits
is positive and rm
is Exact
but self
is not divisible
by $2^b$.
§Examples
See here.
type Output = u16
source§impl ShlRound<isize> for u32
impl ShlRound<isize> for u32
source§fn shl_round(self, bits: isize, rm: RoundingMode) -> (u32, Ordering)
fn shl_round(self, bits: isize, rm: RoundingMode) -> (u32, Ordering)
Left-shifts a number (multiplies it by a power of 2 or divides it by a power
of 2 and takes the floor) 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
non-negative, then the returned Ordering
is always Equal
, even if the
higher bits of the result are lost.
Passing Floor
or Down
is equivalent to using >>
. To test whether
Exact
can be passed, use bits > 0 || self.divisible_by_power_of_2(bits)
.
Rounding might only be necessary if bits
is negative.
Let $q = x2^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 bits
is positive and rm
is Exact
but self
is not divisible
by $2^b$.
§Examples
See here.
type Output = u32
source§impl ShlRound<isize> for u64
impl ShlRound<isize> for u64
source§fn shl_round(self, bits: isize, rm: RoundingMode) -> (u64, Ordering)
fn shl_round(self, bits: isize, rm: RoundingMode) -> (u64, Ordering)
Left-shifts a number (multiplies it by a power of 2 or divides it by a power
of 2 and takes the floor) 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
non-negative, then the returned Ordering
is always Equal
, even if the
higher bits of the result are lost.
Passing Floor
or Down
is equivalent to using >>
. To test whether
Exact
can be passed, use bits > 0 || self.divisible_by_power_of_2(bits)
.
Rounding might only be necessary if bits
is negative.
Let $q = x2^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 bits
is positive and rm
is Exact
but self
is not divisible
by $2^b$.
§Examples
See here.
type Output = u64
source§impl ShlRound<isize> for u128
impl ShlRound<isize> for u128
source§fn shl_round(self, bits: isize, rm: RoundingMode) -> (u128, Ordering)
fn shl_round(self, bits: isize, rm: RoundingMode) -> (u128, Ordering)
Left-shifts a number (multiplies it by a power of 2 or divides it by a power
of 2 and takes the floor) 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
non-negative, then the returned Ordering
is always Equal
, even if the
higher bits of the result are lost.
Passing Floor
or Down
is equivalent to using >>
. To test whether
Exact
can be passed, use bits > 0 || self.divisible_by_power_of_2(bits)
.
Rounding might only be necessary if bits
is negative.
Let $q = x2^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 bits
is positive and rm
is Exact
but self
is not divisible
by $2^b$.
§Examples
See here.
type Output = u128
source§impl ShlRound<isize> for usize
impl ShlRound<isize> for usize
source§fn shl_round(self, bits: isize, rm: RoundingMode) -> (usize, Ordering)
fn shl_round(self, bits: isize, rm: RoundingMode) -> (usize, Ordering)
Left-shifts a number (multiplies it by a power of 2 or divides it by a power
of 2 and takes the floor) 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
non-negative, then the returned Ordering
is always Equal
, even if the
higher bits of the result are lost.
Passing Floor
or Down
is equivalent to using >>
. To test whether
Exact
can be passed, use bits > 0 || self.divisible_by_power_of_2(bits)
.
Rounding might only be necessary if bits
is negative.
Let $q = x2^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 bits
is positive and rm
is Exact
but self
is not divisible
by $2^b$.
§Examples
See here.