pub trait DivRound<RHS = Self> {
    type Output;

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

Divides a number by another number and rounds according to a specified rounding mode.

Required Associated Types

Required Methods

Implementations on Foreign Types

Divides a value by another value and rounds according to a specified rounding mode.

Let $q = \frac{x}{y}$:

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

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

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

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

Worst-case complexity

Constant time and additional memory.

Panics

Panics if other is zero, or if rm is Exact but self is not divisible by other.

Examples

See here.

Divides a value by another value and rounds according to a specified rounding mode.

Let $q = \frac{x}{y}$:

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

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

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

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

Worst-case complexity

Constant time and additional memory.

Panics

Panics if other is zero, or if rm is Exact but self is not divisible by other.

Examples

See here.

Divides a value by another value and rounds according to a specified rounding mode.

Let $q = \frac{x}{y}$:

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

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

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

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

Worst-case complexity

Constant time and additional memory.

Panics

Panics if other is zero, or if rm is Exact but self is not divisible by other.

Examples

See here.

Divides a value by another value and rounds according to a specified rounding mode.

Let $q = \frac{x}{y}$:

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

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

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

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

Worst-case complexity

Constant time and additional memory.

Panics

Panics if other is zero, or if rm is Exact but self is not divisible by other.

Examples

See here.

Divides a value by another value and rounds according to a specified rounding mode.

Let $q = \frac{x}{y}$:

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

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

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

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

Worst-case complexity

Constant time and additional memory.

Panics

Panics if other is zero, or if rm is Exact but self is not divisible by other.

Examples

See here.

Divides a value by another value and rounds according to a specified rounding mode.

Let $q = \frac{x}{y}$:

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

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

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

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

Worst-case complexity

Constant time and additional memory.

Panics

Panics if other is zero, or if rm is Exact but self is not divisible by other.

Examples

See here.

Divides a value by another value and rounds according to a specified rounding mode.

Let $q = \frac{x}{y}$:

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

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

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

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

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

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

Worst-case complexity

Constant time and additional memory.

Panics

Panics if other is zero, if self is Self::MIN and other is -1, or if rm is Exact but self is not divisible by other.

Examples

See here.

Divides a value by another value and rounds according to a specified rounding mode.

Let $q = \frac{x}{y}$:

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

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

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

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

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

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

Worst-case complexity

Constant time and additional memory.

Panics

Panics if other is zero, if self is Self::MIN and other is -1, or if rm is Exact but self is not divisible by other.

Examples

See here.

Divides a value by another value and rounds according to a specified rounding mode.

Let $q = \frac{x}{y}$:

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

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

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

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

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

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

Worst-case complexity

Constant time and additional memory.

Panics

Panics if other is zero, if self is Self::MIN and other is -1, or if rm is Exact but self is not divisible by other.

Examples

See here.

Divides a value by another value and rounds according to a specified rounding mode.

Let $q = \frac{x}{y}$:

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

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

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

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

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

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

Worst-case complexity

Constant time and additional memory.

Panics

Panics if other is zero, if self is Self::MIN and other is -1, or if rm is Exact but self is not divisible by other.

Examples

See here.

Divides a value by another value and rounds according to a specified rounding mode.

Let $q = \frac{x}{y}$:

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

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

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

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

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

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

Worst-case complexity

Constant time and additional memory.

Panics

Panics if other is zero, if self is Self::MIN and other is -1, or if rm is Exact but self is not divisible by other.

Examples

See here.

Divides a value by another value and rounds according to a specified rounding mode.

Let $q = \frac{x}{y}$:

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

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

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

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

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

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

Worst-case complexity

Constant time and additional memory.

Panics

Panics if other is zero, if self is Self::MIN and other is -1, or if rm is Exact but self is not divisible by other.

Examples

See here.

Implementors