diff --git a/include/xerus/misc/math.h b/include/xerus/misc/math.h index 046ab89041bf82be91fe66c8273bbf11cf7f2527..e13ec28efff6285b7b4d8a5b107dbc6690d818e4 100644 --- a/include/xerus/misc/math.h +++ b/include/xerus/misc/math.h @@ -46,35 +46,15 @@ namespace xerus { ///@brief: Calculates _base^_exp by binary exponentiation - template - constexpr T pow(const T& _base, const uint32 _exp) noexcept { - return _exp==0 ? T(1) : (_exp%2==0 ? pow(T(_base*_base), _exp/2) : T(_base*pow(_base, _exp-1))); - } - - ///@brief: Calculates _base^_exp by binary exponentiation - template - constexpr T pow(const T &_base, const uint64 _exp) noexcept { + template::value && std::is_unsigned::value, bool>::type = true> + constexpr T pow(const T &_base, const I _exp) noexcept { return _exp==0 ? T(1) : (_exp%2==0 ? pow(T(_base*_base), _exp/2) : T(_base*pow(_base, _exp-1))); } ///@brief: Calculates _base^_exp by binary exponentiation - template - constexpr T pow(const T &_base, const int64 _exp) noexcept { - return _exp==0 ? - T(1) : - ( - _exp<0 ? - T( 1/pow(_base, -_exp)) - : - ( _exp%2==0 ? pow(T(_base*_base), _exp/2) : T(_base*pow(_base, _exp-1)) ) - ); - } - - - ///@brief: Calculates _base^_exp by binary exponentiation - template - constexpr T pow(const T &_base, const int32 _exp) noexcept { + template::value && !std::is_unsigned::value, bool>::type = true> + constexpr T pow(const T &_base, const I _exp) noexcept { return _exp==0 ? T(1) : (