Version: SMASH-1.5
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_
constexpr T pow_int(const T base, unsigned const exponent)
Efficient template for calculating integer powers using squaring.
Definition: pow.h:23
constexpr T square(const T base)
Efficient template for calculating the square.
Definition: pow.h:38
Definition: action.h:24