File indexing completed on 2023-03-17 11:16:53
0001 #ifndef PhysicsTools_Utilities_Power_h
0002 #define PhysicsTools_Utilities_Power_h
0003 #include <cmath>
0004
0005 namespace funct {
0006 template <typename A, typename B>
0007 struct PowerStruct {
0008 PowerStruct(const A& a, const B& b) : _1(a), _2(b) {}
0009 double operator()() const { return std::pow(_1(), _2()); }
0010 operator double() const { return std::pow(_1(), _2()); }
0011 double operator()(double x) const { return std::pow(_1(x), _2(x)); }
0012 double operator()(double x, double y) const { return std::pow(_1(x, y), _2(x, y)); }
0013 A _1;
0014 B _2;
0015 };
0016
0017 template <typename A, typename B>
0018 struct Power {
0019 typedef PowerStruct<A, B> type;
0020 static type combine(const A& a, const B& b) { return type(a, b); }
0021 };
0022
0023 template <typename A, typename B>
0024 inline typename Power<A, B>::type operator^(const A& a, const B& b) {
0025 return Power<A, B>::combine(a, b);
0026 }
0027
0028 template <typename A, typename B>
0029 inline typename Power<A, B>::type pow(const A& a, const B& b) {
0030 return Power<A, B>::combine(a, b);
0031 }
0032
0033 }
0034
0035 #endif