Skip to main content

Gcd

Trait Gcd 

Source
pub trait Gcd: Sized {
    // Required method
    fn gcd(&self, other: &Self) -> Option<Self>;
}
Expand description

The greatest common divisor of two numbers, in the integer sense.

The result is the largest g >= 0 for which both values are integer multiples of g. It is zero exactly when both values are, and it is never negative: the sign of the operands says nothing about what divides them.

§What implements it

The rational types of this crate, and only those.

A row whose coefficients are integers wants the same operation, and the routines for it are already in the crate: a binary gcd per machine word, and one over the words of an arbitrary precision integer. Implementing this for the primitive integers and for Ubig is left for when a caller needs it, so a bound of T: Gcd means a rational today.

Required Methods§

Source

fn gcd(&self, other: &Self) -> Option<Self>

The greatest common divisor of two numbers.

None when the result is not representable in this type, which a fixed width type can run into: the denominator of the result is the least common multiple of the two denominators, and that is larger than either of them.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§

Source§

impl Gcd for Rational8

Source§

impl Gcd for Rational16

Source§

impl Gcd for Rational32

Source§

impl Gcd for Rational64

Source§

impl Gcd for Rational128

Source§

impl Gcd for RationalUsize

Source§

impl<const S: usize> Gcd for Big<S>

Never fails: the numerator of the result divides both numerators and the denominator is a product of the two denominators, and neither can run out of room.