maths: add gcd implementation
This commit is contained in:
parent
991558fc7f
commit
0533e3caaf
15
maths.hpp
15
maths.hpp
@ -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);
|
||||||
|
Loading…
Reference in New Issue
Block a user