Algorithms

template<typename T1, typename T2>
constexpr common_t<T1, T2> gcd(const T1 a, const T2 b) noexcept

Compile-time greatest common divisor (GCD) function.

Parameters
  • a – integral-valued input.

  • b – integral-valued input.

Returns

the greatest common divisor between integers a and b using a Euclidean algorithm.

template<typename T1, typename T2>
constexpr common_t<T1, T2> lcm(const T1 a, const T2 b) noexcept

Compile-time least common multiple (LCM) function.

Parameters
  • a – integral-valued input.

  • b – integral-valued input.

Returns

the least common multiple between integers a and b using the representation

\[ \text{lcm}(a,b) = \dfrac{| a b |}{\text{gcd}(a,b)} \]
where \( \text{gcd}(a,b) \) denotes the greatest common divisor between \( a \) and \( b \).