GLAC  1.0
complex.h
Go to the documentation of this file.
1 
11 #ifndef COMPLEX_H
12 #define COMPLEX_H
13 
14 #include <iostream>
15 
16 class complex
17 {
18 public:
19  complex();
20  ~complex();
21  complex(double real, double imag);
22 
23  complex (const complex &b); // Copy constructor
24 
25  double z[2];
26  double re() const { return z[0]; }
27  double im() const { return z[1]; }
28  void setRe(double re) { z[0] = re; }
29  void setIm(double im) { z[1] = im; }
30 
31  complex &operator =(const complex& b);
33  complex &operator+=(double b);
35  complex &operator-=(double b);
37  complex &operator*=(double b);
39  complex &operator/=(double b);
40  complex operator-() const;
41 
42  double norm();
43  double normSquared();
45  complex c();
46  complex zeros();
47 
48  friend std::ostream& operator<<(std::ostream& os, const complex& a);
49 };
50 
52 {
53  a += b;
54  return a;
55 }
56 
57 inline complex operator+(complex a, double b)
58 {
59  a += b;
60  return a;
61 }
62 
64 {
65  a -= b;
66  return a;
67 }
68 
69 inline complex operator-(complex a, double b)
70 {
71  a -= b;
72  return a;
73 }
74 
76 {
77  a *= b;
78  return a;
79 }
80 
81 inline complex operator*(complex a, double b)
82 {
83  a *= b;
84  return a;
85 }
86 
88 {
89  a /= b;
90  return a;
91 }
92 
93 inline complex operator/(complex a, double b)
94 {
95  a /= b;
96  return a;
97 }
98 
99 #endif // COMPLEX_H
complex operator+(complex a, complex b)
Definition: complex.h:51
A complex number class, consisting of t.
Definition: complex.h:16
double re() const
Definition: complex.h:26
void setIm(double im)
Definition: complex.h:29
double norm()
Definition: complex.cpp:45
void setRe(double re)
Definition: complex.h:28
complex zeros()
Definition: complex.cpp:86
friend std::ostream & operator<<(std::ostream &os, const complex &a)
Definition: complex.cpp:191
complex operator/(complex a, complex b)
Definition: complex.h:87
complex & operator=(const complex &b)
Definition: complex.cpp:93
complex operator *(complex a, complex b)
Definition: complex.h:75
complex & operator/=(complex b)
Definition: complex.cpp:136
complex operator-(complex a, complex b)
Definition: complex.h:63
double normSquared()
Definition: complex.cpp:53
~complex()
Definition: complex.cpp:19
complex conjugate()
complex::conjugate
Definition: complex.cpp:65
double z[2]
Definition: complex.h:25
complex & operator-=(complex b)
Definition: complex.cpp:158
complex()
Definition: complex.cpp:10
complex & operator *=(complex b)
Definition: complex.cpp:113
complex operator-() const
Definition: complex.cpp:186
complex & operator+=(complex b)
Definition: complex.cpp:103
double im() const
Definition: complex.h:27
complex c()
complex::c
Definition: complex.cpp:78