# Trait malachite_base::num::arithmetic::traits::DivRound

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

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

Divides a number by another number and rounds according to a specified rounding mode. An Ordering is also returned, indicating whether the returned value is less than, equal to, or greater than the exact value.

source

source

## Implementations on Foreign Types§

source§

### impl DivRound for i8

source§

#### fn div_round(self, other: i8, rm: RoundingMode) -> (i8, Ordering)

Divides a value by another value and rounds according to a specified rounding mode. An Ordering is also returned, indicating whether the returned value is less than, equal to, or greater than the exact value.

Let $q = \frac{x}{y}$, and let $g$ be the function that just returns the first element of the pair, without the Ordering:

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

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

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

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

$$g(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}$$

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

Then

$f(x, y, r) = (g(x, y, r), \operatorname{cmp}(g(x, y, r), q))$.

##### 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.

See here.

§

source§

### impl DivRound for i16

source§

#### fn div_round(self, other: i16, rm: RoundingMode) -> (i16, Ordering)

Divides a value by another value and rounds according to a specified rounding mode. An Ordering is also returned, indicating whether the returned value is less than, equal to, or greater than the exact value.

Let $q = \frac{x}{y}$, and let $g$ be the function that just returns the first element of the pair, without the Ordering:

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

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

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

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

$$g(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}$$

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

Then

$f(x, y, r) = (g(x, y, r), \operatorname{cmp}(g(x, y, r), q))$.

##### 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.

See here.

§

source§

### impl DivRound for i32

source§

#### fn div_round(self, other: i32, rm: RoundingMode) -> (i32, Ordering)

Divides a value by another value and rounds according to a specified rounding mode. An Ordering is also returned, indicating whether the returned value is less than, equal to, or greater than the exact value.

Let $q = \frac{x}{y}$, and let $g$ be the function that just returns the first element of the pair, without the Ordering:

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

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

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

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

$$g(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}$$

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

Then

$f(x, y, r) = (g(x, y, r), \operatorname{cmp}(g(x, y, r), q))$.

##### 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.

See here.

§

source§

### impl DivRound for i64

source§

#### fn div_round(self, other: i64, rm: RoundingMode) -> (i64, Ordering)

Divides a value by another value and rounds according to a specified rounding mode. An Ordering is also returned, indicating whether the returned value is less than, equal to, or greater than the exact value.

Let $q = \frac{x}{y}$, and let $g$ be the function that just returns the first element of the pair, without the Ordering:

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

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

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

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

$$g(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}$$

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

Then

$f(x, y, r) = (g(x, y, r), \operatorname{cmp}(g(x, y, r), q))$.

##### 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.

See here.

§

source§

### impl DivRound for i128

source§

#### fn div_round(self, other: i128, rm: RoundingMode) -> (i128, Ordering)

Divides a value by another value and rounds according to a specified rounding mode. An Ordering is also returned, indicating whether the returned value is less than, equal to, or greater than the exact value.

Let $q = \frac{x}{y}$, and let $g$ be the function that just returns the first element of the pair, without the Ordering:

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

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

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

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

$$g(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}$$

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

Then

$f(x, y, r) = (g(x, y, r), \operatorname{cmp}(g(x, y, r), q))$.

##### 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.

See here.

§

source§

### impl DivRound for isize

source§

#### fn div_round(self, other: isize, rm: RoundingMode) -> (isize, Ordering)

Divides a value by another value and rounds according to a specified rounding mode. An Ordering is also returned, indicating whether the returned value is less than, equal to, or greater than the exact value.

Let $q = \frac{x}{y}$, and let $g$ be the function that just returns the first element of the pair, without the Ordering:

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

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

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

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

$$g(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}$$

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

Then

$f(x, y, r) = (g(x, y, r), \operatorname{cmp}(g(x, y, r), q))$.

##### 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.

See here.

§

source§

### impl DivRound for u8

source§

#### fn div_round(self, other: u8, rm: RoundingMode) -> (u8, Ordering)

Divides a value by another value and rounds according to a specified rounding mode. An Ordering is also returned, indicating whether the returned value is less than, equal to, or greater than the exact value.

Let $q = \frac{x}{y}$, and let $g$ be the function that just returns the first element of the pair, without the Ordering:

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

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

$$g(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}$$

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

Then

$f(x, y, r) = (g(x, y, r), \operatorname{cmp}(g(x, y, r), q))$.

##### Panics

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

See here.

§

source§

### impl DivRound for u16

source§

#### fn div_round(self, other: u16, rm: RoundingMode) -> (u16, Ordering)

Divides a value by another value and rounds according to a specified rounding mode. An Ordering is also returned, indicating whether the returned value is less than, equal to, or greater than the exact value.

Let $q = \frac{x}{y}$, and let $g$ be the function that just returns the first element of the pair, without the Ordering:

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

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

$$g(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}$$

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

Then

$f(x, y, r) = (g(x, y, r), \operatorname{cmp}(g(x, y, r), q))$.

##### Panics

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

See here.

§

source§

### impl DivRound for u32

source§

#### fn div_round(self, other: u32, rm: RoundingMode) -> (u32, Ordering)

Divides a value by another value and rounds according to a specified rounding mode. An Ordering is also returned, indicating whether the returned value is less than, equal to, or greater than the exact value.

Let $q = \frac{x}{y}$, and let $g$ be the function that just returns the first element of the pair, without the Ordering:

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

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

$$g(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}$$

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

Then

$f(x, y, r) = (g(x, y, r), \operatorname{cmp}(g(x, y, r), q))$.

##### Panics

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

See here.

§

source§

### impl DivRound for u64

source§

#### fn div_round(self, other: u64, rm: RoundingMode) -> (u64, Ordering)

Divides a value by another value and rounds according to a specified rounding mode. An Ordering is also returned, indicating whether the returned value is less than, equal to, or greater than the exact value.

Let $q = \frac{x}{y}$, and let $g$ be the function that just returns the first element of the pair, without the Ordering:

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

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

$$g(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}$$

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

Then

$f(x, y, r) = (g(x, y, r), \operatorname{cmp}(g(x, y, r), q))$.

##### Panics

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

See here.

§

source§

### impl DivRound for u128

source§

#### fn div_round(self, other: u128, rm: RoundingMode) -> (u128, Ordering)

Divides a value by another value and rounds according to a specified rounding mode. An Ordering is also returned, indicating whether the returned value is less than, equal to, or greater than the exact value.

Let $q = \frac{x}{y}$, and let $g$ be the function that just returns the first element of the pair, without the Ordering:

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

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

$$g(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}$$

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

Then

$f(x, y, r) = (g(x, y, r), \operatorname{cmp}(g(x, y, r), q))$.

##### Panics

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

See here.

§

source§

### impl DivRound for usize

source§

#### fn div_round(self, other: usize, rm: RoundingMode) -> (usize, Ordering)

Divides a value by another value and rounds according to a specified rounding mode. An Ordering is also returned, indicating whether the returned value is less than, equal to, or greater than the exact value.

Let $q = \frac{x}{y}$, and let $g$ be the function that just returns the first element of the pair, without the Ordering:

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

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

$$g(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}$$

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

Then

$f(x, y, r) = (g(x, y, r), \operatorname{cmp}(g(x, y, r), q))$.

##### Panics

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

See here.

§