maths: add gcd implementation

This commit is contained in:
Danny Robson 2015-07-13 16:28:16 +10:00
parent 991558fc7f
commit 0533e3caaf

View File

@ -101,6 +101,21 @@ unsigned
digits [[gnu::pure]] (const T& value); digits [[gnu::pure]] (const T& value);
//-----------------------------------------------------------------------------
// factorisation
template <typename T>
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 int sign (int);
constexpr float sign (float); constexpr float sign (float);