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