Version: SMASH-1.6
pow.h
Go to the documentation of this file.
1
/*
2
*
3
* Copyright (c) 2016-2018
4
* SMASH Team
5
*
6
* GNU General Public License (GPLv3 or later)
7
*
8
*/
9
10
#ifndef SRC_INCLUDE_POW_H_
11
#define SRC_INCLUDE_POW_H_
12
13
namespace
smash
{
14
22
template
<
class
T>
23
inline
constexpr T
pow_int
(
const
T base,
unsigned
const
exponent) {
24
return
(exponent == 0)
25
? 1
26
: (exponent % 2 == 0)
27
?
pow_int
(base, exponent / 2) *
pow_int
(base, exponent / 2)
28
: base *
pow_int
(base, exponent - 1);
29
}
30
37
template
<
class
T>
38
inline
constexpr T
square
(
const
T base) {
39
return
pow_int
(base, 2);
40
}
41
42
}
// namespace smash
43
44
#endif // SRC_INCLUDE_POW_H_
smash::pow_int
constexpr T pow_int(const T base, unsigned const exponent)
Efficient template for calculating integer powers using squaring.
Definition:
pow.h:23
smash::square
constexpr T square(const T base)
Efficient template for calculating the square.
Definition:
pow.h:38
smash
Definition:
action.h:24
src
include
smash
pow.h
Impressum
Data privacy protection
Generated on Fri May 24 2019 16:36:32 for SMASH by
Doxygen
1.8.11