From 34d002754b3ca78eae7c67b57d761cba5ee8da9d Mon Sep 17 00:00:00 2001 From: Benjamin Valentin Date: Wed, 22 Mar 2023 14:28:11 +0100 Subject: [PATCH] imath: add powi() function --- sys/include/imath.h | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/sys/include/imath.h b/sys/include/imath.h index b4175280dc..1f2ff5fcb1 100644 --- a/sys/include/imath.h +++ b/sys/include/imath.h @@ -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