Trait Euclid
trait Euclid: Sized + Div<Self, Output = Self> + Rem<Self, Output = Self>
Required Methods
fn div_euclid(self: &Self, v: &Self) -> SelfCalculates Euclidean division, the matching method for
rem_euclid.This computes the integer
nsuch thatself = n * v + self.rem_euclid(v). In other words, the result isself / vrounded to the integernsuch thatself >= n * v.Examples
use Euclid; let a: i32 = 7; let b: i32 = 4; assert_eq!; // 7 > 4 * 1 assert_eq!; // -7 >= 4 * -2 assert_eq!; // 7 >= -4 * -1 assert_eq!; // -7 >= -4 * 2fn rem_euclid(self: &Self, v: &Self) -> SelfCalculates the least nonnegative remainder of
self (mod v).In particular, the return value
rsatisfies0.0 <= r < v.abs()in most cases. However, due to a floating point round-off error it can result inr == v.abs(), violating the mathematical definition, ifselfis much smaller thanv.abs()in magnitude andself < 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 propertyself == self.div_euclid(v) * v + self.rem_euclid(v)approximatively.Examples
use Euclid; let a: i32 = 7; let b: i32 = 4; assert_eq!; assert_eq!; assert_eq!; assert_eq!;
Provided Methods
fn div_rem_euclid(self: &Self, v: &Self) -> (Self, Self)Returns both the quotient and remainder from Euclidean division.
By default, it internally calls both
Euclid::div_euclidandEuclid::rem_euclid, but it can be overridden in order to implement some optimization.Examples
# use Euclid; let x = 5u8; let y = 3u8; let div = div_euclid; let rem = rem_euclid; assert_eq!;
Implementors
impl Euclid for i8impl Euclid for usizeimpl Euclid for u128impl Euclid for isizeimpl Euclid for i128impl Euclid for u64impl Euclid for i64impl Euclid for u32impl Euclid for i32impl Euclid for u16impl Euclid for f64impl Euclid for i16impl Euclid for u8impl Euclid for f32