diff --git a/maths.hpp b/maths.hpp index 94991d72..d896c90e 100644 --- a/maths.hpp +++ b/maths.hpp @@ -101,6 +101,21 @@ unsigned digits [[gnu::pure]] (const T& value); +//----------------------------------------------------------------------------- +// factorisation +template +constexpr T +gcd (T a, T b) +{ + if (a == b) return a; + + if (a > b) return gcd (a - b, b); + if (b > a) return gcd (a, b - a); + + unreachable (); +} + + //----------------------------------------------------------------------------- constexpr int sign (int); constexpr float sign (float);