![]() |
General Utility Library for C++17 25.4.1
|
Greatest common divisor and least common multiple.
Functions | |
template<typename IntTypeA , typename IntTypeB > | |
constexpr auto | gul17::gcd (IntTypeA a, IntTypeB b) |
Calculate the greatest common divisor of two integers using the Euclidean algorithm. | |
template<typename IntTypeA , typename IntTypeB > | |
constexpr auto | gul17::lcm (IntTypeA a, IntTypeB b) |
Calculate the least common multiple of two integers. | |
Calculate the greatest common divisor of two integers using the Euclidean algorithm.
If both numbers are zero, the function returns zero. Otherwise, the result is a positive integer.
std::common_type_t<IntTypeA, IntTypeB>
) that both inputs can implicitly be converted to. If either a, b, or the result can not be represented by that type, the result is undefined.std::gcd()
from C++17, the GUL17 version cannot be used with integers of different signedness. This avoids undefined behavior when mixing unsigned integers with negative signed values: References gul17::abs(), and gul17::bit_set().
Referenced by gul17::lcm().
Calculate the least common multiple of two integers.
If both numbers are zero, the function returns zero. Otherwise, the result is a positive integer.
std::common_type_t<IntTypeA, IntTypeB>
) that both inputs can implicitly be converted to. If either a, b, or the result can not be represented by that type, the result is undefined.std::lcm()
from C++17, the GUL17 version cannot be used with integers of different signedness. This avoids undefined behavior when mixing unsigned integers with negative signed values: References gul17::abs(), gul17::bit_set(), and gul17::gcd().