consteig
Compile-time eigenvalue and eigenvector computation for C++17
Loading...
Searching...
No Matches
include
consteig
math
functions
pow.hpp
1
#ifndef CONSTMATH_POW_HPP
2
#define CONSTMATH_POW_HPP
3
4
namespace
consteig
5
{
6
9
17
template
<
typename
T>
constexpr
T
pow
(
const
T
x
,
const
unsigned
int
n
)
18
{
19
return
n
== 0 ?
static_cast<
T
>
(1)
20
:
n
% 2 == 0 ?
pow
(
x
*
x
,
n
/ 2)
21
:
pow
(
x
*
x
, (
n
- 1) / 2) *
x
;
22
}
23
32
template
<
typename
T>
constexpr
T
pow
(
const
T
x
,
const
int
n
)
33
{
34
return
n < 0 ? static_cast<T>
(1) /
pow
(
x
,
static_cast<
unsigned
int
>
(-
n
))
35
:
pow
(
x
,
static_cast<
unsigned
int
>
(
n
));
36
}
37
39
40
}
// namespace consteig
41
42
#endif
consteig::pow
constexpr T pow(const T x, const unsigned int n)
Raise x to an unsigned integer power via exponentiation by squaring.
Definition
pow.hpp:17
consteig::epsilon
constexpr T epsilon()
Machine epsilon for type T.
Definition
utilities.hpp:82
Generated by
1.10.0