Trait CheckedLcm

Source
pub trait CheckedLcm<RHS = Self> {
    type Output;

    // Required method
    fn checked_lcm(self, other: RHS) -> Option<Self::Output>;
}
Expand description

Calculates the LCM (least common multiple) of two numbers, returning None if the result is not representable.

Required Associated Types§

Required Methods§

Source

fn checked_lcm(self, other: RHS) -> Option<Self::Output>

Implementations on Foreign Types§

Source§

impl CheckedLcm for u8

Source§

fn checked_lcm(self, other: u8) -> Option<u8>

Computes the LCM (least common multiple) of two numbers, returning None if the result is too large to represent.

$$ f(x, y) = \begin{cases} \operatorname{Some}(\operatorname{lcm}(x, y)) & \text{if} \quad \operatorname{lcm}(x, y) < 2^W, \\ \operatorname{None} & \text{if} \quad \operatorname{lcm}(x, y) \geq 2^W, \end{cases} $$ where $W$ is Self::WIDTH.

§Worst-case complexity

$T(n) = O(n^2)$

$M(n) = O(n)$

where $T$ is time, $M$ is additional memory, and $n$ is max(self.significant_bits(), other.significant_bits()).

§Examples

See here.

Source§

type Output = u8

Source§

impl CheckedLcm for u16

Source§

fn checked_lcm(self, other: u16) -> Option<u16>

Computes the LCM (least common multiple) of two numbers, returning None if the result is too large to represent.

$$ f(x, y) = \begin{cases} \operatorname{Some}(\operatorname{lcm}(x, y)) & \text{if} \quad \operatorname{lcm}(x, y) < 2^W, \\ \operatorname{None} & \text{if} \quad \operatorname{lcm}(x, y) \geq 2^W, \end{cases} $$ where $W$ is Self::WIDTH.

§Worst-case complexity

$T(n) = O(n^2)$

$M(n) = O(n)$

where $T$ is time, $M$ is additional memory, and $n$ is max(self.significant_bits(), other.significant_bits()).

§Examples

See here.

Source§

type Output = u16

Source§

impl CheckedLcm for u32

Source§

fn checked_lcm(self, other: u32) -> Option<u32>

Computes the LCM (least common multiple) of two numbers, returning None if the result is too large to represent.

$$ f(x, y) = \begin{cases} \operatorname{Some}(\operatorname{lcm}(x, y)) & \text{if} \quad \operatorname{lcm}(x, y) < 2^W, \\ \operatorname{None} & \text{if} \quad \operatorname{lcm}(x, y) \geq 2^W, \end{cases} $$ where $W$ is Self::WIDTH.

§Worst-case complexity

$T(n) = O(n^2)$

$M(n) = O(n)$

where $T$ is time, $M$ is additional memory, and $n$ is max(self.significant_bits(), other.significant_bits()).

§Examples

See here.

Source§

type Output = u32

Source§

impl CheckedLcm for u64

Source§

fn checked_lcm(self, other: u64) -> Option<u64>

Computes the LCM (least common multiple) of two numbers, returning None if the result is too large to represent.

$$ f(x, y) = \begin{cases} \operatorname{Some}(\operatorname{lcm}(x, y)) & \text{if} \quad \operatorname{lcm}(x, y) < 2^W, \\ \operatorname{None} & \text{if} \quad \operatorname{lcm}(x, y) \geq 2^W, \end{cases} $$ where $W$ is Self::WIDTH.

§Worst-case complexity

$T(n) = O(n^2)$

$M(n) = O(n)$

where $T$ is time, $M$ is additional memory, and $n$ is max(self.significant_bits(), other.significant_bits()).

§Examples

See here.

Source§

type Output = u64

Source§

impl CheckedLcm for u128

Source§

fn checked_lcm(self, other: u128) -> Option<u128>

Computes the LCM (least common multiple) of two numbers, returning None if the result is too large to represent.

$$ f(x, y) = \begin{cases} \operatorname{Some}(\operatorname{lcm}(x, y)) & \text{if} \quad \operatorname{lcm}(x, y) < 2^W, \\ \operatorname{None} & \text{if} \quad \operatorname{lcm}(x, y) \geq 2^W, \end{cases} $$ where $W$ is Self::WIDTH.

§Worst-case complexity

$T(n) = O(n^2)$

$M(n) = O(n)$

where $T$ is time, $M$ is additional memory, and $n$ is max(self.significant_bits(), other.significant_bits()).

§Examples

See here.

Source§

type Output = u128

Source§

impl CheckedLcm for usize

Source§

fn checked_lcm(self, other: usize) -> Option<usize>

Computes the LCM (least common multiple) of two numbers, returning None if the result is too large to represent.

$$ f(x, y) = \begin{cases} \operatorname{Some}(\operatorname{lcm}(x, y)) & \text{if} \quad \operatorname{lcm}(x, y) < 2^W, \\ \operatorname{None} & \text{if} \quad \operatorname{lcm}(x, y) \geq 2^W, \end{cases} $$ where $W$ is Self::WIDTH.

§Worst-case complexity

$T(n) = O(n^2)$

$M(n) = O(n)$

where $T$ is time, $M$ is additional memory, and $n$ is max(self.significant_bits(), other.significant_bits()).

§Examples

See here.

Source§

type Output = usize

Implementors§