MINT2
Phase.cpp
Go to the documentation of this file.
1 // author: Jonas Rademacker (Jonas.Rademacker@bristol.ac.uk)
2 // status: Mon 9 Feb 2009 19:17:57 GMT
3 #include "Mint/Phase.h"
4 #include <cmath>
6 
7 using namespace std;
8 using namespace MINT;
9 
10 const double Phase::_minPh = 0; // this makes it 0 to 2pi
11 //const double Phase::_minPh = -pi; // this makes it -pi to pi
12 
13 double Phase::rangeMax(){
14  return _minPh + twopi;
15 }
16 double Phase::rangeMin(){
17  return _minPh;
18 }
19 void Phase::toRange(){
20  while (_ph > rangeMax()) _ph -= 2 * pi;
21  while (_ph < rangeMin()) _ph += 2 * pi;
22 }
23 Phase::Phase(const Phase& other)
24  : _ph(other._ph){
25  toRange();
26 }
27 Phase::Phase(double ph_in)
28  : _ph(ph_in){
29  toRange();
30 }
31 Phase& Phase::operator*=(double rhs){
32  _ph *= rhs;
33  toRange();
34  return *this;
35 }
36 Phase& Phase::operator/=(double rhs){
37  _ph /= rhs;
38  toRange();
39  return *this;
40 }
42  _ph += (double) rhs;
43  toRange();
44  return *this;
45 }
46 Phase Phase::operator+(const Phase& rhs) const{
47  Phase newPhase(*this);
48  newPhase += rhs;
49  return newPhase;
50 }
51 const Phase& Phase::operator+() const{
52  return (*this);
53 }
55  _ph -= (double) rhs;
56  _ph = fmod(_ph, twopi);
57  return *this;
58 }
59 Phase Phase::operator-(const Phase& rhs) const{
60  Phase newPhase(*this);
61  newPhase -= rhs;
62  return newPhase;
63 }
65  Phase newPhase(*this);
66  newPhase *= -1.;
67  return newPhase;
68 }
69 double Phase::inDegrees() const{
70  return _ph * 180.0/pi;
71 }
72 
73 void Phase::testPhase(std::ostream& os) const{
74  os << " testing Phase object:" << endl;
75  Phase testPhase(9);
76  os << " testPhase(9) " << testPhase
77  << "( = " << testPhase.inDegrees() << " deg)"
78  << endl;
79  Phase otherPhase(6);
80  os << " otherPhase(3) " << otherPhase
81  << "( = " << otherPhase.inDegrees() << " deg)"
82  << endl;
83 
84  os << " sum of the two ="
85  << (otherPhase + testPhase).inDegrees()
86  << " deg \n difference: "
87  << (otherPhase - testPhase).inDegrees()
88  << " deg \n negative of testPhase "
89  << -testPhase
90  << " = " << (-testPhase).inDegrees()
91  << " deg" << endl;
92  return;
93 }
94 //
Phase & operator/=(double rhs)
Definition: Phase.cpp:36
static const double pi
double _ph
Definition: Phase.h:11
Phase operator-() const
Definition: Phase.cpp:64
void testPhase(std::ostream &os=std::cout) const
Definition: Phase.cpp:73
void toRange()
Definition: Phase.cpp:19
double inDegrees() const
Definition: Phase.cpp:69
static const double twopi
const Phase & operator+() const
Definition: Phase.cpp:51
Phase(const Phase &other)
Definition: Phase.cpp:23
Phase & operator+=(const Phase &rhs)
Definition: Phase.cpp:41
Phase & operator-=(const Phase &rhs)
Definition: Phase.cpp:54
Phase & operator *=(double rhs)
Definition: Phase.cpp:31