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
6
#include <
etl/_concepts/integral.hpp
>
7
8
namespace
etl
{
9
10
template
<
int
egral 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
20
template
<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
integral.hpp
etl
Definition
adjacent_find.hpp:8
etl::ipow
constexpr auto ipow(Int base, Int exponent) noexcept -> Int
Definition
ipow.hpp:11
include
etl
_math
ipow.hpp
Generated on Sat Mar 8 2025 16:19:59 for tetl by
1.14.0