Skip to content

Commit

Permalink
imath: add powi() function
Browse files Browse the repository at this point in the history
  • Loading branch information
benpicco committed Jun 5, 2023
1 parent eefa1b8 commit 34d0027
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 sqrti(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 powi(unsigned x, unsigned y)
{
uint32_t res = 1;

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

return res;
}

#ifdef __cplusplus
}
#endif
Expand Down

0 comments on commit 34d0027

Please sign in to comment.