CMS 3D CMS Logo

SimplifyNumerical.h
Go to the documentation of this file.
1 #ifndef PhysicsTools_Utilities_SimplifyNumerical_h
2 #define PhysicsTools_Utilities_SimplifyNumerical_h
6 
7 namespace funct {
8 
9  template <int n, int m>
10  struct Sum<Numerical<n>, Numerical<m> > {
12  inline static type combine(const Numerical<n>&, const Numerical<m>&) { return type(); }
13  };
14 
15  template <int n, int m>
17  typedef Numerical<n - m> type;
18  inline static type combine(const Numerical<n>&, const Numerical<m>&) { return type(); }
19  };
20 
21  template <int n>
22  struct Minus<Numerical<n> > {
23  typedef Numerical<-n> type;
24  inline static type operate(const Numerical<n>&) { return type(); }
25  };
26 
27  template <int n, int m>
28  struct Product<Numerical<n>, Numerical<m> > {
30  inline static type combine(const Numerical<n>&, const Numerical<m>&) { return type(); }
31  };
32 
33  template <int n>
34  struct Ratio<Numerical<n>, Numerical<1> > {
35  typedef Numerical<n> type;
36  inline static type combine(const Numerical<n>&, const Numerical<1>&) { return type(); }
37  };
38 
39  // n ^ m = n * n ^ ( m - 1 )
40  template <int n, int m, bool posM = (m > 0)>
41  struct NumPower {
43  inline static type combine(const Numerical<n>&, const Numerical<m>&) { return type(); }
44  };
45 
46  // 1 ^ m = 1
47  template <int m, bool posM>
48  struct NumPower<1, m, posM> {
49  typedef Numerical<1> type;
50  inline static type combine(const Numerical<1>&, const Numerical<m>&) { return type(); }
51  };
52 
53  // n ^ 1 = n
54  template <int n>
55  struct NumPower<n, 1, true> {
56  typedef Numerical<n> type;
57  inline static type combine(const Numerical<n>&, const Numerical<1>&) { return type(); }
58  };
59 
60  // n ^ 0 = 1
61  template <int n>
62  struct NumPower<n, 0, true> {
63  typedef Numerical<1> type;
64  inline static type combine(const Numerical<n>&, const Numerical<0>&) { return type(); }
65  };
66 
67  // n ^ (-m) = 1 / n ^ m
68  template <int n, int m>
69  struct NumPower<n, m, false> {
70  typedef typename Fraction<1, NumPower<n, -m>::type::value>::type type;
71  inline static type combine(const Numerical<n>&, const Numerical<m>&) { return type(); }
72  };
73 
74  template <int n, int m>
75  struct Power<Numerical<n>, Numerical<m> > : public NumPower<n, m> {};
76 
77 } // namespace funct
78 
79 #endif
static type combine(const Numerical< n > &, const Numerical< 1 > &)
Definition: Abs.h:5
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:18
static type combine(const Numerical< n > &, const Numerical< 0 > &)
MinusStruct< A > type
Definition: Minus.h:19
static type combine(const Numerical< n > &, const Numerical< m > &)
SumStruct< A, B > type
Definition: Sum.h:19
static type operate(const Numerical< n > &)
RatioStruct< A, B > type
Definition: Ratio.h:18
Sum< A, typename Minus< B >::type >::type type
Definition: Difference.h:10
arg type
Definition: Factorize.h:32
static type combine(const Numerical< n > &, const Numerical< m > &)
Definition: Sum.h:18
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 > &)