Proto
Proto_PowerItoI.H
1 #ifndef _PROTO_POWERITOI_H_
2 #define _PROTO_POWERITOI_H_
3 
4 #include <cassert>
5 #include <cmath>
6 
7 namespace Proto {
8 
10 template <unsigned int P>
11 inline int ipow(int M){return M*ipow<P-1>(M);}
12 
13 template <>
14 inline int ipow<0>(int M){return 1;}
15 } //end Proto namespace
16 
17 // Dynamic version
18 inline int ipow(int a_base, unsigned int a_exp)
19 {
20  int result = 1;
21  for(;;)
22  {
23  if (a_exp & 1){result *= a_base;}
24  a_exp >>= 1;
25  if (!a_exp){break;}
26  a_base *= a_base;
27  }
28  return result;
29 }
30 
31 #endif //end include guard
Definition: Proto_Box.H:11
int ipow(int M)
Template Based Integer Exponentiation.
Definition: Proto_PowerItoI.H:11