Tatooine
include
tatooine
pow.h
Go to the documentation of this file.
1
#ifndef TATOOINE_POW_H
2
#define TATOOINE_POW_H
3
//==============================================================================
4
#include <concepts>
5
//==============================================================================
6
namespace
tatooine
{
7
//==============================================================================
8
template
<std::
int
egral Int>
9
constexpr
auto
pow
(Int x, std::unsigned_integral
auto
const
p) -> Int {
10
if
(p == 0) {
11
return
1;
12
}
13
if
(p == 1) {
14
return
x;
15
}
16
17
auto
const
tmp =
pow
(x, p / 2);
18
if
(p % 2 == 0) {
19
return
tmp * tmp;
20
}
else
{
21
return
x * tmp * tmp;
22
}
23
}
24
//==============================================================================
25
}
// namespace tatooine
26
//==============================================================================
27
#endif
tatooine
Definition:
algorithm.h:6
tatooine::pow
constexpr auto pow(arithmetic auto const x)
Definition:
math.h:30
Generated by
1.9.5