Diffpack Documentation


Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members   Search  

Complex.h

Go to the documentation of this file.
00001 
00005 class Complex
00006 
00007 {
00008 private:
00009   real re;
00010   real im;
00011 
00012 public:
00013 
00014   inline real Re() const;
00015   inline real Im() const;
00016 
00017   Complex ();
00018   Complex (const Complex& y);
00019   Complex (real   r, real   i=0);
00020   
00021   ~Complex();
00022   
00023   Complex& operator =  (const Complex& y);
00024   Complex& operator += (const Complex& y);
00025   Complex& operator += (real   y);
00026   Complex& operator -= (const Complex& y);
00027   Complex& operator -= (real   y);
00028   Complex& operator *= (const Complex& y);
00029   Complex& operator *= (real   y);
00030   Complex& operator /= (const Complex& y);
00031   Complex& operator /= (real   y);
00032 };
00033 
00034 
00035 
00036 
00037 char*  oform2 (char* s, Complex c);
00038 real   getReal (const Complex& c);
00039 
00040 Complex operator /  (const Complex& x, const Complex& y);
00041 Complex operator /  (const Complex& x, real   y);
00042 Complex operator /  (real     x, const Complex& y);
00043 
00044 Complex cos(const Complex& x);
00045 Complex sin(const Complex& x);
00046 
00047 Complex cosh(const Complex& x);
00048 Complex sinh(const Complex& x);
00049 Complex exp(const Complex& x);
00050 
00051 Complex log(const Complex& x);
00052 
00053 Complex pow(const Complex& x, int p);
00054 Complex pow(const Complex& x, const Complex& p);
00055 Complex pow(const Complex& x, real   y);
00056 Complex sqrt(const Complex& x);
00057 
00058 Is&  operator >> (Is& s, Complex& x);
00059 Os&  operator << (Os& s, const Complex& x);
00060 
00061 
00062 
00063 inline int operator == (const Complex& x, const Complex& y);
00064 inline int operator == (const Complex& x, real   y);
00065 inline int operator != (const Complex& x, const Complex& y);
00066 inline int operator != (const Complex& x, real   y);
00067 inline int operator >  (const Complex& x, const Complex& y);
00068 inline int operator >= (const Complex& x, const Complex& y);
00069 inline int operator <  (const Complex& x, const Complex& y);
00070 inline int operator <= (const Complex& x, const Complex& y);
00071 
00072 inline Complex operator - (const Complex& x);
00073 inline Complex conj(const Complex& x);
00074 inline Complex operator + (const Complex& x, const Complex& y);
00075 inline Complex operator + (const Complex& x, real   y);
00076 inline Complex operator + (real   x, const Complex& y);
00077 inline Complex operator - (const Complex& x, const Complex& y);
00078 inline Complex operator - (const Complex& x, real   y);
00079 inline Complex operator - (real   x, const Complex& y);
00080        Complex operator * (const Complex& x, const Complex& y);
00081 inline Complex operator * (const Complex& x, real   y);
00082 inline Complex operator * (real   x, const Complex& y);
00083 
00084 inline real Re(const Complex& x);
00085 inline real Im(const Complex& x);
00086 inline real abs(const Complex& x);
00087 inline real norm(const Complex& x);
00088 inline real arg(const Complex& x);
00089 
00090 inline Complex  polar(real   r, real   t = 0.0);
00091 
00092 
00093 
00094 
00095 inline real Complex ::Re() const { return re; }
00096 inline real Complex ::Im() const { return im; }
00097 
00098 
00099 
00100 inline Complex ::Complex() { re = im = 0.0; }
00101 inline Complex ::Complex(const Complex& y) :re(y.Re()), im(y.Im()) {}
00102 inline Complex ::Complex(real   r, real   i) :re(r), im(i) {}
00103 
00104 
00105 
00106 inline Complex ::~Complex() {}
00107 
00108 
00109 
00110 inline real Re(const Complex& x)
00111 
00112 {
00113   return x.Re();
00114 }
00115 
00116 
00117 inline real Im(const Complex& x)
00118 
00119 {
00120   return x.Im();
00121 }
00122 
00123 
00124 inline real abs(const Complex& x)
00125 
00126 {
00127   return sqrt(x.Re()*x.Re() + x.Im()*x.Im());
00128 }
00129 
00130 
00131 inline real norm(const Complex& x)
00132 
00133 {
00134   return (x.Re() * x.Re() + x.Im() * x.Im());
00135 }
00136 
00137 
00138 inline real arg(const Complex& x)
00139 
00140 {
00141   return atan2(x.Im(), x.Re());
00142 }
00143 
00144 
00145 inline Complex  polar(real   r, real   t)
00146 
00147 {
00148   return Complex(r * cos(t), r * sin(t));
00149 }
00150 
00151 
00152 inline int operator >  (const Complex& x, const Complex& y)
00153 
00154 {
00155   return (norm(x) > norm(y));
00156 }
00157 
00158 
00159 inline int operator <  (const Complex& x, const Complex& y)
00160 
00161 {
00162   return (norm(x) < norm(y));
00163 }
00164 
00165 
00166 inline int operator >=  (const Complex& x, const Complex& y)
00167 
00168 {
00169   return (norm(x) >= norm(y));
00170 }
00171 
00172 
00173 inline int operator <=  (const Complex& x, const Complex& y)
00174 
00175 {
00176   return (norm(x) <= norm(y));
00177 }
00178 
00179 
00180 inline Complex&  Complex ::operator =  (const Complex& y)
00181 
00182 {
00183   re = y.Re(); im = y.Im(); return *this;
00184 }
00185 
00186 
00187 inline Complex&  Complex ::operator += (const Complex& y)
00188 
00189 {
00190   re += y.Re();  im += y.Im(); return *this;
00191 }
00192 
00193 
00194 inline Complex&  Complex ::operator += (real   y)
00195 
00196 {
00197   re += y; return *this;
00198 }
00199 
00200 
00201 inline Complex&  Complex ::operator -= (const Complex& y)
00202 
00203 {
00204   re -= y.Re();  im -= y.Im(); return *this;
00205 }
00206 
00207 
00208 inline Complex&  Complex ::operator -= (real   y)
00209 
00210 {
00211   re -= y; return *this;
00212 }
00213 
00214 
00215 inline Complex&  Complex ::operator *= (const Complex& y)
00216 
00217 {
00218   real   r = re * y.Re() - im * y.Im();
00219   im = re * y.Im() + im * y.Re();
00220   re = r;
00221   return *this;
00222 }
00223 
00224 
00225 inline Complex&  Complex ::operator *= (real   y)
00226 
00227 {
00228   re *=  y; im *=  y; return *this;
00229 }
00230 
00231 
00232 
00233 
00234 inline int  operator == (const Complex& x, const Complex& y)
00235 
00236 {
00237   return x.Re() == y.Re() && x.Im() == y.Im();
00238 }
00239 
00240 
00241 inline int  operator == (const Complex& x, real   y)
00242 
00243 {
00244   return x.Im() == 0.0 && x.Re() == y;
00245 }
00246 
00247 
00248 inline int  operator != (const Complex& x, const Complex& y)
00249 
00250 {
00251   return x.Re() != y.Re() || x.Im() != y.Im();
00252 }
00253 
00254 
00255 inline int  operator != (const Complex& x, real   y)
00256 
00257 {
00258   return x.Im() != 0.0 || x.Re() != y;
00259 }
00260 
00261 
00262 inline Complex  operator - (const Complex& x)
00263 
00264 {
00265   return Complex(-x.Re(), -x.Im());
00266 }
00267 
00268 
00269 inline Complex  conj(const Complex& x)
00270 
00271 {
00272   return Complex(x.Re(), -x.Im());
00273 }
00274 
00275 
00276 inline Complex  operator + (const Complex& x, const Complex& y)
00277 
00278 {
00279   return Complex(x.Re() + y.Re(), x.Im() + y.Im());
00280 }
00281 
00282 
00283 inline Complex  operator + (const Complex& x, real   y)
00284 
00285 {
00286   return Complex(x.Re() + y, x.Im());
00287 }
00288 
00289 
00290 inline Complex  operator + (real   x, const Complex& y)
00291 
00292 {
00293   return Complex(x + y.Re(), y.Im());
00294 }
00295 
00296 
00297 inline Complex  operator - (const Complex& x, const Complex& y)
00298 
00299 {
00300   return Complex(x.Re() - y.Re(), x.Im() - y.Im());
00301 }
00302 
00303 
00304 inline Complex  operator - (const Complex& x, real   y)
00305 
00306 {
00307   return Complex(x.Re() - y, x.Im());
00308 }
00309 
00310 
00311 inline Complex  operator - (real   x, const Complex& y)
00312 
00313 {
00314   return Complex(x - y.Re(), -y.Im());
00315 }
00316 
00317 
00318 inline Complex  operator * (const Complex& x, real   y)
00319 
00320 {
00321   return Complex(x.Re() * y, x.Im() * y);
00322 }
00323 
00324 
00325 inline Complex  operator * (real   x, const Complex& y)
00326 
00327 {
00328   return Complex(x * y.Re(), x * y.Im());
00329 }
00330 
00331 
00332 
00333 
00334 
00335 
00336 inline Complex sqr     (Complex a)         { return a*a; }
00337 inline Complex pow3    (Complex a)         { return a*a*a; }
00338 inline Complex pow4    (Complex a)         { Complex b = a*a; return b*b; }
00339 
00340 extern Complex pow_int  (Complex a, int i);  
00341 extern bool eq (Complex a, Complex b, real tol = comparison_tolerance);
00342 extern bool lt (Complex a, Complex b, real tol = comparison_tolerance);
00343 extern bool le (Complex a, Complex b, real tol = comparison_tolerance);
00344 
00345 #ifdef WIN32
00346 #undef min
00347 #undef max
00348 #endif
00349 
00350 inline Complex min(Complex arg1, Complex arg2)
00351 { return  (arg1 < arg2) ? arg1 : arg2; }
00352 
00353 inline Complex max(Complex arg1, Complex arg2)
00354 { return  (arg1 > arg2) ? arg1 : arg2; }
00355 
00356 
00357 

Copyright © 2003 inuTech GmbH. All rights reserved.