pub trait Euclid: Sized + Div<Output = Self> + Rem<Output = Self> {
    // Required methods
    fn div_euclid(&self, v: &Self) -> Self;
    fn rem_euclid(&self, v: &Self) -> Self;
}

Required Methods§

source

fn div_euclid(&self, v: &Self) -> Self

Calculates Euclidean division, the matching method for rem_euclid.

This computes the integer n such that self = n * v + self.rem_euclid(v). In other words, the result is self / v rounded to the integer n such that self >= n * v.

Examples
use num_traits::Euclid;

let a: i32 = 7;
let b: i32 = 4;
assert_eq!(Euclid::div_euclid(&a, &b), 1); // 7 > 4 * 1
assert_eq!(Euclid::div_euclid(&-a, &b), -2); // -7 >= 4 * -2
assert_eq!(Euclid::div_euclid(&a, &-b), -1); // 7 >= -4 * -1
assert_eq!(Euclid::div_euclid(&-a, &-b), 2); // -7 >= -4 * 2
source

fn rem_euclid(&self, v: &Self) -> Self

Calculates the least nonnegative remainder of self (mod v).

In particular, the return value r satisfies 0.0 <= r < v.abs() in most cases. However, due to a floating point round-off error it can result in r == v.abs(), violating the mathematical definition, if self is much smaller than v.abs() in magnitude and self < 0.0. This result is not an element of the function’s codomain, but it is the closest floating point number in the real numbers and thus fulfills the property self == self.div_euclid(v) * v + self.rem_euclid(v) approximatively.

Examples
use num_traits::Euclid;

let a: i32 = 7;
let b: i32 = 4;
assert_eq!(Euclid::rem_euclid(&a, &b), 3);
assert_eq!(Euclid::rem_euclid(&-a, &b), 1);
assert_eq!(Euclid::rem_euclid(&a, &-b), 3);
assert_eq!(Euclid::rem_euclid(&-a, &-b), 1);

Object Safety§

This trait is not object safe.

Implementations on Foreign Types§

source§

impl Euclid for f32

source§

fn div_euclid(&self, v: &f32) -> f32

source§

fn rem_euclid(&self, v: &f32) -> f32

source§

impl Euclid for f64

source§

fn div_euclid(&self, v: &f64) -> f64

source§

fn rem_euclid(&self, v: &f64) -> f64

source§

impl Euclid for i8

source§

fn div_euclid(&self, v: &i8) -> i8

source§

fn rem_euclid(&self, v: &i8) -> i8

source§

impl Euclid for i16

source§

fn div_euclid(&self, v: &i16) -> i16

source§

fn rem_euclid(&self, v: &i16) -> i16

source§

impl Euclid for i32

source§

fn div_euclid(&self, v: &i32) -> i32

source§

fn rem_euclid(&self, v: &i32) -> i32

source§

impl Euclid for i64

source§

fn div_euclid(&self, v: &i64) -> i64

source§

fn rem_euclid(&self, v: &i64) -> i64

source§

impl Euclid for i128

source§

fn div_euclid(&self, v: &i128) -> i128

source§

fn rem_euclid(&self, v: &i128) -> i128

source§

impl Euclid for isize

source§

fn div_euclid(&self, v: &isize) -> isize

source§

fn rem_euclid(&self, v: &isize) -> isize

source§

impl Euclid for u8

source§

fn div_euclid(&self, v: &u8) -> u8

source§

fn rem_euclid(&self, v: &u8) -> u8

source§

impl Euclid for u16

source§

fn div_euclid(&self, v: &u16) -> u16

source§

fn rem_euclid(&self, v: &u16) -> u16

source§

impl Euclid for u32

source§

fn div_euclid(&self, v: &u32) -> u32

source§

fn rem_euclid(&self, v: &u32) -> u32

source§

impl Euclid for u64

source§

fn div_euclid(&self, v: &u64) -> u64

source§

fn rem_euclid(&self, v: &u64) -> u64

source§

impl Euclid for u128

source§

fn div_euclid(&self, v: &u128) -> u128

source§

fn rem_euclid(&self, v: &u128) -> u128

source§

impl Euclid for usize

source§

fn div_euclid(&self, v: &usize) -> usize

source§

fn rem_euclid(&self, v: &usize) -> usize

source§

impl Euclid for BigInt

source§

fn div_euclid(&self, v: &BigInt) -> BigInt

source§

fn rem_euclid(&self, v: &BigInt) -> BigInt

source§

impl Euclid for BigUint

Implementors§