Trait malachite_base::num::arithmetic::traits::DivRem
source · [−]pub trait DivRem<RHS = Self> {
type DivOutput;
type RemOutput;
fn div_rem(self, other: RHS) -> (Self::DivOutput, Self::RemOutput);
}
Expand description
Divides two numbers, returning the quotient and remainder. The quotient is rounded towards zero, and the remainder has the same sign as the dividend (first input).
The quotient and remainder satisfy $x = qy + r$ and $0 \leq |r| < |y|$.
Required Associated Types
Required Methods
Implementations on Foreign Types
sourceimpl DivRem<u8> for u8
impl DivRem<u8> for u8
sourcefn div_rem(self, other: u8) -> (u8, u8)
fn div_rem(self, other: u8) -> (u8, u8)
Divides a number by another number, returning the quotient and remainder. The quotient is rounded towards zero.
The quotient and remainder satisfy $x = qy + r$ and $0 \leq r < y$.
$$ f(x, y) = \left ( \left \lfloor \frac{x}{y} \right \rfloor, \space x - y\left \lfloor \frac{x}{y} \right \rfloor \right ). $$
For unsigned integers, div_rem
is equivalent to div_mod
.
Worst-case complexity
Constant time and additional memory.
Panics
Panics if other
is 0.
Examples
See here.
type DivOutput = u8
type RemOutput = u8
sourceimpl DivRem<u16> for u16
impl DivRem<u16> for u16
sourcefn div_rem(self, other: u16) -> (u16, u16)
fn div_rem(self, other: u16) -> (u16, u16)
Divides a number by another number, returning the quotient and remainder. The quotient is rounded towards zero.
The quotient and remainder satisfy $x = qy + r$ and $0 \leq r < y$.
$$ f(x, y) = \left ( \left \lfloor \frac{x}{y} \right \rfloor, \space x - y\left \lfloor \frac{x}{y} \right \rfloor \right ). $$
For unsigned integers, div_rem
is equivalent to div_mod
.
Worst-case complexity
Constant time and additional memory.
Panics
Panics if other
is 0.
Examples
See here.
type DivOutput = u16
type RemOutput = u16
sourceimpl DivRem<u32> for u32
impl DivRem<u32> for u32
sourcefn div_rem(self, other: u32) -> (u32, u32)
fn div_rem(self, other: u32) -> (u32, u32)
Divides a number by another number, returning the quotient and remainder. The quotient is rounded towards zero.
The quotient and remainder satisfy $x = qy + r$ and $0 \leq r < y$.
$$ f(x, y) = \left ( \left \lfloor \frac{x}{y} \right \rfloor, \space x - y\left \lfloor \frac{x}{y} \right \rfloor \right ). $$
For unsigned integers, div_rem
is equivalent to div_mod
.
Worst-case complexity
Constant time and additional memory.
Panics
Panics if other
is 0.
Examples
See here.
type DivOutput = u32
type RemOutput = u32
sourceimpl DivRem<u64> for u64
impl DivRem<u64> for u64
sourcefn div_rem(self, other: u64) -> (u64, u64)
fn div_rem(self, other: u64) -> (u64, u64)
Divides a number by another number, returning the quotient and remainder. The quotient is rounded towards zero.
The quotient and remainder satisfy $x = qy + r$ and $0 \leq r < y$.
$$ f(x, y) = \left ( \left \lfloor \frac{x}{y} \right \rfloor, \space x - y\left \lfloor \frac{x}{y} \right \rfloor \right ). $$
For unsigned integers, div_rem
is equivalent to div_mod
.
Worst-case complexity
Constant time and additional memory.
Panics
Panics if other
is 0.
Examples
See here.
type DivOutput = u64
type RemOutput = u64
sourceimpl DivRem<u128> for u128
impl DivRem<u128> for u128
sourcefn div_rem(self, other: u128) -> (u128, u128)
fn div_rem(self, other: u128) -> (u128, u128)
Divides a number by another number, returning the quotient and remainder. The quotient is rounded towards zero.
The quotient and remainder satisfy $x = qy + r$ and $0 \leq r < y$.
$$ f(x, y) = \left ( \left \lfloor \frac{x}{y} \right \rfloor, \space x - y\left \lfloor \frac{x}{y} \right \rfloor \right ). $$
For unsigned integers, div_rem
is equivalent to div_mod
.
Worst-case complexity
Constant time and additional memory.
Panics
Panics if other
is 0.
Examples
See here.
type DivOutput = u128
type RemOutput = u128
sourceimpl DivRem<usize> for usize
impl DivRem<usize> for usize
sourcefn div_rem(self, other: usize) -> (usize, usize)
fn div_rem(self, other: usize) -> (usize, usize)
Divides a number by another number, returning the quotient and remainder. The quotient is rounded towards zero.
The quotient and remainder satisfy $x = qy + r$ and $0 \leq r < y$.
$$ f(x, y) = \left ( \left \lfloor \frac{x}{y} \right \rfloor, \space x - y\left \lfloor \frac{x}{y} \right \rfloor \right ). $$
For unsigned integers, div_rem
is equivalent to div_mod
.
Worst-case complexity
Constant time and additional memory.
Panics
Panics if other
is 0.
Examples
See here.
type DivOutput = usize
type RemOutput = usize
sourceimpl DivRem<i8> for i8
impl DivRem<i8> for i8
sourcefn div_rem(self, other: i8) -> (i8, i8)
fn div_rem(self, other: i8) -> (i8, i8)
Divides a number by another number, returning the quotient and remainder. The quotient is rounded towards zero and the remainder has the same sign as the dividend.
The quotient and remainder satisfy $x = qy + r$ and $0 \leq |r| < |y|$.
$$ f(x, y) = \left ( \operatorname{sgn}(xy) \left \lfloor \left | \frac{x}{y} \right | \right \rfloor, \space x - y \operatorname{sgn}(xy) \left \lfloor \left | \frac{x}{y} \right | \right \rfloor \right ). $$
Worst-case complexity
Constant time and additional memory.
Panics
Panics if other
is 0, or if self
is $t::MIN
and other
is -1.
Examples
See here.
type DivOutput = i8
type RemOutput = i8
sourceimpl DivRem<i16> for i16
impl DivRem<i16> for i16
sourcefn div_rem(self, other: i16) -> (i16, i16)
fn div_rem(self, other: i16) -> (i16, i16)
Divides a number by another number, returning the quotient and remainder. The quotient is rounded towards zero and the remainder has the same sign as the dividend.
The quotient and remainder satisfy $x = qy + r$ and $0 \leq |r| < |y|$.
$$ f(x, y) = \left ( \operatorname{sgn}(xy) \left \lfloor \left | \frac{x}{y} \right | \right \rfloor, \space x - y \operatorname{sgn}(xy) \left \lfloor \left | \frac{x}{y} \right | \right \rfloor \right ). $$
Worst-case complexity
Constant time and additional memory.
Panics
Panics if other
is 0, or if self
is $t::MIN
and other
is -1.
Examples
See here.
type DivOutput = i16
type RemOutput = i16
sourceimpl DivRem<i32> for i32
impl DivRem<i32> for i32
sourcefn div_rem(self, other: i32) -> (i32, i32)
fn div_rem(self, other: i32) -> (i32, i32)
Divides a number by another number, returning the quotient and remainder. The quotient is rounded towards zero and the remainder has the same sign as the dividend.
The quotient and remainder satisfy $x = qy + r$ and $0 \leq |r| < |y|$.
$$ f(x, y) = \left ( \operatorname{sgn}(xy) \left \lfloor \left | \frac{x}{y} \right | \right \rfloor, \space x - y \operatorname{sgn}(xy) \left \lfloor \left | \frac{x}{y} \right | \right \rfloor \right ). $$
Worst-case complexity
Constant time and additional memory.
Panics
Panics if other
is 0, or if self
is $t::MIN
and other
is -1.
Examples
See here.
type DivOutput = i32
type RemOutput = i32
sourceimpl DivRem<i64> for i64
impl DivRem<i64> for i64
sourcefn div_rem(self, other: i64) -> (i64, i64)
fn div_rem(self, other: i64) -> (i64, i64)
Divides a number by another number, returning the quotient and remainder. The quotient is rounded towards zero and the remainder has the same sign as the dividend.
The quotient and remainder satisfy $x = qy + r$ and $0 \leq |r| < |y|$.
$$ f(x, y) = \left ( \operatorname{sgn}(xy) \left \lfloor \left | \frac{x}{y} \right | \right \rfloor, \space x - y \operatorname{sgn}(xy) \left \lfloor \left | \frac{x}{y} \right | \right \rfloor \right ). $$
Worst-case complexity
Constant time and additional memory.
Panics
Panics if other
is 0, or if self
is $t::MIN
and other
is -1.
Examples
See here.
type DivOutput = i64
type RemOutput = i64
sourceimpl DivRem<i128> for i128
impl DivRem<i128> for i128
sourcefn div_rem(self, other: i128) -> (i128, i128)
fn div_rem(self, other: i128) -> (i128, i128)
Divides a number by another number, returning the quotient and remainder. The quotient is rounded towards zero and the remainder has the same sign as the dividend.
The quotient and remainder satisfy $x = qy + r$ and $0 \leq |r| < |y|$.
$$ f(x, y) = \left ( \operatorname{sgn}(xy) \left \lfloor \left | \frac{x}{y} \right | \right \rfloor, \space x - y \operatorname{sgn}(xy) \left \lfloor \left | \frac{x}{y} \right | \right \rfloor \right ). $$
Worst-case complexity
Constant time and additional memory.
Panics
Panics if other
is 0, or if self
is $t::MIN
and other
is -1.
Examples
See here.
type DivOutput = i128
type RemOutput = i128
sourceimpl DivRem<isize> for isize
impl DivRem<isize> for isize
sourcefn div_rem(self, other: isize) -> (isize, isize)
fn div_rem(self, other: isize) -> (isize, isize)
Divides a number by another number, returning the quotient and remainder. The quotient is rounded towards zero and the remainder has the same sign as the dividend.
The quotient and remainder satisfy $x = qy + r$ and $0 \leq |r| < |y|$.
$$ f(x, y) = \left ( \operatorname{sgn}(xy) \left \lfloor \left | \frac{x}{y} \right | \right \rfloor, \space x - y \operatorname{sgn}(xy) \left \lfloor \left | \frac{x}{y} \right | \right \rfloor \right ). $$
Worst-case complexity
Constant time and additional memory.
Panics
Panics if other
is 0, or if self
is $t::MIN
and other
is -1.
Examples
See here.