QuadExpr.h
Go to the documentation of this file.
1 // Christopher Backhouse - bckhouse@fnal.gov
2 
3 #ifndef QUADEXPR_H
4 #define QUADEXPR_H
5 
6 #include <iosfwd>
7 
8 class QuadExpr
9 {
10 public:
11  QuadExpr(double v) : a(0), b(0), c(v) {}
12  // Named constructor for independent variable
13  static QuadExpr X();
14 
15  double Quadratic() const {return a;}
16  double Linear() const {return b;}
17  double Constant() const {return c;}
18 
19  double Eval(double x) const;
20 
21  QuadExpr& operator+=(const QuadExpr& e);
22  QuadExpr& operator-=(const QuadExpr& e);
23  QuadExpr& operator*=(const QuadExpr& e);
24 
25  QuadExpr operator+(const QuadExpr& e) const;
26  QuadExpr operator-(const QuadExpr& e) const;
27  QuadExpr operator*(const QuadExpr& e) const;
28 
29  QuadExpr operator+(double v) const {return (*this)+QuadExpr(v);}
30  QuadExpr operator-(double v) const {return (*this)-QuadExpr(v);}
31  QuadExpr operator*(double v) const {return (*this)*QuadExpr(v);}
32 
33 protected:
34  double a, b, c; // a*x^2 + b*x + c
35 };
36 
37 inline QuadExpr operator+(double v, const QuadExpr& e){return e+v;}
38 inline QuadExpr operator-(double v, const QuadExpr& e){return QuadExpr(v)-e;}
39 inline QuadExpr operator*(double v, const QuadExpr& e){return e*v;}
40 
41 std::ostream& operator<<(std::ostream&, const QuadExpr&);
42 
43 #endif
QuadExpr & operator-=(const QuadExpr &e)
Definition: QuadExpr.cxx:30
QuadExpr operator*(double v) const
Definition: QuadExpr.h:31
QuadExpr(double v)
Definition: QuadExpr.h:11
QuadExpr operator*(const QuadExpr &e) const
Definition: QuadExpr.cxx:45
QuadExpr operator-(double v) const
Definition: QuadExpr.h:30
QuadExpr & operator+=(const QuadExpr &e)
Definition: QuadExpr.cxx:15
double Linear() const
Definition: QuadExpr.h:16
QuadExpr operator+(double v) const
Definition: QuadExpr.h:29
double a
Definition: QuadExpr.h:34
double c
Definition: QuadExpr.h:34
QuadExpr operator-(const QuadExpr &e) const
Definition: QuadExpr.cxx:38
double b
Definition: QuadExpr.h:34
const double e
QuadExpr & operator*=(const QuadExpr &e)
Definition: QuadExpr.cxx:63
static QuadExpr X()
Definition: QuadExpr.cxx:8
double Constant() const
Definition: QuadExpr.h:17
double Eval(double x) const
Definition: QuadExpr.cxx:69
std::ostream & operator<<(std::ostream &, const QuadExpr &)
Definition: QuadExpr.cxx:74
list x
Definition: train.py:276
QuadExpr operator+(const QuadExpr &e) const
Definition: QuadExpr.cxx:23
double Quadratic() const
Definition: QuadExpr.h:15