Skip to content

Commit

Permalink
imath: add ipow() function
Browse files Browse the repository at this point in the history
  • Loading branch information
benpicco committed Mar 22, 2023
1 parent 382e260 commit 38a96c7
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions sys/include/imath.h
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,25 @@ static inline unsigned isqrt(unsigned x)
return y0;
}

/**
* @brief Returns the value of x to the power of y
*
* @param x base
* @param y exponent
*
* @return x^y
*/
static inline uint32_t ipow(unsigned x, unsigned y)
{
uint32_t res = 1;

while (y--) {
res *= x;
}

return res;
}

#ifdef __cplusplus
}
#endif
Expand Down

0 comments on commit 38a96c7

Please sign in to comment.