Trait malachite_base::num::arithmetic::traits::DivRem

source ·
pub trait DivRem<RHS = Self> {
    type DivOutput;
    type RemOutput;

    // Required method
    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§

source

fn div_rem(self, other: RHS) -> (Self::DivOutput, Self::RemOutput)

Implementations on Foreign Types§

source§

impl DivRem for i8

source§

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.

source§

type DivOutput = i8

source§

type RemOutput = i8

source§

impl DivRem for i16

source§

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.

source§

type DivOutput = i16

source§

type RemOutput = i16

source§

impl DivRem for i32

source§

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.

source§

type DivOutput = i32

source§

type RemOutput = i32

source§

impl DivRem for i64

source§

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.

source§

type DivOutput = i64

source§

type RemOutput = i64

source§

impl DivRem for i128

source§

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.

source§

type DivOutput = i128

source§

type RemOutput = i128

source§

impl DivRem for isize

source§

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.

source§

type DivOutput = isize

source§

type RemOutput = isize

source§

impl DivRem for u8

source§

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.

source§

type DivOutput = u8

source§

type RemOutput = u8

source§

impl DivRem for u16

source§

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.

source§

type DivOutput = u16

source§

type RemOutput = u16

source§

impl DivRem for u32

source§

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.

source§

type DivOutput = u32

source§

type RemOutput = u32

source§

impl DivRem for u64

source§

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.

source§

type DivOutput = u64

source§

type RemOutput = u64

source§

impl DivRem for u128

source§

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.

source§

type DivOutput = u128

source§

type RemOutput = u128

source§

impl DivRem for usize

source§

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.

source§

type DivOutput = usize

source§

type RemOutput = usize

Implementors§