CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
SimplifyNumerical.h
Go to the documentation of this file.
1 #ifndef PhysicsTools_Utilities_SimplifyNumerical_h
2 #define PhysicsTools_Utilities_SimplifyNumerical_h
5 
6 namespace funct {
7 
8  template<int n, int m>
9  struct Sum<Numerical<n>, Numerical<m> > {
11  inline static type combine(const Numerical<n>&, const Numerical<m>&)
12  { return type(); }
13  };
14 
15  template<int n, int m>
16  struct Difference<Numerical<n>, Numerical<m> > {
17  typedef Numerical<n - m> type;
18  inline static type combine(const Numerical<n>&, const Numerical<m>&)
19  { return type(); }
20  };
21 
22 template<int n>
23  struct Minus<Numerical<n> > {
24  typedef Numerical<- n> type;
25  inline static type operate(const Numerical<n>&)
26  { return type(); }
27  };
28 
29  template<int n, int m>
30  struct Product<Numerical<n>, Numerical<m> > {
32  inline static type combine(const Numerical<n>&, const Numerical<m>&)
33  { return type(); }
34  };
35 
36  template<int n>
37  struct Ratio<Numerical<n>, Numerical<1> > {
38  typedef Numerical<n> type;
39  inline static type combine(const Numerical<n>&, const Numerical<1>&)
40  { return type(); }
41  };
42 
43  // n ^ m = n * n ^ ( m - 1 )
44  template<int n, int m, bool posM = (m > 0)>
45  struct NumPower {
47  inline static type combine(const Numerical<n>&, const Numerical<m>&)
48  { return type(); }
49  };
50 
51  // 1 ^ m = 1
52  template<int m, bool posM>
53  struct NumPower<1, m, posM> {
54  typedef Numerical<1> type;
55  inline static type combine(const Numerical<1>&, const Numerical<m>&)
56  { return type(); }
57  };
58 
59  // n ^ 1 = n
60  template<int n>
61  struct NumPower<n, 1, true> {
62  typedef Numerical<n> type;
63  inline static type combine(const Numerical<n>&, const Numerical<1>&)
64  { return type(); }
65  };
66 
67  // n ^ 0 = 1
68  template<int n>
69  struct NumPower<n, 0, true> {
70  typedef Numerical<1> type;
71  inline static type combine(const Numerical<n>&, const Numerical<0>&)
72  { return type(); }
73  };
74 
75  // n ^ (-m) = 1 / n ^ m
76  template<int n, int m>
77  struct NumPower<n, m, false> {
78  typedef typename Fraction<1, NumPower<n, -m>::type::value>::type type;
79  inline static type combine(const Numerical<n>&, const Numerical<m>&)
80  { return type(); }
81  };
82 
83  template<int n, int m>
84  struct Power<Numerical<n>, Numerical<m> > : public NumPower<n, m> {
85  };
86 
87 
88 }
89 
90 #endif
static type combine(const Numerical< n > &, const Numerical< 1 > &)
static type combine(const Numerical< n > &, const Numerical< m > &)
static type combine(const Numerical< n > &, const Numerical< 1 > &)
static type combine(const Numerical< n > &, const Numerical< m > &)
ProductStruct< A, B > type
Definition: Product.h:27
static type combine(const Numerical< n > &, const Numerical< 0 > &)
MinusStruct< A > type
Definition: Minus.h:27
static type combine(const Numerical< n > &, const Numerical< m > &)
SumStruct< A, B > type
Definition: Sum.h:28
static type operate(const Numerical< n > &)
RatioStruct< A, B > type
Definition: Ratio.h:27
Sum< A, typename Minus< B >::type >::type type
Definition: Difference.h:10
arg type
Definition: Factorize.h:37
static type combine(const Numerical< n > &, const Numerical< m > &)
Definition: Sum.h:27
Numerical< n *NumPower< n, m-1 >::type::value > type
Fraction< 1, NumPower< n,-m >::type::value >::type type
static type combine(const Numerical< n > &, const Numerical< m > &)
static type combine(const Numerical< 1 > &, const Numerical< m > &)