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

Implementations on Foreign Types

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

Implementors