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