Version: SMASH-3.1
pow.h
Go to the documentation of this file.
1 /*
2  *
3  * Copyright (c) 2016-2018,2020,2022
4  * SMASH Team
5  *
6  * GNU General Public License (GPLv3 or later)
7  *
8  */
9 
10 #ifndef SRC_INCLUDE_SMASH_POW_H_
11 #define SRC_INCLUDE_SMASH_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) ? 1
25  : (exponent % 2 == 0)
26  ? pow_int(base, exponent / 2) * pow_int(base, exponent / 2)
27  : base * pow_int(base, exponent - 1);
28 }
29 
36 template <class T>
37 inline constexpr T square(const T base) {
38  return pow_int(base, 2);
39 }
40 
41 } // namespace smash
42 
43 #endif // SRC_INCLUDE_SMASH_POW_H_
Definition: action.h:24
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:37