SoftSUSY is hosted by Hepforge, IPPP Durham
SOFTSUSY  4.0
mycomplex.h
Go to the documentation of this file.
1 
10 #ifndef COMPLEX_H
11 #define COMPLEX_H
12 
13 #include <iosfwd>
14 #include <complex>
15 
17 class Complex : public std::complex<double> {
18 public:
20  Complex(double r = 0.0, double i = 0.0) : std::complex<double>(r,i) {}
22  Complex(const std::complex<double> & cc) : std::complex<double>(cc) {}
23 
24  //Copy constructor and assignment operator are automatically created from base class
25  //real() and imag() taken from base class
26 
27  /**** never used, can be replaced with call to constructor if needed in future***
28  void setRe(double a) { *this = Complex(a,imag()); }///< sets real part
29  void setIm(double a) { *this = Complex(real(),a); }///< sets imaginary part
30  *********************************************************************************/
31 
32  double mod() const { return std::abs(*this); }
33  double arg() const { return std::arg(*this); }
34 
35  Complex conj() const { return std::conj(*this); }
36  Complex cc() const { return std::conj(*this); }
37 
40  //David: careful, unusual definition!
41  bool operator>=(const Complex & a) const {
42  return (this->real() >= a.real() || this->imag() >= a.imag());
43  }
44 
45  //David: this makes valarray<Complex>::max() in linalg.cpp work Ben's way
46  bool operator<(const Complex & b) const { return (std::abs(*this) < std::abs(b)); }
47 };
48 
50 inline std::ostream & operator <<(std::ostream & left, const Complex & s) {
51  left << s.real();
52  if (s.imag() >= 0.0) left << "+";
53  left << s.imag() << "i";
54  return left;
55 }
56 
58 inline std::istream & operator >> (std::istream & left, Complex & v) {
59  double r, i;
60  left >> r >> i;
61  v = Complex(r,i);
62  return left;
63 }
64 
65 //David: the std:: versions of these work fine
66 inline Complex conj(const Complex &a) { return std::conj(a); }
67 inline Complex log(const Complex &a) { return std::log(a); }
68 inline Complex exp(const Complex &a) { return std::exp(a); }
69 inline Complex sqrt(const Complex &a) { return std::sqrt(a); }
70 
71 #endif
Complex log(const Complex &a)
Principal log.
Definition: mycomplex.h:67
std::ostream & operator<<(std::ostream &left, const Complex &s)
Formatted output.
Definition: mycomplex.h:50
double arg() const
returns angle (in Argand diagram): theta=-pi->pi
Definition: mycomplex.h:33
Complex conj() const
Complex conjugate.
Definition: mycomplex.h:35
bool operator>=(const Complex &a) const
Definition: mycomplex.h:41
Complex(double r=0.0, double i=0.0)
General constructor.
Definition: mycomplex.h:20
double mod() const
returns modulus of number
Definition: mycomplex.h:32
Complex(const std::complex< double > &cc)
Constructor from C++ standard complex class.
Definition: mycomplex.h:22
std::istream & operator>>(std::istream &left, Complex &v)
Formatted input.
Definition: mycomplex.h:58
Complex cc() const
Complex conjugate.
Definition: mycomplex.h:36
drop-in replacement for the original home-grown Complex class
Definition: mycomplex.h:17