diff options
author | Dan Goodliffe <dan@randomdan.homeip.net> | 2024-10-17 02:58:16 +0100 |
---|---|---|
committer | Dan Goodliffe <dan@randomdan.homeip.net> | 2024-10-17 02:59:12 +0100 |
commit | cfec8308a39ae4a2a1a1b1fe0df0a099470d9c78 (patch) | |
tree | fb406218d6d7f79e02331d89e6f0567c386d98e7 /lib/maths.h | |
parent | Don't dump stencil texture (diff) | |
download | ilt-cfec8308a39ae4a2a1a1b1fe0df0a099470d9c78.tar.bz2 ilt-cfec8308a39ae4a2a1a1b1fe0df0a099470d9c78.tar.xz ilt-cfec8308a39ae4a2a1a1b1fe0df0a099470d9c78.zip |
Simple constexpr pow function
Diffstat (limited to 'lib/maths.h')
-rw-r--r-- | lib/maths.h | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/lib/maths.h b/lib/maths.h index 32f2884..97b7ef5 100644 --- a/lib/maths.h +++ b/lib/maths.h @@ -261,6 +261,19 @@ midpoint(const std::pair<T, T> & v) return std::midpoint(v.first, v.second); } +// std::pow is not constexpr +template<typename T> + requires requires(T n) { n *= n; } +constexpr inline T +pow(const T base, std::integral auto exp) +{ + T res {1}; + while (exp--) { + res *= base; + } + return res; +} + // Conversions template<typename T> inline constexpr auto |