Proto  3.2
Proto_Math.H
Go to the documentation of this file.
1 #ifndef _PROTO_MATH_H_
2 #define _PROTO_MATH_H_
3 
4 namespace Proto {
5 
6  /// Template Based Integer Exponentiation
7  template <unsigned int P>
8  inline int ipow(int M){return M*ipow<P-1>(M);}
9 
10  template <>
11  inline int ipow<0>(int M){return 1;}
12 
13  // Dynamic version
14  inline int ipow(int a_base, unsigned int a_exp)
15  {
16  int result = 1;
17  for(;;)
18  {
19  if (a_exp & 1){result *= a_base;}
20  a_exp >>= 1;
21  if (!a_exp){break;}
22  a_base *= a_base;
23  }
24  return result;
25  }
26 
27  inline int factorial(int value)
28  {
29  if (value == 0) { return 1; }
30  else { return value * factorial(value - 1); }
31  }
32 
33  template<typename T>
34  inline T taylor(int index)
35  {
36  return 1.0/((T)factorial(index));
37  }
38 
39 } //end Proto namespace
40 
41 #endif //end include guard
int factorial(int value)
Definition: Proto_Math.H:27
int ipow< 0 >(int M)
Definition: Proto_Math.H:11
T taylor(int index)
Definition: Proto_Math.H:34
Definition: Proto_Array.H:17
uint64_t index
Definition: Proto_MBBoxPartition.H:15
int ipow(int M)
Template Based Integer Exponentiation.
Definition: Proto_Math.H:8