maths: move more operations into util::

This commit is contained in:
Danny Robson 2015-11-13 17:13:38 +11:00
parent 7b083df977
commit 89fe57b65b
3 changed files with 12 additions and 16 deletions

View File

@ -75,7 +75,7 @@ template uint64_t log2 (uint64_t);
template <typename T> template <typename T>
double double
rootsquare (T a, T b) rootsquare (T a, T b)
{ return sqrt (pow2 (a) + pow2 (b)); } { return sqrt (util::pow2 (a) + util::pow2 (b)); }
template double rootsquare (double, double); template double rootsquare (double, double);

View File

@ -26,14 +26,16 @@
#include <type_traits> #include <type_traits>
#include <utility> #include <utility>
template <typename T>
T
abs (T value)
{ return value > 0 ? value : -value; }
///////////////////////////////////////////////////////////////////////////////
namespace util { namespace util {
template <typename T> T abs (T t) { return ::abs<T> (t); } template <typename T>
T
abs [[gnu::const]] (T t)
{
return t > 0 ? t : -t;
}
} }
@ -47,17 +49,11 @@ namespace util {
{ return value * value; } { return value * value; }
} }
template <typename T> constexpr T pow2 [[gnu::const]] (T value) { return util::pow2 (value); }
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
template <typename T>
constexpr T
pow [[gnu::const]] (T x, unsigned y);
namespace util { namespace util {
template <typename T> template <typename T>
constexpr T pow (T x, unsigned y) { return ::pow (x, y); } constexpr T
pow [[gnu::const]] (T x, unsigned y);
} }

View File

@ -26,12 +26,12 @@
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
template <typename T> template <typename T>
constexpr T constexpr T
pow (T x, unsigned y) util::pow (T x, unsigned y)
{ {
if (y == 0) if (y == 0)
return T(1); return T(1);
return x * ::pow (x, y - 1); return x * util::pow (x, y - 1);
} }