31#ifndef ETL_GCD_INCLUDED
32#define ETL_GCD_INCLUDED
36#include "static_assert.h"
45 template <
intmax_t Value1,
intmax_t Value2>
48 static ETL_CONSTANT intmax_t value = gcd_const<Value2, Value1 % Value2>::value;
51 template <
intmax_t Value1>
54 static ETL_CONSTANT intmax_t value = Value1;
62 ETL_NODISCARD ETL_CONSTEXPR14
typename etl::enable_if<etl::is_unsigned<T>::value, T>
::type gcd(T a, T b) ETL_NOEXCEPT
64 ETL_STATIC_ASSERT(etl::is_integral<T>::value,
"Integral type required");
66 if ((a == 0 || b == 0))
86 ETL_NODISCARD ETL_CONSTEXPR14
typename etl::enable_if<etl::is_signed<T>::value, T>::type gcd(T a, T b) ETL_NOEXCEPT
88 ETL_STATIC_ASSERT(etl::is_integral<T>::value,
"Integral type required");
90 typedef typename etl::make_unsigned<T>::type utype;
92 utype ua = etl::absolute_unsigned(a);
93 utype ub = etl::absolute_unsigned(b);
95 return static_cast<T
>(gcd(ua, ub));
99 #if ETL_HAS_INITIALIZER_LIST
105 template <
typename T,
typename... TRest>
106 ETL_NODISCARD ETL_CONSTEXPR14 T gcd(T first, TRest... rest) ETL_NOEXCEPT
110 for (T value : {rest...})
112 result = gcd(result, value);
130 template <
typename T,
typename... TRest>
131 ETL_NODISCARD ETL_CONSTEXPR14 T gcd(T a, T b, TRest... rest) ETL_NOEXCEPT
133 T gcd_ab = gcd(a, b);
143 return gcd(gcd_ab, rest...);
bitset_ext
Definition absolute.h:40