maths: add integer power operation

This commit is contained in:
Danny Robson 2015-01-21 23:35:34 +11:00
parent d3c300053b
commit 4260c91cd0
2 changed files with 19 additions and 0 deletions

View File

@ -37,6 +37,11 @@ pow2 [[gnu::pure]] (T value)
{ return value * value; }
template <typename T>
T
pow (T x, unsigned y);
template <typename T>
bool
is_pow2 [[gnu::pure]] (T value);

View File

@ -34,3 +34,17 @@ align (T value, U size) {
return divup (value, size) * size;
}
//-----------------------------------------------------------------------------
template <typename T>
T
pow (T x, unsigned y)
{
T v = 1;
for (unsigned i = 1; i <= y; ++i)
v *= x;
return v;
}