gul-cpp / gul14

General Utility Library for C++14
https://gul14.info/
GNU Lesser General Public License v2.1
2 stars 1 forks source link

Add gcd() and lcm() #11

Closed alt-graph closed 2 years ago

alt-graph commented 2 years ago

These functions can calculate the greatest common divisor and least common multiple of two integers.

They are very similar to the C++17 functions std::gcd() and std::lcm(), but do not work with integers of different signedness – a static_assert prevents that. This makes them safer to use because the standard versions cause UB when used with one unsigned integer and one negative integer.