Skip to main content

Gcd

Trait Gcd 

Source
pub trait Gcd<Other = Self> {
    type Output;

    // Required method
    fn gcd(self, other: Other) -> Self::Output;
}

Required Associated Types§

Required Methods§

Source

fn gcd(self, other: Other) -> Self::Output

Returns greatest common divisor.

use traiter::numbers::Gcd;
// signed integers
assert_eq!(Gcd::gcd(-3i8, 3i8), 3i8);
assert_eq!(Gcd::gcd(-3i8, 2i8), 1i8);
assert_eq!(Gcd::gcd(-3i8, 0i8), 3i8);
// unsigned integers
assert_eq!(Gcd::gcd(3u8, 3u8), 3u8);
assert_eq!(Gcd::gcd(3u8, 2u8), 1u8);
assert_eq!(Gcd::gcd(3u8, 0u8), 3u8);

Dyn Compatibility§

This trait is dyn compatible.

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

Implementations on Foreign Types§

Source§

impl Gcd for i8

Source§

type Output = i8

Source§

fn gcd(self, other: Self) -> Self::Output

Source§

impl Gcd for i16

Source§

type Output = i16

Source§

fn gcd(self, other: Self) -> Self::Output

Source§

impl Gcd for i32

Source§

type Output = i32

Source§

fn gcd(self, other: Self) -> Self::Output

Source§

impl Gcd for i64

Source§

type Output = i64

Source§

fn gcd(self, other: Self) -> Self::Output

Source§

impl Gcd for i128

Source§

type Output = i128

Source§

fn gcd(self, other: Self) -> Self::Output

Source§

impl Gcd for isize

Source§

type Output = isize

Source§

fn gcd(self, other: Self) -> Self::Output

Source§

impl Gcd for u8

Source§

type Output = u8

Source§

fn gcd(self, other: Self) -> Self::Output

Source§

impl Gcd for u16

Source§

type Output = u16

Source§

fn gcd(self, other: Self) -> Self::Output

Source§

impl Gcd for u32

Source§

type Output = u32

Source§

fn gcd(self, other: Self) -> Self::Output

Source§

impl Gcd for u64

Source§

type Output = u64

Source§

fn gcd(self, other: Self) -> Self::Output

Source§

impl Gcd for u128

Source§

type Output = u128

Source§

fn gcd(self, other: Self) -> Self::Output

Source§

impl Gcd for usize

Source§

type Output = usize

Source§

fn gcd(self, other: Self) -> Self::Output

Implementors§