Trait malachite_base::num::arithmetic::traits::DivRound
source · 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.
Required Associated Types§
Required Methods§
fn div_round(self, other: RHS, rm: RoundingMode) -> (Self::Output, Ordering)
Implementations on Foreign Types§
source§impl DivRound for i8
impl DivRound for i8
source§fn div_round(self, other: i8, rm: RoundingMode) -> (i8, Ordering)
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))$.
§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.
type Output = i8
source§impl DivRound for i16
impl DivRound for i16
source§fn div_round(self, other: i16, rm: RoundingMode) -> (i16, Ordering)
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))$.
§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.
type Output = i16
source§impl DivRound for i32
impl DivRound for i32
source§fn div_round(self, other: i32, rm: RoundingMode) -> (i32, Ordering)
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))$.
§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.
type Output = i32
source§impl DivRound for i64
impl DivRound for i64
source§fn div_round(self, other: i64, rm: RoundingMode) -> (i64, Ordering)
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))$.
§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.
type Output = i64
source§impl DivRound for i128
impl DivRound for i128
source§fn div_round(self, other: i128, rm: RoundingMode) -> (i128, Ordering)
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))$.
§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.
type Output = i128
source§impl DivRound for isize
impl DivRound for isize
source§fn div_round(self, other: isize, rm: RoundingMode) -> (isize, Ordering)
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))$.
§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.
type Output = isize
source§impl DivRound for u8
impl DivRound for u8
source§fn div_round(self, other: u8, rm: RoundingMode) -> (u8, Ordering)
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))$.
§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.
type Output = u8
source§impl DivRound for u16
impl DivRound for u16
source§fn div_round(self, other: u16, rm: RoundingMode) -> (u16, Ordering)
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))$.
§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.
type Output = u16
source§impl DivRound for u32
impl DivRound for u32
source§fn div_round(self, other: u32, rm: RoundingMode) -> (u32, Ordering)
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))$.
§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.
type Output = u32
source§impl DivRound for u64
impl DivRound for u64
source§fn div_round(self, other: u64, rm: RoundingMode) -> (u64, Ordering)
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))$.
§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.
type Output = u64
source§impl DivRound for u128
impl DivRound for u128
source§fn div_round(self, other: u128, rm: RoundingMode) -> (u128, Ordering)
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))$.
§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.
type Output = u128
source§impl DivRound for usize
impl DivRound for usize
source§fn div_round(self, other: usize, rm: RoundingMode) -> (usize, Ordering)
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))$.
§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.