pub trait ShrRound<RHS> {
    type Output;

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

Right-shifts a number (divides it by a power of 2), rounding the result according to a specified rounding mode.

Rounding might only be necessary if other is positive.

Required Associated Types

Required Methods

Implementations on Foreign Types

Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode.

Passing RoundingMode::Floor or RoundingMode::Down is equivalent to using >>. To test whether RoundingMode::Exact can be passed, use self.divisible_by_power_of_2(bits).

Let $q = \frac{x}{2^k}$:

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

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

$$ f(x, k, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd}. \end{cases} $$

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

Worst-case complexity

Constant time and additional memory.

Panics

Panics if rm is RoundingMode::Exact but self is not divisible by $2^b$.

Examples

See here.

Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode.

Passing RoundingMode::Floor or RoundingMode::Down is equivalent to using >>. To test whether RoundingMode::Exact can be passed, use self.divisible_by_power_of_2(bits).

Let $q = \frac{x}{2^k}$:

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

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

$$ f(x, k, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd}. \end{cases} $$

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

Worst-case complexity

Constant time and additional memory.

Panics

Panics if rm is RoundingMode::Exact but self is not divisible by $2^b$.

Examples

See here.

Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode.

Passing RoundingMode::Floor or RoundingMode::Down is equivalent to using >>. To test whether RoundingMode::Exact can be passed, use self.divisible_by_power_of_2(bits).

Let $q = \frac{x}{2^k}$:

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

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

$$ f(x, k, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd}. \end{cases} $$

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

Worst-case complexity

Constant time and additional memory.

Panics

Panics if rm is RoundingMode::Exact but self is not divisible by $2^b$.

Examples

See here.

Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode.

Passing RoundingMode::Floor or RoundingMode::Down is equivalent to using >>. To test whether RoundingMode::Exact can be passed, use self.divisible_by_power_of_2(bits).

Let $q = \frac{x}{2^k}$:

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

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

$$ f(x, k, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd}. \end{cases} $$

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

Worst-case complexity

Constant time and additional memory.

Panics

Panics if rm is RoundingMode::Exact but self is not divisible by $2^b$.

Examples

See here.

Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode.

Passing RoundingMode::Floor or RoundingMode::Down is equivalent to using >>. To test whether RoundingMode::Exact can be passed, use self.divisible_by_power_of_2(bits).

Let $q = \frac{x}{2^k}$:

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

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

$$ f(x, k, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd}. \end{cases} $$

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

Worst-case complexity

Constant time and additional memory.

Panics

Panics if rm is RoundingMode::Exact but self is not divisible by $2^b$.

Examples

See here.

Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode.

Passing RoundingMode::Floor or RoundingMode::Down is equivalent to using >>. To test whether RoundingMode::Exact can be passed, use self.divisible_by_power_of_2(bits).

Let $q = \frac{x}{2^k}$:

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

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

$$ f(x, k, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd}. \end{cases} $$

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

Worst-case complexity

Constant time and additional memory.

Panics

Panics if rm is RoundingMode::Exact but self is not divisible by $2^b$.

Examples

See here.

Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode.

Passing RoundingMode::Floor or RoundingMode::Down is equivalent to using >>. To test whether RoundingMode::Exact can be passed, use self.divisible_by_power_of_2(bits).

Let $q = \frac{x}{2^k}$:

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

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

$$ f(x, k, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd}. \end{cases} $$

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

Worst-case complexity

Constant time and additional memory.

Panics

Panics if rm is RoundingMode::Exact but self is not divisible by $2^b$.

Examples

See here.

Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode.

Passing RoundingMode::Floor or RoundingMode::Down is equivalent to using >>. To test whether RoundingMode::Exact can be passed, use self.divisible_by_power_of_2(bits).

Let $q = \frac{x}{2^k}$:

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

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

$$ f(x, k, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd}. \end{cases} $$

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

Worst-case complexity

Constant time and additional memory.

Panics

Panics if rm is RoundingMode::Exact but self is not divisible by $2^b$.

Examples

See here.

Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode.

Passing RoundingMode::Floor or RoundingMode::Down is equivalent to using >>. To test whether RoundingMode::Exact can be passed, use self.divisible_by_power_of_2(bits).

Let $q = \frac{x}{2^k}$:

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

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

$$ f(x, k, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd}. \end{cases} $$

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

Worst-case complexity

Constant time and additional memory.

Panics

Panics if rm is RoundingMode::Exact but self is not divisible by $2^b$.

Examples

See here.

Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode.

Passing RoundingMode::Floor or RoundingMode::Down is equivalent to using >>. To test whether RoundingMode::Exact can be passed, use self.divisible_by_power_of_2(bits).

Let $q = \frac{x}{2^k}$:

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

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

$$ f(x, k, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd}. \end{cases} $$

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

Worst-case complexity

Constant time and additional memory.

Panics

Panics if rm is RoundingMode::Exact but self is not divisible by $2^b$.

Examples

See here.

Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode.

Passing RoundingMode::Floor or RoundingMode::Down is equivalent to using >>. To test whether RoundingMode::Exact can be passed, use self.divisible_by_power_of_2(bits).

Let $q = \frac{x}{2^k}$:

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

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

$$ f(x, k, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd}. \end{cases} $$

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

Worst-case complexity

Constant time and additional memory.

Panics

Panics if rm is RoundingMode::Exact but self is not divisible by $2^b$.

Examples

See here.

Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode.

Passing RoundingMode::Floor or RoundingMode::Down is equivalent to using >>. To test whether RoundingMode::Exact can be passed, use self.divisible_by_power_of_2(bits).

Let $q = \frac{x}{2^k}$:

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

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

$$ f(x, k, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd}. \end{cases} $$

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

Worst-case complexity

Constant time and additional memory.

Panics

Panics if rm is RoundingMode::Exact but self is not divisible by $2^b$.

Examples

See here.

Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode.

Passing RoundingMode::Floor or RoundingMode::Down is equivalent to using >>. To test whether RoundingMode::Exact can be passed, use self.divisible_by_power_of_2(bits).

Let $q = \frac{x}{2^k}$:

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

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

$$ f(x, k, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd}. \end{cases} $$

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

Worst-case complexity

Constant time and additional memory.

Panics

Panics if rm is RoundingMode::Exact but self is not divisible by $2^b$.

Examples

See here.

Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode.

Passing RoundingMode::Floor or RoundingMode::Down is equivalent to using >>. To test whether RoundingMode::Exact can be passed, use self.divisible_by_power_of_2(bits).

Let $q = \frac{x}{2^k}$:

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

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

$$ f(x, k, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd}. \end{cases} $$

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

Worst-case complexity

Constant time and additional memory.

Panics

Panics if rm is RoundingMode::Exact but self is not divisible by $2^b$.

Examples

See here.

Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode.

Passing RoundingMode::Floor or RoundingMode::Down is equivalent to using >>. To test whether RoundingMode::Exact can be passed, use self.divisible_by_power_of_2(bits).

Let $q = \frac{x}{2^k}$:

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

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

$$ f(x, k, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd}. \end{cases} $$

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

Worst-case complexity

Constant time and additional memory.

Panics

Panics if rm is RoundingMode::Exact but self is not divisible by $2^b$.

Examples

See here.

Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode.

Passing RoundingMode::Floor or RoundingMode::Down is equivalent to using >>. To test whether RoundingMode::Exact can be passed, use self.divisible_by_power_of_2(bits).

Let $q = \frac{x}{2^k}$:

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

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

$$ f(x, k, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd}. \end{cases} $$

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

Worst-case complexity

Constant time and additional memory.

Panics

Panics if rm is RoundingMode::Exact but self is not divisible by $2^b$.

Examples

See here.

Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode.

Passing RoundingMode::Floor or RoundingMode::Down is equivalent to using >>. To test whether RoundingMode::Exact can be passed, use self.divisible_by_power_of_2(bits).

Let $q = \frac{x}{2^k}$:

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

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

$$ f(x, k, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd}. \end{cases} $$

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

Worst-case complexity

Constant time and additional memory.

Panics

Panics if rm is RoundingMode::Exact but self is not divisible by $2^b$.

Examples

See here.

Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode.

Passing RoundingMode::Floor or RoundingMode::Down is equivalent to using >>. To test whether RoundingMode::Exact can be passed, use self.divisible_by_power_of_2(bits).

Let $q = \frac{x}{2^k}$:

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

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

$$ f(x, k, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd}. \end{cases} $$

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

Worst-case complexity

Constant time and additional memory.

Panics

Panics if rm is RoundingMode::Exact but self is not divisible by $2^b$.

Examples

See here.

Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode.

Passing RoundingMode::Floor or RoundingMode::Down is equivalent to using >>. To test whether RoundingMode::Exact can be passed, use self.divisible_by_power_of_2(bits).

Let $q = \frac{x}{2^k}$:

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

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

$$ f(x, k, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd}. \end{cases} $$

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

Worst-case complexity

Constant time and additional memory.

Panics

Panics if rm is RoundingMode::Exact but self is not divisible by $2^b$.

Examples

See here.

Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode.

Passing RoundingMode::Floor or RoundingMode::Down is equivalent to using >>. To test whether RoundingMode::Exact can be passed, use self.divisible_by_power_of_2(bits).

Let $q = \frac{x}{2^k}$:

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

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

$$ f(x, k, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd}. \end{cases} $$

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

Worst-case complexity

Constant time and additional memory.

Panics

Panics if rm is RoundingMode::Exact but self is not divisible by $2^b$.

Examples

See here.

Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode.

Passing RoundingMode::Floor or RoundingMode::Down is equivalent to using >>. To test whether RoundingMode::Exact can be passed, use self.divisible_by_power_of_2(bits).

Let $q = \frac{x}{2^k}$:

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

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

$$ f(x, k, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd}. \end{cases} $$

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

Worst-case complexity

Constant time and additional memory.

Panics

Panics if rm is RoundingMode::Exact but self is not divisible by $2^b$.

Examples

See here.

Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode.

Passing RoundingMode::Floor or RoundingMode::Down is equivalent to using >>. To test whether RoundingMode::Exact can be passed, use self.divisible_by_power_of_2(bits).

Let $q = \frac{x}{2^k}$:

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

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

$$ f(x, k, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd}. \end{cases} $$

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

Worst-case complexity

Constant time and additional memory.

Panics

Panics if rm is RoundingMode::Exact but self is not divisible by $2^b$.

Examples

See here.

Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode.

Passing RoundingMode::Floor or RoundingMode::Down is equivalent to using >>. To test whether RoundingMode::Exact can be passed, use self.divisible_by_power_of_2(bits).

Let $q = \frac{x}{2^k}$:

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

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

$$ f(x, k, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd}. \end{cases} $$

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

Worst-case complexity

Constant time and additional memory.

Panics

Panics if rm is RoundingMode::Exact but self is not divisible by $2^b$.

Examples

See here.

Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode.

Passing RoundingMode::Floor or RoundingMode::Down is equivalent to using >>. To test whether RoundingMode::Exact can be passed, use self.divisible_by_power_of_2(bits).

Let $q = \frac{x}{2^k}$:

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

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

$$ f(x, k, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd}. \end{cases} $$

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

Worst-case complexity

Constant time and additional memory.

Panics

Panics if rm is RoundingMode::Exact but self is not divisible by $2^b$.

Examples

See here.

Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode.

Passing RoundingMode::Floor or RoundingMode::Down is equivalent to using >>. To test whether RoundingMode::Exact can be passed, use self.divisible_by_power_of_2(bits).

Let $q = \frac{x}{2^k}$:

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

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

$$ f(x, k, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd}. \end{cases} $$

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

Worst-case complexity

Constant time and additional memory.

Panics

Panics if rm is RoundingMode::Exact but self is not divisible by $2^b$.

Examples

See here.

Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode.

Passing RoundingMode::Floor or RoundingMode::Down is equivalent to using >>. To test whether RoundingMode::Exact can be passed, use self.divisible_by_power_of_2(bits).

Let $q = \frac{x}{2^k}$:

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

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

$$ f(x, k, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd}. \end{cases} $$

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

Worst-case complexity

Constant time and additional memory.

Panics

Panics if rm is RoundingMode::Exact but self is not divisible by $2^b$.

Examples

See here.

Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode.

Passing RoundingMode::Floor or RoundingMode::Down is equivalent to using >>. To test whether RoundingMode::Exact can be passed, use self.divisible_by_power_of_2(bits).

Let $q = \frac{x}{2^k}$:

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

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

$$ f(x, k, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd}. \end{cases} $$

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

Worst-case complexity

Constant time and additional memory.

Panics

Panics if rm is RoundingMode::Exact but self is not divisible by $2^b$.

Examples

See here.

Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode.

Passing RoundingMode::Floor or RoundingMode::Down is equivalent to using >>. To test whether RoundingMode::Exact can be passed, use self.divisible_by_power_of_2(bits).

Let $q = \frac{x}{2^k}$:

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

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

$$ f(x, k, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd}. \end{cases} $$

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

Worst-case complexity

Constant time and additional memory.

Panics

Panics if rm is RoundingMode::Exact but self is not divisible by $2^b$.

Examples

See here.

Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode.

Passing RoundingMode::Floor or RoundingMode::Down is equivalent to using >>. To test whether RoundingMode::Exact can be passed, use self.divisible_by_power_of_2(bits).

Let $q = \frac{x}{2^k}$:

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

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

$$ f(x, k, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd}. \end{cases} $$

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

Worst-case complexity

Constant time and additional memory.

Panics

Panics if rm is RoundingMode::Exact but self is not divisible by $2^b$.

Examples

See here.

Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode.

Passing RoundingMode::Floor or RoundingMode::Down is equivalent to using >>. To test whether RoundingMode::Exact can be passed, use self.divisible_by_power_of_2(bits).

Let $q = \frac{x}{2^k}$:

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

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

$$ f(x, k, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd}. \end{cases} $$

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

Worst-case complexity

Constant time and additional memory.

Panics

Panics if rm is RoundingMode::Exact but self is not divisible by $2^b$.

Examples

See here.

Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode.

Passing RoundingMode::Floor or RoundingMode::Down is equivalent to using >>. To test whether RoundingMode::Exact can be passed, use self.divisible_by_power_of_2(bits).

Let $q = \frac{x}{2^k}$:

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

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

$$ f(x, k, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd}. \end{cases} $$

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

Worst-case complexity

Constant time and additional memory.

Panics

Panics if rm is RoundingMode::Exact but self is not divisible by $2^b$.

Examples

See here.

Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode.

Passing RoundingMode::Floor or RoundingMode::Down is equivalent to using >>. To test whether RoundingMode::Exact can be passed, use self.divisible_by_power_of_2(bits).

Let $q = \frac{x}{2^k}$:

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

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

$$ f(x, k, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd}. \end{cases} $$

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

Worst-case complexity

Constant time and additional memory.

Panics

Panics if rm is RoundingMode::Exact but self is not divisible by $2^b$.

Examples

See here.

Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode.

Passing RoundingMode::Floor or RoundingMode::Down is equivalent to using >>. To test whether RoundingMode::Exact can be passed, use self.divisible_by_power_of_2(bits).

Let $q = \frac{x}{2^k}$:

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

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

$$ f(x, k, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd}. \end{cases} $$

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

Worst-case complexity

Constant time and additional memory.

Panics

Panics if rm is RoundingMode::Exact but self is not divisible by $2^b$.

Examples

See here.

Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode.

Passing RoundingMode::Floor or RoundingMode::Down is equivalent to using >>. To test whether RoundingMode::Exact can be passed, use self.divisible_by_power_of_2(bits).

Let $q = \frac{x}{2^k}$:

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

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

$$ f(x, k, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd}. \end{cases} $$

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

Worst-case complexity

Constant time and additional memory.

Panics

Panics if rm is RoundingMode::Exact but self is not divisible by $2^b$.

Examples

See here.

Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode.

Passing RoundingMode::Floor or RoundingMode::Down is equivalent to using >>. To test whether RoundingMode::Exact can be passed, use self.divisible_by_power_of_2(bits).

Let $q = \frac{x}{2^k}$:

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

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

$$ f(x, k, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd}. \end{cases} $$

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

Worst-case complexity

Constant time and additional memory.

Panics

Panics if rm is RoundingMode::Exact but self is not divisible by $2^b$.

Examples

See here.

Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode.

Passing RoundingMode::Floor or RoundingMode::Down is equivalent to using >>. To test whether RoundingMode::Exact can be passed, use self.divisible_by_power_of_2(bits).

Let $q = \frac{x}{2^k}$:

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

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

$$ f(x, k, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd}. \end{cases} $$

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

Worst-case complexity

Constant time and additional memory.

Panics

Panics if rm is RoundingMode::Exact but self is not divisible by $2^b$.

Examples

See here.

Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode.

Passing RoundingMode::Floor or RoundingMode::Down is equivalent to using >>. To test whether RoundingMode::Exact can be passed, use self.divisible_by_power_of_2(bits).

Let $q = \frac{x}{2^p}$:

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

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

$$ f(x, p, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd}. \end{cases} $$

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

Worst-case complexity

Constant time and additional memory.

Panics

Panics if rm is RoundingMode::Exact but self is not divisible by $2^b$.

Examples

See here.

Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode.

Passing RoundingMode::Floor or RoundingMode::Down is equivalent to using >>. To test whether RoundingMode::Exact can be passed, use self.divisible_by_power_of_2(bits).

Let $q = \frac{x}{2^p}$:

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

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

$$ f(x, p, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd}. \end{cases} $$

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

Worst-case complexity

Constant time and additional memory.

Panics

Panics if rm is RoundingMode::Exact but self is not divisible by $2^b$.

Examples

See here.

Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode.

Passing RoundingMode::Floor or RoundingMode::Down is equivalent to using >>. To test whether RoundingMode::Exact can be passed, use self.divisible_by_power_of_2(bits).

Let $q = \frac{x}{2^p}$:

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

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

$$ f(x, p, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd}. \end{cases} $$

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

Worst-case complexity

Constant time and additional memory.

Panics

Panics if rm is RoundingMode::Exact but self is not divisible by $2^b$.

Examples

See here.

Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode.

Passing RoundingMode::Floor or RoundingMode::Down is equivalent to using >>. To test whether RoundingMode::Exact can be passed, use self.divisible_by_power_of_2(bits).

Let $q = \frac{x}{2^p}$:

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

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

$$ f(x, p, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd}. \end{cases} $$

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

Worst-case complexity

Constant time and additional memory.

Panics

Panics if rm is RoundingMode::Exact but self is not divisible by $2^b$.

Examples

See here.

Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode.

Passing RoundingMode::Floor or RoundingMode::Down is equivalent to using >>. To test whether RoundingMode::Exact can be passed, use self.divisible_by_power_of_2(bits).

Let $q = \frac{x}{2^p}$:

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

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

$$ f(x, p, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd}. \end{cases} $$

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

Worst-case complexity

Constant time and additional memory.

Panics

Panics if rm is RoundingMode::Exact but self is not divisible by $2^b$.

Examples

See here.

Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode.

Passing RoundingMode::Floor or RoundingMode::Down is equivalent to using >>. To test whether RoundingMode::Exact can be passed, use self.divisible_by_power_of_2(bits).

Let $q = \frac{x}{2^p}$:

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

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

$$ f(x, p, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd}. \end{cases} $$

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

Worst-case complexity

Constant time and additional memory.

Panics

Panics if rm is RoundingMode::Exact but self is not divisible by $2^b$.

Examples

See here.

Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode.

Passing RoundingMode::Floor or RoundingMode::Down is equivalent to using >>. To test whether RoundingMode::Exact can be passed, use self.divisible_by_power_of_2(bits).

Let $q = \frac{x}{2^p}$:

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

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

$$ f(x, p, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd}. \end{cases} $$

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

Worst-case complexity

Constant time and additional memory.

Panics

Panics if rm is RoundingMode::Exact but self is not divisible by $2^b$.

Examples

See here.

Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode.

Passing RoundingMode::Floor or RoundingMode::Down is equivalent to using >>. To test whether RoundingMode::Exact can be passed, use self.divisible_by_power_of_2(bits).

Let $q = \frac{x}{2^p}$:

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

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

$$ f(x, p, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd}. \end{cases} $$

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

Worst-case complexity

Constant time and additional memory.

Panics

Panics if rm is RoundingMode::Exact but self is not divisible by $2^b$.

Examples

See here.

Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode.

Passing RoundingMode::Floor or RoundingMode::Down is equivalent to using >>. To test whether RoundingMode::Exact can be passed, use self.divisible_by_power_of_2(bits).

Let $q = \frac{x}{2^p}$:

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

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

$$ f(x, p, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd}. \end{cases} $$

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

Worst-case complexity

Constant time and additional memory.

Panics

Panics if rm is RoundingMode::Exact but self is not divisible by $2^b$.

Examples

See here.

Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode.

Passing RoundingMode::Floor or RoundingMode::Down is equivalent to using >>. To test whether RoundingMode::Exact can be passed, use self.divisible_by_power_of_2(bits).

Let $q = \frac{x}{2^p}$:

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

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

$$ f(x, p, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd}. \end{cases} $$

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

Worst-case complexity

Constant time and additional memory.

Panics

Panics if rm is RoundingMode::Exact but self is not divisible by $2^b$.

Examples

See here.

Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode.

Passing RoundingMode::Floor or RoundingMode::Down is equivalent to using >>. To test whether RoundingMode::Exact can be passed, use self.divisible_by_power_of_2(bits).

Let $q = \frac{x}{2^p}$:

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

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

$$ f(x, p, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd}. \end{cases} $$

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

Worst-case complexity

Constant time and additional memory.

Panics

Panics if rm is RoundingMode::Exact but self is not divisible by $2^b$.

Examples

See here.

Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode.

Passing RoundingMode::Floor or RoundingMode::Down is equivalent to using >>. To test whether RoundingMode::Exact can be passed, use self.divisible_by_power_of_2(bits).

Let $q = \frac{x}{2^p}$:

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

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

$$ f(x, p, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd}. \end{cases} $$

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

Worst-case complexity

Constant time and additional memory.

Panics

Panics if rm is RoundingMode::Exact but self is not divisible by $2^b$.

Examples

See here.

Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode.

Passing RoundingMode::Floor or RoundingMode::Down is equivalent to using >>. To test whether RoundingMode::Exact can be passed, use self.divisible_by_power_of_2(bits).

Let $q = \frac{x}{2^p}$:

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

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

$$ f(x, p, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd}. \end{cases} $$

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

Worst-case complexity

Constant time and additional memory.

Panics

Panics if rm is RoundingMode::Exact but self is not divisible by $2^b$.

Examples

See here.

Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode.

Passing RoundingMode::Floor or RoundingMode::Down is equivalent to using >>. To test whether RoundingMode::Exact can be passed, use self.divisible_by_power_of_2(bits).

Let $q = \frac{x}{2^p}$:

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

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

$$ f(x, p, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd}. \end{cases} $$

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

Worst-case complexity

Constant time and additional memory.

Panics

Panics if rm is RoundingMode::Exact but self is not divisible by $2^b$.

Examples

See here.

Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode.

Passing RoundingMode::Floor or RoundingMode::Down is equivalent to using >>. To test whether RoundingMode::Exact can be passed, use self.divisible_by_power_of_2(bits).

Let $q = \frac{x}{2^p}$:

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

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

$$ f(x, p, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd}. \end{cases} $$

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

Worst-case complexity

Constant time and additional memory.

Panics

Panics if rm is RoundingMode::Exact but self is not divisible by $2^b$.

Examples

See here.

Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode.

Passing RoundingMode::Floor or RoundingMode::Down is equivalent to using >>. To test whether RoundingMode::Exact can be passed, use self.divisible_by_power_of_2(bits).

Let $q = \frac{x}{2^p}$:

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

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

$$ f(x, p, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd}. \end{cases} $$

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

Worst-case complexity

Constant time and additional memory.

Panics

Panics if rm is RoundingMode::Exact but self is not divisible by $2^b$.

Examples

See here.

Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode.

Passing RoundingMode::Floor or RoundingMode::Down is equivalent to using >>. To test whether RoundingMode::Exact can be passed, use self.divisible_by_power_of_2(bits).

Let $q = \frac{x}{2^p}$:

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

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

$$ f(x, p, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd}. \end{cases} $$

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

Worst-case complexity

Constant time and additional memory.

Panics

Panics if rm is RoundingMode::Exact but self is not divisible by $2^b$.

Examples

See here.

Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode.

Passing RoundingMode::Floor or RoundingMode::Down is equivalent to using >>. To test whether RoundingMode::Exact can be passed, use self.divisible_by_power_of_2(bits).

Let $q = \frac{x}{2^p}$:

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

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

$$ f(x, p, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd}. \end{cases} $$

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

Worst-case complexity

Constant time and additional memory.

Panics

Panics if rm is RoundingMode::Exact but self is not divisible by $2^b$.

Examples

See here.

Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode.

Passing RoundingMode::Floor or RoundingMode::Down is equivalent to using >>. To test whether RoundingMode::Exact can be passed, use self.divisible_by_power_of_2(bits).

Let $q = \frac{x}{2^p}$:

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

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

$$ f(x, p, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd}. \end{cases} $$

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

Worst-case complexity

Constant time and additional memory.

Panics

Panics if rm is RoundingMode::Exact but self is not divisible by $2^b$.

Examples

See here.

Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode.

Passing RoundingMode::Floor or RoundingMode::Down is equivalent to using >>. To test whether RoundingMode::Exact can be passed, use self.divisible_by_power_of_2(bits).

Let $q = \frac{x}{2^p}$:

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

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

$$ f(x, p, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd}. \end{cases} $$

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

Worst-case complexity

Constant time and additional memory.

Panics

Panics if rm is RoundingMode::Exact but self is not divisible by $2^b$.

Examples

See here.

Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode.

Passing RoundingMode::Floor or RoundingMode::Down is equivalent to using >>. To test whether RoundingMode::Exact can be passed, use self.divisible_by_power_of_2(bits).

Let $q = \frac{x}{2^p}$:

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

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

$$ f(x, p, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd}. \end{cases} $$

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

Worst-case complexity

Constant time and additional memory.

Panics

Panics if rm is RoundingMode::Exact but self is not divisible by $2^b$.

Examples

See here.

Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode.

Passing RoundingMode::Floor or RoundingMode::Down is equivalent to using >>. To test whether RoundingMode::Exact can be passed, use self.divisible_by_power_of_2(bits).

Let $q = \frac{x}{2^p}$:

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

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

$$ f(x, p, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd}. \end{cases} $$

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

Worst-case complexity

Constant time and additional memory.

Panics

Panics if rm is RoundingMode::Exact but self is not divisible by $2^b$.

Examples

See here.

Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode.

Passing RoundingMode::Floor or RoundingMode::Down is equivalent to using >>. To test whether RoundingMode::Exact can be passed, use self.divisible_by_power_of_2(bits).

Let $q = \frac{x}{2^p}$:

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

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

$$ f(x, p, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd}. \end{cases} $$

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

Worst-case complexity

Constant time and additional memory.

Panics

Panics if rm is RoundingMode::Exact but self is not divisible by $2^b$.

Examples

See here.

Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode.

Passing RoundingMode::Floor or RoundingMode::Down is equivalent to using >>. To test whether RoundingMode::Exact can be passed, use self.divisible_by_power_of_2(bits).

Let $q = \frac{x}{2^p}$:

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

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

$$ f(x, p, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd}. \end{cases} $$

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

Worst-case complexity

Constant time and additional memory.

Panics

Panics if rm is RoundingMode::Exact but self is not divisible by $2^b$.

Examples

See here.

Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode.

Passing RoundingMode::Floor or RoundingMode::Down is equivalent to using >>. To test whether RoundingMode::Exact can be passed, use self.divisible_by_power_of_2(bits).

Let $q = \frac{x}{2^p}$:

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

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

$$ f(x, p, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd}. \end{cases} $$

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

Worst-case complexity

Constant time and additional memory.

Panics

Panics if rm is RoundingMode::Exact but self is not divisible by $2^b$.

Examples

See here.

Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode.

Passing RoundingMode::Floor or RoundingMode::Down is equivalent to using >>. To test whether RoundingMode::Exact can be passed, use self.divisible_by_power_of_2(bits).

Let $q = \frac{x}{2^p}$:

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

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

$$ f(x, p, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd}. \end{cases} $$

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

Worst-case complexity

Constant time and additional memory.

Panics

Panics if rm is RoundingMode::Exact but self is not divisible by $2^b$.

Examples

See here.

Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode.

Passing RoundingMode::Floor or RoundingMode::Down is equivalent to using >>. To test whether RoundingMode::Exact can be passed, use self.divisible_by_power_of_2(bits).

Let $q = \frac{x}{2^p}$:

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

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

$$ f(x, p, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd}. \end{cases} $$

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

Worst-case complexity

Constant time and additional memory.

Panics

Panics if rm is RoundingMode::Exact but self is not divisible by $2^b$.

Examples

See here.

Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode.

Passing RoundingMode::Floor or RoundingMode::Down is equivalent to using >>. To test whether RoundingMode::Exact can be passed, use self.divisible_by_power_of_2(bits).

Let $q = \frac{x}{2^p}$:

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

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

$$ f(x, p, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd}. \end{cases} $$

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

Worst-case complexity

Constant time and additional memory.

Panics

Panics if rm is RoundingMode::Exact but self is not divisible by $2^b$.

Examples

See here.

Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode.

Passing RoundingMode::Floor or RoundingMode::Down is equivalent to using >>. To test whether RoundingMode::Exact can be passed, use self.divisible_by_power_of_2(bits).

Let $q = \frac{x}{2^p}$:

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

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

$$ f(x, p, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd}. \end{cases} $$

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

Worst-case complexity

Constant time and additional memory.

Panics

Panics if rm is RoundingMode::Exact but self is not divisible by $2^b$.

Examples

See here.

Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode.

Passing RoundingMode::Floor or RoundingMode::Down is equivalent to using >>. To test whether RoundingMode::Exact can be passed, use self.divisible_by_power_of_2(bits).

Let $q = \frac{x}{2^p}$:

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

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

$$ f(x, p, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd}. \end{cases} $$

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

Worst-case complexity

Constant time and additional memory.

Panics

Panics if rm is RoundingMode::Exact but self is not divisible by $2^b$.

Examples

See here.

Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode.

Passing RoundingMode::Floor or RoundingMode::Down is equivalent to using >>. To test whether RoundingMode::Exact can be passed, use self.divisible_by_power_of_2(bits).

Let $q = \frac{x}{2^p}$:

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

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

$$ f(x, p, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd}. \end{cases} $$

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

Worst-case complexity

Constant time and additional memory.

Panics

Panics if rm is RoundingMode::Exact but self is not divisible by $2^b$.

Examples

See here.

Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode.

Passing RoundingMode::Floor or RoundingMode::Down is equivalent to using >>. To test whether RoundingMode::Exact can be passed, use self.divisible_by_power_of_2(bits).

Let $q = \frac{x}{2^p}$:

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

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

$$ f(x, p, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd}. \end{cases} $$

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

Worst-case complexity

Constant time and additional memory.

Panics

Panics if rm is RoundingMode::Exact but self is not divisible by $2^b$.

Examples

See here.

Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode.

Passing RoundingMode::Floor or RoundingMode::Down is equivalent to using >>. To test whether RoundingMode::Exact can be passed, use self.divisible_by_power_of_2(bits).

Let $q = \frac{x}{2^p}$:

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

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

$$ f(x, p, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd}. \end{cases} $$

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

Worst-case complexity

Constant time and additional memory.

Panics

Panics if rm is RoundingMode::Exact but self is not divisible by $2^b$.

Examples

See here.

Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode.

Passing RoundingMode::Floor or RoundingMode::Down is equivalent to using >>. To test whether RoundingMode::Exact can be passed, use self.divisible_by_power_of_2(bits).

Let $q = \frac{x}{2^p}$:

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

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

$$ f(x, p, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd}. \end{cases} $$

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

Worst-case complexity

Constant time and additional memory.

Panics

Panics if rm is RoundingMode::Exact but self is not divisible by $2^b$.

Examples

See here.

Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode.

Passing RoundingMode::Floor or RoundingMode::Down is equivalent to using >>. To test whether RoundingMode::Exact can be passed, use self.divisible_by_power_of_2(bits).

Let $q = \frac{x}{2^p}$:

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

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

$$ f(x, p, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd}. \end{cases} $$

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

Worst-case complexity

Constant time and additional memory.

Panics

Panics if rm is RoundingMode::Exact but self is not divisible by $2^b$.

Examples

See here.

Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode.

Passing RoundingMode::Floor or RoundingMode::Down is equivalent to using >>. To test whether RoundingMode::Exact can be passed, use self.divisible_by_power_of_2(bits).

Let $q = \frac{x}{2^p}$:

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

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

$$ f(x, p, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd}. \end{cases} $$

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

Worst-case complexity

Constant time and additional memory.

Panics

Panics if rm is RoundingMode::Exact but self is not divisible by $2^b$.

Examples

See here.

Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode.

Passing RoundingMode::Floor or RoundingMode::Down is equivalent to using >>. To test whether RoundingMode::Exact can be passed, use self.divisible_by_power_of_2(bits). Rounding might only be necessary if bits is non-negative.

Let $q = \frac{x}{2^p}$:

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

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

$f(x, p, \mathrm{Floor}) = \lfloor q \rfloor.$

$f(x, p, \mathrm{Ceiling}) = \lceil q \rceil.$

$$ f(x, p, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd}. \end{cases} $$

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

Worst-case complexity

Constant time and additional memory.

Panics

Panics if bits is positive and rm is RoundingMode::Exact but self is not divisible by $2^b$.

Examples

See here.

Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode.

Passing RoundingMode::Floor or RoundingMode::Down is equivalent to using >>. To test whether RoundingMode::Exact can be passed, use self.divisible_by_power_of_2(bits). Rounding might only be necessary if bits is non-negative.

Let $q = \frac{x}{2^p}$:

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

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

$f(x, p, \mathrm{Floor}) = \lfloor q \rfloor.$

$f(x, p, \mathrm{Ceiling}) = \lceil q \rceil.$

$$ f(x, p, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd}. \end{cases} $$

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

Worst-case complexity

Constant time and additional memory.

Panics

Panics if bits is positive and rm is RoundingMode::Exact but self is not divisible by $2^b$.

Examples

See here.

Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode.

Passing RoundingMode::Floor or RoundingMode::Down is equivalent to using >>. To test whether RoundingMode::Exact can be passed, use self.divisible_by_power_of_2(bits). Rounding might only be necessary if bits is non-negative.

Let $q = \frac{x}{2^p}$:

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

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

$f(x, p, \mathrm{Floor}) = \lfloor q \rfloor.$

$f(x, p, \mathrm{Ceiling}) = \lceil q \rceil.$

$$ f(x, p, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd}. \end{cases} $$

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

Worst-case complexity

Constant time and additional memory.

Panics

Panics if bits is positive and rm is RoundingMode::Exact but self is not divisible by $2^b$.

Examples

See here.

Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode.

Passing RoundingMode::Floor or RoundingMode::Down is equivalent to using >>. To test whether RoundingMode::Exact can be passed, use self.divisible_by_power_of_2(bits). Rounding might only be necessary if bits is non-negative.

Let $q = \frac{x}{2^p}$:

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

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

$f(x, p, \mathrm{Floor}) = \lfloor q \rfloor.$

$f(x, p, \mathrm{Ceiling}) = \lceil q \rceil.$

$$ f(x, p, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd}. \end{cases} $$

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

Worst-case complexity

Constant time and additional memory.

Panics

Panics if bits is positive and rm is RoundingMode::Exact but self is not divisible by $2^b$.

Examples

See here.

Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode.

Passing RoundingMode::Floor or RoundingMode::Down is equivalent to using >>. To test whether RoundingMode::Exact can be passed, use self.divisible_by_power_of_2(bits). Rounding might only be necessary if bits is non-negative.

Let $q = \frac{x}{2^p}$:

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

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

$f(x, p, \mathrm{Floor}) = \lfloor q \rfloor.$

$f(x, p, \mathrm{Ceiling}) = \lceil q \rceil.$

$$ f(x, p, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd}. \end{cases} $$

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

Worst-case complexity

Constant time and additional memory.

Panics

Panics if bits is positive and rm is RoundingMode::Exact but self is not divisible by $2^b$.

Examples

See here.

Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode.

Passing RoundingMode::Floor or RoundingMode::Down is equivalent to using >>. To test whether RoundingMode::Exact can be passed, use self.divisible_by_power_of_2(bits). Rounding might only be necessary if bits is non-negative.

Let $q = \frac{x}{2^p}$:

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

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

$f(x, p, \mathrm{Floor}) = \lfloor q \rfloor.$

$f(x, p, \mathrm{Ceiling}) = \lceil q \rceil.$

$$ f(x, p, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd}. \end{cases} $$

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

Worst-case complexity

Constant time and additional memory.

Panics

Panics if bits is positive and rm is RoundingMode::Exact but self is not divisible by $2^b$.

Examples

See here.

Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode.

Passing RoundingMode::Floor or RoundingMode::Down is equivalent to using >>. To test whether RoundingMode::Exact can be passed, use self.divisible_by_power_of_2(bits). Rounding might only be necessary if bits is non-negative.

Let $q = \frac{x}{2^p}$:

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

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

$f(x, p, \mathrm{Floor}) = \lfloor q \rfloor.$

$f(x, p, \mathrm{Ceiling}) = \lceil q \rceil.$

$$ f(x, p, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd}. \end{cases} $$

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

Worst-case complexity

Constant time and additional memory.

Panics

Panics if bits is positive and rm is RoundingMode::Exact but self is not divisible by $2^b$.

Examples

See here.

Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode.

Passing RoundingMode::Floor or RoundingMode::Down is equivalent to using >>. To test whether RoundingMode::Exact can be passed, use self.divisible_by_power_of_2(bits). Rounding might only be necessary if bits is non-negative.

Let $q = \frac{x}{2^p}$:

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

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

$f(x, p, \mathrm{Floor}) = \lfloor q \rfloor.$

$f(x, p, \mathrm{Ceiling}) = \lceil q \rceil.$

$$ f(x, p, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd}. \end{cases} $$

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

Worst-case complexity

Constant time and additional memory.

Panics

Panics if bits is positive and rm is RoundingMode::Exact but self is not divisible by $2^b$.

Examples

See here.

Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode.

Passing RoundingMode::Floor or RoundingMode::Down is equivalent to using >>. To test whether RoundingMode::Exact can be passed, use self.divisible_by_power_of_2(bits). Rounding might only be necessary if bits is non-negative.

Let $q = \frac{x}{2^p}$:

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

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

$f(x, p, \mathrm{Floor}) = \lfloor q \rfloor.$

$f(x, p, \mathrm{Ceiling}) = \lceil q \rceil.$

$$ f(x, p, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd}. \end{cases} $$

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

Worst-case complexity

Constant time and additional memory.

Panics

Panics if bits is positive and rm is RoundingMode::Exact but self is not divisible by $2^b$.

Examples

See here.

Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode.

Passing RoundingMode::Floor or RoundingMode::Down is equivalent to using >>. To test whether RoundingMode::Exact can be passed, use self.divisible_by_power_of_2(bits). Rounding might only be necessary if bits is non-negative.

Let $q = \frac{x}{2^p}$:

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

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

$f(x, p, \mathrm{Floor}) = \lfloor q \rfloor.$

$f(x, p, \mathrm{Ceiling}) = \lceil q \rceil.$

$$ f(x, p, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd}. \end{cases} $$

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

Worst-case complexity

Constant time and additional memory.

Panics

Panics if bits is positive and rm is RoundingMode::Exact but self is not divisible by $2^b$.

Examples

See here.

Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode.

Passing RoundingMode::Floor or RoundingMode::Down is equivalent to using >>. To test whether RoundingMode::Exact can be passed, use self.divisible_by_power_of_2(bits). Rounding might only be necessary if bits is non-negative.

Let $q = \frac{x}{2^p}$:

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

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

$f(x, p, \mathrm{Floor}) = \lfloor q \rfloor.$

$f(x, p, \mathrm{Ceiling}) = \lceil q \rceil.$

$$ f(x, p, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd}. \end{cases} $$

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

Worst-case complexity

Constant time and additional memory.

Panics

Panics if bits is positive and rm is RoundingMode::Exact but self is not divisible by $2^b$.

Examples

See here.

Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode.

Passing RoundingMode::Floor or RoundingMode::Down is equivalent to using >>. To test whether RoundingMode::Exact can be passed, use self.divisible_by_power_of_2(bits). Rounding might only be necessary if bits is non-negative.

Let $q = \frac{x}{2^p}$:

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

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

$f(x, p, \mathrm{Floor}) = \lfloor q \rfloor.$

$f(x, p, \mathrm{Ceiling}) = \lceil q \rceil.$

$$ f(x, p, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd}. \end{cases} $$

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

Worst-case complexity

Constant time and additional memory.

Panics

Panics if bits is positive and rm is RoundingMode::Exact but self is not divisible by $2^b$.

Examples

See here.

Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode.

Passing RoundingMode::Floor or RoundingMode::Down is equivalent to using >>. To test whether RoundingMode::Exact can be passed, use self.divisible_by_power_of_2(bits). Rounding might only be necessary if bits is non-negative.

Let $q = \frac{x}{2^p}$:

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

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

$f(x, p, \mathrm{Floor}) = \lfloor q \rfloor.$

$f(x, p, \mathrm{Ceiling}) = \lceil q \rceil.$

$$ f(x, p, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd}. \end{cases} $$

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

Worst-case complexity

Constant time and additional memory.

Panics

Panics if bits is positive and rm is RoundingMode::Exact but self is not divisible by $2^b$.

Examples

See here.

Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode.

Passing RoundingMode::Floor or RoundingMode::Down is equivalent to using >>. To test whether RoundingMode::Exact can be passed, use self.divisible_by_power_of_2(bits). Rounding might only be necessary if bits is non-negative.

Let $q = \frac{x}{2^p}$:

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

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

$f(x, p, \mathrm{Floor}) = \lfloor q \rfloor.$

$f(x, p, \mathrm{Ceiling}) = \lceil q \rceil.$

$$ f(x, p, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd}. \end{cases} $$

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

Worst-case complexity

Constant time and additional memory.

Panics

Panics if bits is positive and rm is RoundingMode::Exact but self is not divisible by $2^b$.

Examples

See here.

Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode.

Passing RoundingMode::Floor or RoundingMode::Down is equivalent to using >>. To test whether RoundingMode::Exact can be passed, use self.divisible_by_power_of_2(bits). Rounding might only be necessary if bits is non-negative.

Let $q = \frac{x}{2^p}$:

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

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

$f(x, p, \mathrm{Floor}) = \lfloor q \rfloor.$

$f(x, p, \mathrm{Ceiling}) = \lceil q \rceil.$

$$ f(x, p, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd}. \end{cases} $$

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

Worst-case complexity

Constant time and additional memory.

Panics

Panics if bits is positive and rm is RoundingMode::Exact but self is not divisible by $2^b$.

Examples

See here.

Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode.

Passing RoundingMode::Floor or RoundingMode::Down is equivalent to using >>. To test whether RoundingMode::Exact can be passed, use self.divisible_by_power_of_2(bits). Rounding might only be necessary if bits is non-negative.

Let $q = \frac{x}{2^p}$:

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

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

$f(x, p, \mathrm{Floor}) = \lfloor q \rfloor.$

$f(x, p, \mathrm{Ceiling}) = \lceil q \rceil.$

$$ f(x, p, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd}. \end{cases} $$

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

Worst-case complexity

Constant time and additional memory.

Panics

Panics if bits is positive and rm is RoundingMode::Exact but self is not divisible by $2^b$.

Examples

See here.

Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode.

Passing RoundingMode::Floor or RoundingMode::Down is equivalent to using >>. To test whether RoundingMode::Exact can be passed, use self.divisible_by_power_of_2(bits). Rounding might only be necessary if bits is non-negative.

Let $q = \frac{x}{2^p}$:

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

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

$f(x, p, \mathrm{Floor}) = \lfloor q \rfloor.$

$f(x, p, \mathrm{Ceiling}) = \lceil q \rceil.$

$$ f(x, p, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd}. \end{cases} $$

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

Worst-case complexity

Constant time and additional memory.

Panics

Panics if bits is positive and rm is RoundingMode::Exact but self is not divisible by $2^b$.

Examples

See here.

Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode.

Passing RoundingMode::Floor or RoundingMode::Down is equivalent to using >>. To test whether RoundingMode::Exact can be passed, use self.divisible_by_power_of_2(bits). Rounding might only be necessary if bits is non-negative.

Let $q = \frac{x}{2^p}$:

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

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

$f(x, p, \mathrm{Floor}) = \lfloor q \rfloor.$

$f(x, p, \mathrm{Ceiling}) = \lceil q \rceil.$

$$ f(x, p, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd}. \end{cases} $$

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

Worst-case complexity

Constant time and additional memory.

Panics

Panics if bits is positive and rm is RoundingMode::Exact but self is not divisible by $2^b$.

Examples

See here.

Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode.

Passing RoundingMode::Floor or RoundingMode::Down is equivalent to using >>. To test whether RoundingMode::Exact can be passed, use self.divisible_by_power_of_2(bits). Rounding might only be necessary if bits is non-negative.

Let $q = \frac{x}{2^p}$:

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

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

$f(x, p, \mathrm{Floor}) = \lfloor q \rfloor.$

$f(x, p, \mathrm{Ceiling}) = \lceil q \rceil.$

$$ f(x, p, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd}. \end{cases} $$

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

Worst-case complexity

Constant time and additional memory.

Panics

Panics if bits is positive and rm is RoundingMode::Exact but self is not divisible by $2^b$.

Examples

See here.

Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode.

Passing RoundingMode::Floor or RoundingMode::Down is equivalent to using >>. To test whether RoundingMode::Exact can be passed, use self.divisible_by_power_of_2(bits). Rounding might only be necessary if bits is non-negative.

Let $q = \frac{x}{2^p}$:

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

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

$f(x, p, \mathrm{Floor}) = \lfloor q \rfloor.$

$f(x, p, \mathrm{Ceiling}) = \lceil q \rceil.$

$$ f(x, p, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd}. \end{cases} $$

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

Worst-case complexity

Constant time and additional memory.

Panics

Panics if bits is positive and rm is RoundingMode::Exact but self is not divisible by $2^b$.

Examples

See here.

Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode.

Passing RoundingMode::Floor or RoundingMode::Down is equivalent to using >>. To test whether RoundingMode::Exact can be passed, use self.divisible_by_power_of_2(bits). Rounding might only be necessary if bits is non-negative.

Let $q = \frac{x}{2^p}$:

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

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

$f(x, p, \mathrm{Floor}) = \lfloor q \rfloor.$

$f(x, p, \mathrm{Ceiling}) = \lceil q \rceil.$

$$ f(x, p, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd}. \end{cases} $$

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

Worst-case complexity

Constant time and additional memory.

Panics

Panics if bits is positive and rm is RoundingMode::Exact but self is not divisible by $2^b$.

Examples

See here.

Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode.

Passing RoundingMode::Floor or RoundingMode::Down is equivalent to using >>. To test whether RoundingMode::Exact can be passed, use self.divisible_by_power_of_2(bits). Rounding might only be necessary if bits is non-negative.

Let $q = \frac{x}{2^p}$:

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

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

$f(x, p, \mathrm{Floor}) = \lfloor q \rfloor.$

$f(x, p, \mathrm{Ceiling}) = \lceil q \rceil.$

$$ f(x, p, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd}. \end{cases} $$

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

Worst-case complexity

Constant time and additional memory.

Panics

Panics if bits is positive and rm is RoundingMode::Exact but self is not divisible by $2^b$.

Examples

See here.

Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode.

Passing RoundingMode::Floor or RoundingMode::Down is equivalent to using >>. To test whether RoundingMode::Exact can be passed, use self.divisible_by_power_of_2(bits). Rounding might only be necessary if bits is non-negative.

Let $q = \frac{x}{2^p}$:

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

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

$f(x, p, \mathrm{Floor}) = \lfloor q \rfloor.$

$f(x, p, \mathrm{Ceiling}) = \lceil q \rceil.$

$$ f(x, p, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd}. \end{cases} $$

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

Worst-case complexity

Constant time and additional memory.

Panics

Panics if bits is positive and rm is RoundingMode::Exact but self is not divisible by $2^b$.

Examples

See here.

Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode.

Passing RoundingMode::Floor or RoundingMode::Down is equivalent to using >>. To test whether RoundingMode::Exact can be passed, use self.divisible_by_power_of_2(bits). Rounding might only be necessary if bits is non-negative.

Let $q = \frac{x}{2^p}$:

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

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

$f(x, p, \mathrm{Floor}) = \lfloor q \rfloor.$

$f(x, p, \mathrm{Ceiling}) = \lceil q \rceil.$

$$ f(x, p, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd}. \end{cases} $$

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

Worst-case complexity

Constant time and additional memory.

Panics

Panics if bits is positive and rm is RoundingMode::Exact but self is not divisible by $2^b$.

Examples

See here.

Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode.

Passing RoundingMode::Floor or RoundingMode::Down is equivalent to using >>. To test whether RoundingMode::Exact can be passed, use self.divisible_by_power_of_2(bits). Rounding might only be necessary if bits is non-negative.

Let $q = \frac{x}{2^p}$:

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

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

$f(x, p, \mathrm{Floor}) = \lfloor q \rfloor.$

$f(x, p, \mathrm{Ceiling}) = \lceil q \rceil.$

$$ f(x, p, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd}. \end{cases} $$

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

Worst-case complexity

Constant time and additional memory.

Panics

Panics if bits is positive and rm is RoundingMode::Exact but self is not divisible by $2^b$.

Examples

See here.

Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode.

Passing RoundingMode::Floor or RoundingMode::Down is equivalent to using >>. To test whether RoundingMode::Exact can be passed, use self.divisible_by_power_of_2(bits). Rounding might only be necessary if bits is non-negative.

Let $q = \frac{x}{2^p}$:

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

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

$f(x, p, \mathrm{Floor}) = \lfloor q \rfloor.$

$f(x, p, \mathrm{Ceiling}) = \lceil q \rceil.$

$$ f(x, p, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd}. \end{cases} $$

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

Worst-case complexity

Constant time and additional memory.

Panics

Panics if bits is positive and rm is RoundingMode::Exact but self is not divisible by $2^b$.

Examples

See here.

Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode.

Passing RoundingMode::Floor or RoundingMode::Down is equivalent to using >>. To test whether RoundingMode::Exact can be passed, use self.divisible_by_power_of_2(bits). Rounding might only be necessary if bits is non-negative.

Let $q = \frac{x}{2^p}$:

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

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

$f(x, p, \mathrm{Floor}) = \lfloor q \rfloor.$

$f(x, p, \mathrm{Ceiling}) = \lceil q \rceil.$

$$ f(x, p, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd}. \end{cases} $$

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

Worst-case complexity

Constant time and additional memory.

Panics

Panics if bits is positive and rm is RoundingMode::Exact but self is not divisible by $2^b$.

Examples

See here.

Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode.

Passing RoundingMode::Floor or RoundingMode::Down is equivalent to using >>. To test whether RoundingMode::Exact can be passed, use self.divisible_by_power_of_2(bits). Rounding might only be necessary if bits is non-negative.

Let $q = \frac{x}{2^p}$:

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

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

$f(x, p, \mathrm{Floor}) = \lfloor q \rfloor.$

$f(x, p, \mathrm{Ceiling}) = \lceil q \rceil.$

$$ f(x, p, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd}. \end{cases} $$

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

Worst-case complexity

Constant time and additional memory.

Panics

Panics if bits is positive and rm is RoundingMode::Exact but self is not divisible by $2^b$.

Examples

See here.

Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode.

Passing RoundingMode::Floor or RoundingMode::Down is equivalent to using >>. To test whether RoundingMode::Exact can be passed, use self.divisible_by_power_of_2(bits). Rounding might only be necessary if bits is non-negative.

Let $q = \frac{x}{2^p}$:

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

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

$f(x, p, \mathrm{Floor}) = \lfloor q \rfloor.$

$f(x, p, \mathrm{Ceiling}) = \lceil q \rceil.$

$$ f(x, p, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd}. \end{cases} $$

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

Worst-case complexity

Constant time and additional memory.

Panics

Panics if bits is positive and rm is RoundingMode::Exact but self is not divisible by $2^b$.

Examples

See here.

Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode.

Passing RoundingMode::Floor or RoundingMode::Down is equivalent to using >>. To test whether RoundingMode::Exact can be passed, use self.divisible_by_power_of_2(bits). Rounding might only be necessary if bits is non-negative.

Let $q = \frac{x}{2^p}$:

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

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

$f(x, p, \mathrm{Floor}) = \lfloor q \rfloor.$

$f(x, p, \mathrm{Ceiling}) = \lceil q \rceil.$

$$ f(x, p, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd}. \end{cases} $$

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

Worst-case complexity

Constant time and additional memory.

Panics

Panics if bits is positive and rm is RoundingMode::Exact but self is not divisible by $2^b$.

Examples

See here.

Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode.

Passing RoundingMode::Floor or RoundingMode::Down is equivalent to using >>. To test whether RoundingMode::Exact can be passed, use self.divisible_by_power_of_2(bits). Rounding might only be necessary if bits is non-negative.

Let $q = \frac{x}{2^p}$:

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

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

$f(x, p, \mathrm{Floor}) = \lfloor q \rfloor.$

$f(x, p, \mathrm{Ceiling}) = \lceil q \rceil.$

$$ f(x, p, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd}. \end{cases} $$

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

Worst-case complexity

Constant time and additional memory.

Panics

Panics if bits is positive and rm is RoundingMode::Exact but self is not divisible by $2^b$.

Examples

See here.

Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode.

Passing RoundingMode::Floor or RoundingMode::Down is equivalent to using >>. To test whether RoundingMode::Exact can be passed, use self.divisible_by_power_of_2(bits). Rounding might only be necessary if bits is non-negative.

Let $q = \frac{x}{2^p}$:

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

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

$f(x, p, \mathrm{Floor}) = \lfloor q \rfloor.$

$f(x, p, \mathrm{Ceiling}) = \lceil q \rceil.$

$$ f(x, p, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd}. \end{cases} $$

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

Worst-case complexity

Constant time and additional memory.

Panics

Panics if bits is positive and rm is RoundingMode::Exact but self is not divisible by $2^b$.

Examples

See here.

Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode.

Passing RoundingMode::Floor or RoundingMode::Down is equivalent to using >>. To test whether RoundingMode::Exact can be passed, use self.divisible_by_power_of_2(bits). Rounding might only be necessary if bits is non-negative.

Let $q = \frac{x}{2^p}$:

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

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

$f(x, p, \mathrm{Floor}) = \lfloor q \rfloor.$

$f(x, p, \mathrm{Ceiling}) = \lceil q \rceil.$

$$ f(x, p, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd}. \end{cases} $$

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

Worst-case complexity

Constant time and additional memory.

Panics

Panics if bits is positive and rm is RoundingMode::Exact but self is not divisible by $2^b$.

Examples

See here.

Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode.

Passing RoundingMode::Floor or RoundingMode::Down is equivalent to using >>. To test whether RoundingMode::Exact can be passed, use self.divisible_by_power_of_2(bits). Rounding might only be necessary if bits is non-negative.

Let $q = \frac{x}{2^p}$:

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

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

$f(x, p, \mathrm{Floor}) = \lfloor q \rfloor.$

$f(x, p, \mathrm{Ceiling}) = \lceil q \rceil.$

$$ f(x, p, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd}. \end{cases} $$

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

Worst-case complexity

Constant time and additional memory.

Panics

Panics if bits is positive and rm is RoundingMode::Exact but self is not divisible by $2^b$.

Examples

See here.

Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode.

Passing RoundingMode::Floor or RoundingMode::Down is equivalent to using >>. To test whether RoundingMode::Exact can be passed, use self.divisible_by_power_of_2(bits). Rounding might only be necessary if bits is non-negative.

Let $q = \frac{x}{2^p}$:

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

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

$f(x, p, \mathrm{Floor}) = \lfloor q \rfloor.$

$f(x, p, \mathrm{Ceiling}) = \lceil q \rceil.$

$$ f(x, p, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd}. \end{cases} $$

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

Worst-case complexity

Constant time and additional memory.

Panics

Panics if bits is positive and rm is RoundingMode::Exact but self is not divisible by $2^b$.

Examples

See here.

Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode.

Passing RoundingMode::Floor or RoundingMode::Down is equivalent to using >>. To test whether RoundingMode::Exact can be passed, use self.divisible_by_power_of_2(bits). Rounding might only be necessary if bits is non-negative.

Let $q = \frac{x}{2^p}$:

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

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

$f(x, p, \mathrm{Floor}) = \lfloor q \rfloor.$

$f(x, p, \mathrm{Ceiling}) = \lceil q \rceil.$

$$ f(x, p, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd}. \end{cases} $$

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

Worst-case complexity

Constant time and additional memory.

Panics

Panics if bits is positive and rm is RoundingMode::Exact but self is not divisible by $2^b$.

Examples

See here.

Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode.

Passing RoundingMode::Floor or RoundingMode::Down is equivalent to using >>. To test whether RoundingMode::Exact can be passed, use self.divisible_by_power_of_2(bits). Rounding might only be necessary if bits is non-negative.

Let $q = \frac{x}{2^p}$:

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

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

$f(x, p, \mathrm{Floor}) = \lfloor q \rfloor.$

$f(x, p, \mathrm{Ceiling}) = \lceil q \rceil.$

$$ f(x, p, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd}. \end{cases} $$

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

Worst-case complexity

Constant time and additional memory.

Panics

Panics if bits is positive and rm is RoundingMode::Exact but self is not divisible by $2^b$.

Examples

See here.

Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode.

Passing RoundingMode::Floor or RoundingMode::Down is equivalent to using >>. To test whether RoundingMode::Exact can be passed, use self.divisible_by_power_of_2(bits). Rounding might only be necessary if bits is non-negative.

Let $q = \frac{x}{2^p}$:

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

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

$f(x, p, \mathrm{Floor}) = \lfloor q \rfloor.$

$f(x, p, \mathrm{Ceiling}) = \lceil q \rceil.$

$$ f(x, p, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd}. \end{cases} $$

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

Worst-case complexity

Constant time and additional memory.

Panics

Panics if bits is positive and rm is RoundingMode::Exact but self is not divisible by $2^b$.

Examples

See here.

Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode.

Passing RoundingMode::Floor or RoundingMode::Down is equivalent to using >>. To test whether RoundingMode::Exact can be passed, use self.divisible_by_power_of_2(bits). Rounding might only be necessary if bits is non-negative.

Let $q = \frac{x}{2^p}$:

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

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

$f(x, p, \mathrm{Floor}) = \lfloor q \rfloor.$

$f(x, p, \mathrm{Ceiling}) = \lceil q \rceil.$

$$ f(x, p, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd}. \end{cases} $$

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

Worst-case complexity

Constant time and additional memory.

Panics

Panics if bits is positive and rm is RoundingMode::Exact but self is not divisible by $2^b$.

Examples

See here.

Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode.

Passing RoundingMode::Floor or RoundingMode::Down is equivalent to using >>. To test whether RoundingMode::Exact can be passed, use self.divisible_by_power_of_2(bits). Rounding might only be necessary if bits is non-negative.

Let $q = \frac{x}{2^p}$:

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

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

$f(x, p, \mathrm{Floor}) = \lfloor q \rfloor.$

$f(x, p, \mathrm{Ceiling}) = \lceil q \rceil.$

$$ f(x, p, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd}. \end{cases} $$

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

Worst-case complexity

Constant time and additional memory.

Panics

Panics if bits is positive and rm is RoundingMode::Exact but self is not divisible by $2^b$.

Examples

See here.

Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode.

Passing RoundingMode::Floor or RoundingMode::Down is equivalent to using >>. To test whether RoundingMode::Exact can be passed, use self.divisible_by_power_of_2(bits). Rounding might only be necessary if bits is non-negative.

Let $q = \frac{x}{2^p}$:

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

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

$f(x, p, \mathrm{Floor}) = \lfloor q \rfloor.$

$f(x, p, \mathrm{Ceiling}) = \lceil q \rceil.$

$$ f(x, p, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd}. \end{cases} $$

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

Worst-case complexity

Constant time and additional memory.

Panics

Panics if bits is positive and rm is RoundingMode::Exact but self is not divisible by $2^b$.

Examples

See here.

Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode.

Passing RoundingMode::Floor or RoundingMode::Down is equivalent to using >>. To test whether RoundingMode::Exact can be passed, use self.divisible_by_power_of_2(bits). Rounding might only be necessary if bits is non-negative.

Let $q = \frac{x}{2^p}$:

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

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

$f(x, p, \mathrm{Floor}) = \lfloor q \rfloor.$

$f(x, p, \mathrm{Ceiling}) = \lceil q \rceil.$

$$ f(x, p, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd}. \end{cases} $$

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

Worst-case complexity

Constant time and additional memory.

Panics

Panics if bits is positive and rm is RoundingMode::Exact but self is not divisible by $2^b$.

Examples

See here.

Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode.

Passing RoundingMode::Floor or RoundingMode::Down is equivalent to using >>. To test whether RoundingMode::Exact can be passed, use self.divisible_by_power_of_2(bits). Rounding might only be necessary if bits is non-negative.

Let $q = \frac{x}{2^p}$:

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

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

$f(x, p, \mathrm{Floor}) = \lfloor q \rfloor.$

$f(x, p, \mathrm{Ceiling}) = \lceil q \rceil.$

$$ f(x, p, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd}. \end{cases} $$

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

Worst-case complexity

Constant time and additional memory.

Panics

Panics if bits is positive and rm is RoundingMode::Exact but self is not divisible by $2^b$.

Examples

See here.

Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode.

Passing RoundingMode::Floor or RoundingMode::Down is equivalent to using >>. To test whether RoundingMode::Exact can be passed, use self.divisible_by_power_of_2(bits). Rounding might only be necessary if bits is non-negative.

Let $q = \frac{x}{2^p}$:

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

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

$f(x, p, \mathrm{Floor}) = \lfloor q \rfloor.$

$f(x, p, \mathrm{Ceiling}) = \lceil q \rceil.$

$$ f(x, p, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd}. \end{cases} $$

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

Worst-case complexity

Constant time and additional memory.

Panics

Panics if bits is positive and rm is RoundingMode::Exact but self is not divisible by $2^b$.

Examples

See here.

Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode.

Passing RoundingMode::Floor or RoundingMode::Down is equivalent to using >>. To test whether RoundingMode::Exact can be passed, use self.divisible_by_power_of_2(bits). Rounding might only be necessary if bits is non-negative.

Let $q = \frac{x}{2^p}$:

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

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

$f(x, p, \mathrm{Floor}) = \lfloor q \rfloor.$

$f(x, p, \mathrm{Ceiling}) = \lceil q \rceil.$

$$ f(x, p, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd}. \end{cases} $$

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

Worst-case complexity

Constant time and additional memory.

Panics

Panics if bits is positive and rm is RoundingMode::Exact but self is not divisible by $2^b$.

Examples

See here.

Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode.

Passing RoundingMode::Floor or RoundingMode::Down is equivalent to using >>. To test whether RoundingMode::Exact can be passed, use self.divisible_by_power_of_2(bits). Rounding might only be necessary if bits is non-negative.

Let $q = \frac{x}{2^p}$:

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

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

$f(x, p, \mathrm{Floor}) = \lfloor q \rfloor.$

$f(x, p, \mathrm{Ceiling}) = \lceil q \rceil.$

$$ f(x, p, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd}. \end{cases} $$

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

Worst-case complexity

Constant time and additional memory.

Panics

Panics if bits is positive and rm is RoundingMode::Exact but self is not divisible by $2^b$.

Examples

See here.

Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode.

Passing RoundingMode::Floor or RoundingMode::Down is equivalent to using >>. To test whether RoundingMode::Exact can be passed, use self.divisible_by_power_of_2(bits). Rounding might only be necessary if bits is non-negative.

Let $q = \frac{x}{2^p}$:

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

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

$f(x, p, \mathrm{Floor}) = \lfloor q \rfloor.$

$f(x, p, \mathrm{Ceiling}) = \lceil q \rceil.$

$$ f(x, p, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd}. \end{cases} $$

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

Worst-case complexity

Constant time and additional memory.

Panics

Panics if bits is positive and rm is RoundingMode::Exact but self is not divisible by $2^b$.

Examples

See here.

Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode.

Passing RoundingMode::Floor or RoundingMode::Down is equivalent to using >>. To test whether RoundingMode::Exact can be passed, use self.divisible_by_power_of_2(bits). Rounding might only be necessary if bits is non-negative.

Let $q = \frac{x}{2^p}$:

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

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

$f(x, p, \mathrm{Floor}) = \lfloor q \rfloor.$

$f(x, p, \mathrm{Ceiling}) = \lceil q \rceil.$

$$ f(x, p, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd}. \end{cases} $$

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

Worst-case complexity

Constant time and additional memory.

Panics

Panics if bits is positive and rm is RoundingMode::Exact but self is not divisible by $2^b$.

Examples

See here.

Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode.

Passing RoundingMode::Floor or RoundingMode::Down is equivalent to using >>. To test whether RoundingMode::Exact can be passed, use self.divisible_by_power_of_2(bits). Rounding might only be necessary if bits is non-negative.

Let $q = \frac{x}{2^p}$:

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

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

$f(x, p, \mathrm{Floor}) = \lfloor q \rfloor.$

$f(x, p, \mathrm{Ceiling}) = \lceil q \rceil.$

$$ f(x, p, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd}. \end{cases} $$

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

Worst-case complexity

Constant time and additional memory.

Panics

Panics if bits is positive and rm is RoundingMode::Exact but self is not divisible by $2^b$.

Examples

See here.

Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode.

Passing RoundingMode::Floor or RoundingMode::Down is equivalent to using >>. To test whether RoundingMode::Exact can be passed, use self.divisible_by_power_of_2(bits). Rounding might only be necessary if bits is non-negative.

Let $q = \frac{x}{2^p}$:

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

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

$f(x, p, \mathrm{Floor}) = \lfloor q \rfloor.$

$f(x, p, \mathrm{Ceiling}) = \lceil q \rceil.$

$$ f(x, p, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd}. \end{cases} $$

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

Worst-case complexity

Constant time and additional memory.

Panics

Panics if bits is positive and rm is RoundingMode::Exact but self is not divisible by $2^b$.

Examples

See here.

Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode.

Passing RoundingMode::Floor or RoundingMode::Down is equivalent to using >>. To test whether RoundingMode::Exact can be passed, use self.divisible_by_power_of_2(bits). Rounding might only be necessary if bits is non-negative.

Let $q = \frac{x}{2^p}$:

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

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

$f(x, p, \mathrm{Floor}) = \lfloor q \rfloor.$

$f(x, p, \mathrm{Ceiling}) = \lceil q \rceil.$

$$ f(x, p, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd}. \end{cases} $$

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

Worst-case complexity

Constant time and additional memory.

Panics

Panics if bits is positive and rm is RoundingMode::Exact but self is not divisible by $2^b$.

Examples

See here.

Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode.

Passing RoundingMode::Floor or RoundingMode::Down is equivalent to using >>. To test whether RoundingMode::Exact can be passed, use self.divisible_by_power_of_2(bits). Rounding might only be necessary if bits is non-negative.

Let $q = \frac{x}{2^p}$:

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

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

$f(x, p, \mathrm{Floor}) = \lfloor q \rfloor.$

$f(x, p, \mathrm{Ceiling}) = \lceil q \rceil.$

$$ f(x, p, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd}. \end{cases} $$

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

Worst-case complexity

Constant time and additional memory.

Panics

Panics if bits is positive and rm is RoundingMode::Exact but self is not divisible by $2^b$.

Examples

See here.

Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode.

Passing RoundingMode::Floor or RoundingMode::Down is equivalent to using >>. To test whether RoundingMode::Exact can be passed, use self.divisible_by_power_of_2(bits). Rounding might only be necessary if bits is non-negative.

Let $q = \frac{x}{2^p}$:

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

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

$f(x, p, \mathrm{Floor}) = \lfloor q \rfloor.$

$f(x, p, \mathrm{Ceiling}) = \lceil q \rceil.$

$$ f(x, p, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd}. \end{cases} $$

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

Worst-case complexity

Constant time and additional memory.

Panics

Panics if bits is positive and rm is RoundingMode::Exact but self is not divisible by $2^b$.

Examples

See here.

Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode.

Passing RoundingMode::Floor or RoundingMode::Down is equivalent to using >>. To test whether RoundingMode::Exact can be passed, use self.divisible_by_power_of_2(bits). Rounding might only be necessary if bits is non-negative.

Let $q = \frac{x}{2^p}$:

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

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

$f(x, p, \mathrm{Floor}) = \lfloor q \rfloor.$

$f(x, p, \mathrm{Ceiling}) = \lceil q \rceil.$

$$ f(x, p, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd}. \end{cases} $$

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

Worst-case complexity

Constant time and additional memory.

Panics

Panics if bits is positive and rm is RoundingMode::Exact but self is not divisible by $2^b$.

Examples

See here.

Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode.

Passing RoundingMode::Floor or RoundingMode::Down is equivalent to using >>. To test whether RoundingMode::Exact can be passed, use self.divisible_by_power_of_2(bits). Rounding might only be necessary if bits is non-negative.

Let $q = \frac{x}{2^p}$:

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

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

$f(x, p, \mathrm{Floor}) = \lfloor q \rfloor.$

$f(x, p, \mathrm{Ceiling}) = \lceil q \rceil.$

$$ f(x, p, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd}. \end{cases} $$

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

Worst-case complexity

Constant time and additional memory.

Panics

Panics if bits is positive and rm is RoundingMode::Exact but self is not divisible by $2^b$.

Examples

See here.

Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode.

Passing RoundingMode::Floor or RoundingMode::Down is equivalent to using >>. To test whether RoundingMode::Exact can be passed, use self.divisible_by_power_of_2(bits). Rounding might only be necessary if bits is non-negative.

Let $q = \frac{x}{2^p}$:

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

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

$f(x, p, \mathrm{Floor}) = \lfloor q \rfloor.$

$f(x, p, \mathrm{Ceiling}) = \lceil q \rceil.$

$$ f(x, p, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd}. \end{cases} $$

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

Worst-case complexity

Constant time and additional memory.

Panics

Panics if bits is positive and rm is RoundingMode::Exact but self is not divisible by $2^b$.

Examples

See here.

Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode.

Passing RoundingMode::Floor or RoundingMode::Down is equivalent to using >>. To test whether RoundingMode::Exact can be passed, use self.divisible_by_power_of_2(bits). Rounding might only be necessary if bits is non-negative.

Let $q = \frac{x}{2^p}$:

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

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

$f(x, p, \mathrm{Floor}) = \lfloor q \rfloor.$

$f(x, p, \mathrm{Ceiling}) = \lceil q \rceil.$

$$ f(x, p, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd}. \end{cases} $$

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

Worst-case complexity

Constant time and additional memory.

Panics

Panics if bits is positive and rm is RoundingMode::Exact but self is not divisible by $2^b$.

Examples

See here.

Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode.

Passing RoundingMode::Floor or RoundingMode::Down is equivalent to using >>. To test whether RoundingMode::Exact can be passed, use self.divisible_by_power_of_2(bits). Rounding might only be necessary if bits is non-negative.

Let $q = \frac{x}{2^p}$:

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

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

$f(x, p, \mathrm{Floor}) = \lfloor q \rfloor.$

$f(x, p, \mathrm{Ceiling}) = \lceil q \rceil.$

$$ f(x, p, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd}. \end{cases} $$

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

Worst-case complexity

Constant time and additional memory.

Panics

Panics if bits is positive and rm is RoundingMode::Exact but self is not divisible by $2^b$.

Examples

See here.

Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode.

Passing RoundingMode::Floor or RoundingMode::Down is equivalent to using >>. To test whether RoundingMode::Exact can be passed, use self.divisible_by_power_of_2(bits). Rounding might only be necessary if bits is non-negative.

Let $q = \frac{x}{2^p}$:

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

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

$f(x, p, \mathrm{Floor}) = \lfloor q \rfloor.$

$f(x, p, \mathrm{Ceiling}) = \lceil q \rceil.$

$$ f(x, p, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd}. \end{cases} $$

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

Worst-case complexity

Constant time and additional memory.

Panics

Panics if bits is positive and rm is RoundingMode::Exact but self is not divisible by $2^b$.

Examples

See here.

Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode.

Passing RoundingMode::Floor or RoundingMode::Down is equivalent to using >>. To test whether RoundingMode::Exact can be passed, use self.divisible_by_power_of_2(bits). Rounding might only be necessary if bits is non-negative.

Let $q = \frac{x}{2^p}$:

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

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

$f(x, p, \mathrm{Floor}) = \lfloor q \rfloor.$

$f(x, p, \mathrm{Ceiling}) = \lceil q \rceil.$

$$ f(x, p, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd}. \end{cases} $$

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

Worst-case complexity

Constant time and additional memory.

Panics

Panics if bits is positive and rm is RoundingMode::Exact but self is not divisible by $2^b$.

Examples

See here.

Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode.

Passing RoundingMode::Floor or RoundingMode::Down is equivalent to using >>. To test whether RoundingMode::Exact can be passed, use self.divisible_by_power_of_2(bits). Rounding might only be necessary if bits is non-negative.

Let $q = \frac{x}{2^p}$:

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

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

$f(x, p, \mathrm{Floor}) = \lfloor q \rfloor.$

$f(x, p, \mathrm{Ceiling}) = \lceil q \rceil.$

$$ f(x, p, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd}. \end{cases} $$

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

Worst-case complexity

Constant time and additional memory.

Panics

Panics if bits is positive and rm is RoundingMode::Exact but self is not divisible by $2^b$.

Examples

See here.

Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode.

Passing RoundingMode::Floor or RoundingMode::Down is equivalent to using >>. To test whether RoundingMode::Exact can be passed, use self.divisible_by_power_of_2(bits). Rounding might only be necessary if bits is non-negative.

Let $q = \frac{x}{2^p}$:

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

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

$f(x, p, \mathrm{Floor}) = \lfloor q \rfloor.$

$f(x, p, \mathrm{Ceiling}) = \lceil q \rceil.$

$$ f(x, p, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd}. \end{cases} $$

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

Worst-case complexity

Constant time and additional memory.

Panics

Panics if bits is positive and rm is RoundingMode::Exact but self is not divisible by $2^b$.

Examples

See here.

Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode.

Passing RoundingMode::Floor or RoundingMode::Down is equivalent to using >>. To test whether RoundingMode::Exact can be passed, use self.divisible_by_power_of_2(bits). Rounding might only be necessary if bits is non-negative.

Let $q = \frac{x}{2^p}$:

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

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

$f(x, p, \mathrm{Floor}) = \lfloor q \rfloor.$

$f(x, p, \mathrm{Ceiling}) = \lceil q \rceil.$

$$ f(x, p, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd}. \end{cases} $$

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

Worst-case complexity

Constant time and additional memory.

Panics

Panics if bits is positive and rm is RoundingMode::Exact but self is not divisible by $2^b$.

Examples

See here.

Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode.

Passing RoundingMode::Floor or RoundingMode::Down is equivalent to using >>. To test whether RoundingMode::Exact can be passed, use self.divisible_by_power_of_2(bits). Rounding might only be necessary if bits is non-negative.

Let $q = \frac{x}{2^p}$:

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

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

$f(x, p, \mathrm{Floor}) = \lfloor q \rfloor.$

$f(x, p, \mathrm{Ceiling}) = \lceil q \rceil.$

$$ f(x, p, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd}. \end{cases} $$

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

Worst-case complexity

Constant time and additional memory.

Panics

Panics if bits is positive and rm is RoundingMode::Exact but self is not divisible by $2^b$.

Examples

See here.

Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode.

Passing RoundingMode::Floor or RoundingMode::Down is equivalent to using >>. To test whether RoundingMode::Exact can be passed, use self.divisible_by_power_of_2(bits). Rounding might only be necessary if bits is non-negative.

Let $q = \frac{x}{2^p}$:

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

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

$f(x, p, \mathrm{Floor}) = \lfloor q \rfloor.$

$f(x, p, \mathrm{Ceiling}) = \lceil q \rceil.$

$$ f(x, p, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd}. \end{cases} $$

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

Worst-case complexity

Constant time and additional memory.

Panics

Panics if bits is positive and rm is RoundingMode::Exact but self is not divisible by $2^b$.

Examples

See here.

Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode.

Passing RoundingMode::Floor or RoundingMode::Down is equivalent to using >>. To test whether RoundingMode::Exact can be passed, use self.divisible_by_power_of_2(bits). Rounding might only be necessary if bits is non-negative.

Let $q = \frac{x}{2^p}$:

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

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

$f(x, p, \mathrm{Floor}) = \lfloor q \rfloor.$

$f(x, p, \mathrm{Ceiling}) = \lceil q \rceil.$

$$ f(x, p, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd}. \end{cases} $$

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

Worst-case complexity

Constant time and additional memory.

Panics

Panics if bits is positive and rm is RoundingMode::Exact but self is not divisible by $2^b$.

Examples

See here.

Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode.

Passing RoundingMode::Floor or RoundingMode::Down is equivalent to using >>. To test whether RoundingMode::Exact can be passed, use self.divisible_by_power_of_2(bits). Rounding might only be necessary if bits is non-negative.

Let $q = \frac{x}{2^p}$:

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

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

$f(x, p, \mathrm{Floor}) = \lfloor q \rfloor.$

$f(x, p, \mathrm{Ceiling}) = \lceil q \rceil.$

$$ f(x, p, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd}. \end{cases} $$

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

Worst-case complexity

Constant time and additional memory.

Panics

Panics if bits is positive and rm is RoundingMode::Exact but self is not divisible by $2^b$.

Examples

See here.

Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode.

Passing RoundingMode::Floor or RoundingMode::Down is equivalent to using >>. To test whether RoundingMode::Exact can be passed, use self.divisible_by_power_of_2(bits). Rounding might only be necessary if bits is non-negative.

Let $q = \frac{x}{2^p}$:

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

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

$f(x, p, \mathrm{Floor}) = \lfloor q \rfloor.$

$f(x, p, \mathrm{Ceiling}) = \lceil q \rceil.$

$$ f(x, p, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd}. \end{cases} $$

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

Worst-case complexity

Constant time and additional memory.

Panics

Panics if bits is positive and rm is RoundingMode::Exact but self is not divisible by $2^b$.

Examples

See here.

Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode.

Passing RoundingMode::Floor or RoundingMode::Down is equivalent to using >>. To test whether RoundingMode::Exact can be passed, use self.divisible_by_power_of_2(bits). Rounding might only be necessary if bits is non-negative.

Let $q = \frac{x}{2^p}$:

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

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

$f(x, p, \mathrm{Floor}) = \lfloor q \rfloor.$

$f(x, p, \mathrm{Ceiling}) = \lceil q \rceil.$

$$ f(x, p, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd}. \end{cases} $$

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

Worst-case complexity

Constant time and additional memory.

Panics

Panics if bits is positive and rm is RoundingMode::Exact but self is not divisible by $2^b$.

Examples

See here.

Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode.

Passing RoundingMode::Floor or RoundingMode::Down is equivalent to using >>. To test whether RoundingMode::Exact can be passed, use self.divisible_by_power_of_2(bits). Rounding might only be necessary if bits is non-negative.

Let $q = \frac{x}{2^p}$:

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

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

$f(x, p, \mathrm{Floor}) = \lfloor q \rfloor.$

$f(x, p, \mathrm{Ceiling}) = \lceil q \rceil.$

$$ f(x, p, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd}. \end{cases} $$

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

Worst-case complexity

Constant time and additional memory.

Panics

Panics if bits is positive and rm is RoundingMode::Exact but self is not divisible by $2^b$.

Examples

See here.

Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode.

Passing RoundingMode::Floor or RoundingMode::Down is equivalent to using >>. To test whether RoundingMode::Exact can be passed, use self.divisible_by_power_of_2(bits). Rounding might only be necessary if bits is non-negative.

Let $q = \frac{x}{2^p}$:

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

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

$f(x, p, \mathrm{Floor}) = \lfloor q \rfloor.$

$f(x, p, \mathrm{Ceiling}) = \lceil q \rceil.$

$$ f(x, p, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd}. \end{cases} $$

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

Worst-case complexity

Constant time and additional memory.

Panics

Panics if bits is positive and rm is RoundingMode::Exact but self is not divisible by $2^b$.

Examples

See here.

Shifts a number right (divides it by a power of 2) and rounds according to the specified rounding mode.

Passing RoundingMode::Floor or RoundingMode::Down is equivalent to using >>. To test whether RoundingMode::Exact can be passed, use self.divisible_by_power_of_2(bits). Rounding might only be necessary if bits is non-negative.

Let $q = \frac{x}{2^p}$:

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

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

$f(x, p, \mathrm{Floor}) = \lfloor q \rfloor.$

$f(x, p, \mathrm{Ceiling}) = \lceil q \rceil.$

$$ f(x, p, \mathrm{Nearest}) = \begin{cases} \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor < \frac{1}{2}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor > \frac{1}{2}, \\ \lfloor q \rfloor & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is even}, \\ \lceil q \rceil & \text{if} \quad q - \lfloor q \rfloor = \frac{1}{2} \ \text{and} \ \lfloor q \rfloor \ \text{is odd}. \end{cases} $$

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

Worst-case complexity

Constant time and additional memory.

Panics

Panics if bits is positive and rm is RoundingMode::Exact but self is not divisible by $2^b$.

Examples

See here.

Implementors