Trait num_traits::ops::euclid::Euclid

source ·
pub trait Euclid: Sized + Div<Self, Output = Self> + Rem<Self, 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);

Implementations on Foreign Types§

source§

impl Euclid for u8

source§

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

source§

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

source§

impl Euclid for usize

source§

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

source§

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

source§

impl Euclid for i128

source§

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

source§

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

source§

impl Euclid for f32

source§

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

source§

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

source§

impl Euclid for u64

source§

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

source§

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

source§

impl Euclid for i16

source§

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

source§

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

source§

impl Euclid for isize

source§

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

source§

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

source§

impl Euclid for f64

source§

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

source§

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

source§

impl Euclid for i8

source§

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

source§

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

source§

impl Euclid for u128

source§

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

source§

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

source§

impl Euclid for u16

source§

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

source§

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

source§

impl Euclid for i32

source§

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

source§

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

source§

impl Euclid for u32

source§

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

source§

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

source§

impl Euclid for i64

source§

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

source§

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

Implementors§