File indexing completed on 2024-04-06 12:24:21
0001 #ifndef PhysicsTools_Utilities_SimplifyNumerical_h
0002 #define PhysicsTools_Utilities_SimplifyNumerical_h
0003 #include "PhysicsTools/Utilities/interface/Fraction.h"
0004 #include "PhysicsTools/Utilities/interface/Numerical.h"
0005 #include "PhysicsTools/Utilities/interface/Operations.h"
0006
0007 namespace funct {
0008
0009 template <int n, int m>
0010 struct Sum<Numerical<n>, Numerical<m> > {
0011 typedef Numerical<n + m> type;
0012 inline static type combine(const Numerical<n>&, const Numerical<m>&) { return type(); }
0013 };
0014
0015 template <int n, int m>
0016 struct Difference<Numerical<n>, Numerical<m> > {
0017 typedef Numerical<n - m> type;
0018 inline static type combine(const Numerical<n>&, const Numerical<m>&) { return type(); }
0019 };
0020
0021 template <int n>
0022 struct Minus<Numerical<n> > {
0023 typedef Numerical<-n> type;
0024 inline static type operate(const Numerical<n>&) { return type(); }
0025 };
0026
0027 template <int n, int m>
0028 struct Product<Numerical<n>, Numerical<m> > {
0029 typedef Numerical<n * m> type;
0030 inline static type combine(const Numerical<n>&, const Numerical<m>&) { return type(); }
0031 };
0032
0033 template <int n>
0034 struct Ratio<Numerical<n>, Numerical<1> > {
0035 typedef Numerical<n> type;
0036 inline static type combine(const Numerical<n>&, const Numerical<1>&) { return type(); }
0037 };
0038
0039
0040 template <int n, int m, bool posM = (m > 0)>
0041 struct NumPower {
0042 typedef Numerical<n * NumPower<n, m - 1>::type::value> type;
0043 inline static type combine(const Numerical<n>&, const Numerical<m>&) { return type(); }
0044 };
0045
0046
0047 template <int m, bool posM>
0048 struct NumPower<1, m, posM> {
0049 typedef Numerical<1> type;
0050 inline static type combine(const Numerical<1>&, const Numerical<m>&) { return type(); }
0051 };
0052
0053
0054 template <int n>
0055 struct NumPower<n, 1, true> {
0056 typedef Numerical<n> type;
0057 inline static type combine(const Numerical<n>&, const Numerical<1>&) { return type(); }
0058 };
0059
0060
0061 template <int n>
0062 struct NumPower<n, 0, true> {
0063 typedef Numerical<1> type;
0064 inline static type combine(const Numerical<n>&, const Numerical<0>&) { return type(); }
0065 };
0066
0067
0068 template <int n, int m>
0069 struct NumPower<n, m, false> {
0070 typedef typename Fraction<1, NumPower<n, -m>::type::value>::type type;
0071 inline static type combine(const Numerical<n>&, const Numerical<m>&) { return type(); }
0072 };
0073
0074 template <int n, int m>
0075 struct Power<Numerical<n>, Numerical<m> > : public NumPower<n, m> {};
0076
0077 }
0078
0079 #endif