tetl 0.1.0
Embedded Template Library
Loading...
Searching...
No Matches
ipow.hpp
Go to the documentation of this file.
1// SPDX-License-Identifier: BSL-1.0
2
3#ifndef TETL_MATH_IPOW_HPP
4#define TETL_MATH_IPOW_HPP
5
7
8namespace etl {
9
10template <integral Int>
11[[nodiscard]] constexpr auto ipow(Int base, Int exponent) noexcept -> Int
12{
13 auto result = Int(1);
14 for (auto i = Int(0); i < exponent; ++i) {
15 result *= base;
16 }
17 return result;
18}
19
20template <auto Base>
21[[nodiscard]] constexpr auto ipow(decltype(Base) exponent) noexcept -> decltype(Base)
22{
23 using Int = decltype(Base);
24
25 if constexpr (Base == Int(2)) {
26 return static_cast<Int>(Int(1) << exponent);
27 } else {
28 return ipow(Base, exponent);
29 }
30}
31
32} // namespace etl
33
34#endif // TETL_MATH_IPOW_HPP
Definition adjacent_find.hpp:8
constexpr auto ipow(Int base, Int exponent) noexcept -> Int
Definition ipow.hpp:11