Trait malachite_base::num::arithmetic::traits::DivMod

source ·
pub trait DivMod<RHS = Self> {
    type DivOutput;
    type ModOutput;

    // Required method
    fn div_mod(self, other: RHS) -> (Self::DivOutput, Self::ModOutput);
}
Expand description

Divides two numbers, returning the quotient and remainder. The quotient is rounded towards negative infinity, and the remainder has the same sign as the divisor (second input).

The quotient and remainder satisfy $x = qy + r$ and $0 \leq |r| < |y|$.

Required Associated Types§

Required Methods§

source

fn div_mod(self, other: RHS) -> (Self::DivOutput, Self::ModOutput)

Implementations on Foreign Types§

source§

impl DivMod for i8

source§

fn div_mod(self, other: i8) -> (i8, i8)

Divides a number by another number, returning the quotient and remainder. The quotient is rounded towards negative infinity, and the remainder has the same sign as the second number.

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 ). $$

§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 ModOutput = i8

source§

impl DivMod for i16

source§

fn div_mod(self, other: i16) -> (i16, i16)

Divides a number by another number, returning the quotient and remainder. The quotient is rounded towards negative infinity, and the remainder has the same sign as the second number.

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 ). $$

§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 ModOutput = i16

source§

impl DivMod for i32

source§

fn div_mod(self, other: i32) -> (i32, i32)

Divides a number by another number, returning the quotient and remainder. The quotient is rounded towards negative infinity, and the remainder has the same sign as the second number.

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 ). $$

§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 ModOutput = i32

source§

impl DivMod for i64

source§

fn div_mod(self, other: i64) -> (i64, i64)

Divides a number by another number, returning the quotient and remainder. The quotient is rounded towards negative infinity, and the remainder has the same sign as the second number.

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 ). $$

§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 ModOutput = i64

source§

impl DivMod for i128

source§

fn div_mod(self, other: i128) -> (i128, i128)

Divides a number by another number, returning the quotient and remainder. The quotient is rounded towards negative infinity, and the remainder has the same sign as the second number.

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 ). $$

§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 ModOutput = i128

source§

impl DivMod for isize

source§

fn div_mod(self, other: isize) -> (isize, isize)

Divides a number by another number, returning the quotient and remainder. The quotient is rounded towards negative infinity, and the remainder has the same sign as the second number.

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 ). $$

§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 = isize

§

type ModOutput = isize

source§

impl DivMod for u8

source§

fn div_mod(self, other: u8) -> (u8, u8)

Divides a number by another number, returning the quotient and remainder. The quotient is rounded towards negative infinity.

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 ). $$

§Worst-case complexity

Constant time and additional memory.

§Panics

Panics if other is 0.

§Examples

See here.

§

type DivOutput = u8

§

type ModOutput = u8

source§

impl DivMod for u16

source§

fn div_mod(self, other: u16) -> (u16, u16)

Divides a number by another number, returning the quotient and remainder. The quotient is rounded towards negative infinity.

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 ). $$

§Worst-case complexity

Constant time and additional memory.

§Panics

Panics if other is 0.

§Examples

See here.

§

type DivOutput = u16

§

type ModOutput = u16

source§

impl DivMod for u32

source§

fn div_mod(self, other: u32) -> (u32, u32)

Divides a number by another number, returning the quotient and remainder. The quotient is rounded towards negative infinity.

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 ). $$

§Worst-case complexity

Constant time and additional memory.

§Panics

Panics if other is 0.

§Examples

See here.

§

type DivOutput = u32

§

type ModOutput = u32

source§

impl DivMod for u64

source§

fn div_mod(self, other: u64) -> (u64, u64)

Divides a number by another number, returning the quotient and remainder. The quotient is rounded towards negative infinity.

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 ). $$

§Worst-case complexity

Constant time and additional memory.

§Panics

Panics if other is 0.

§Examples

See here.

§

type DivOutput = u64

§

type ModOutput = u64

source§

impl DivMod for u128

source§

fn div_mod(self, other: u128) -> (u128, u128)

Divides a number by another number, returning the quotient and remainder. The quotient is rounded towards negative infinity.

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 ). $$

§Worst-case complexity

Constant time and additional memory.

§Panics

Panics if other is 0.

§Examples

See here.

§

type DivOutput = u128

§

type ModOutput = u128

source§

impl DivMod for usize

source§

fn div_mod(self, other: usize) -> (usize, usize)

Divides a number by another number, returning the quotient and remainder. The quotient is rounded towards negative infinity.

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 ). $$

§Worst-case complexity

Constant time and additional memory.

§Panics

Panics if other is 0.

§Examples

See here.

§

type DivOutput = usize

§

type ModOutput = usize

Implementors§