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

    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

Implementations on Foreign Types

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.

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.

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.

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.

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.

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.

Implementors