Main Page   Modules   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members   Related Pages   Examples  

CTBcomplex.icc

Go to the documentation of this file.
00001 
00006 /*----------------------------------------------------------------------------*/
00007 /* C Tool Box: Designed and implemented by:                                   */
00008 /*    Walter F.J. Mueller   Gesellschaft fuer Schwerionenforschung (GSI)      */
00009 /*                          Postfach 110552, D-64220 Darmstadt, Germany       */
00010 /*                  Email:  W.F.J.Mueller@gsi.de                              */
00011 /*                  WWW:    http://www-kp3.gsi.de/www/kp3/people/mueller.html */
00012 /*------------------------------------------+---------------------------------*/
00013 
00014 #include <math.h>
00015 
00016 #include "CTBtraits.hxx"
00017 #include "CTBmath.hxx"
00018 
00019 //------------------------------------------+-----------------------------------
00021 
00022 template <class T>
00023 inline CTBcomplex<T>::CTBcomplex(T f_re, T f_im)
00024   : mf_re(f_re),
00025     mf_im(f_im)
00026 {}
00027 
00028 //------------------------------------------+-----------------------------------
00030 
00031 template <class T>
00032 inline T& CTBcomplex<T>::Re()
00033 {
00034   return mf_re;
00035 }
00036 
00037 //------------------------------------------+-----------------------------------
00039 
00040 template <class T>
00041 inline const T& CTBcomplex<T>::Re() const
00042 {
00043   return mf_re;
00044 }
00045 
00046 //------------------------------------------+-----------------------------------
00048 
00049 template <class T>
00050 inline T& CTBcomplex<T>::Im()
00051 {
00052   return mf_im;
00053 }
00054 
00055 //------------------------------------------+-----------------------------------
00057 
00058 template <class T>
00059 inline const T& CTBcomplex<T>::Im() const
00060 {
00061   return mf_im;
00062 }
00063 
00064 //------------------------------------------+-----------------------------------
00066 
00067 template <class T>
00068 inline void CTBcomplex<T>::Re(T f_re)
00069 {
00070   mf_re = f_re;
00071   return;
00072 }
00073 
00074 //------------------------------------------+-----------------------------------
00076 
00077 template <class T>
00078 inline void CTBcomplex<T>::Im(T f_im)
00079 {
00080   mf_im = f_im;
00081   return;
00082 }
00083 
00084 //------------------------------------------+-----------------------------------
00086 
00087 template <class T>
00088 inline T CTBcomplex<T>::Abs() const
00089 {
00090   return CTBpythag(mf_re, mf_im);
00091 }
00092 
00093 //------------------------------------------+-----------------------------------
00095 
00096 template <class T>
00097 inline T CTBcomplex<T>::Arg() const
00098 {
00099   return atan2(mf_im, mf_re);
00100 }
00101 
00102 //------------------------------------------+-----------------------------------
00104 
00105 template <class T>
00106 inline bool CTBcomplex<T>::IsReal() const
00107 {
00108   return mf_im == 0. || fabs(mf_im) <= CTBtraits<T>::Epsilon() * fabs(mf_re);
00109 }
00110 
00111 //------------------------------------------+-----------------------------------
00113 
00114 template <class T>
00115 inline bool CTBcomplex<T>::IsImaginary() const
00116 {
00117   return mf_re == 0. || fabs(mf_re) <= CTBtraits<T>::Epsilon() * fabs(mf_im);
00118 }
00119 
00120 //------------------------------------------+-----------------------------------
00122 
00123 template <class T>
00124 inline CTBcomplex<T> CTBcomplex<T>::Conj() const
00125 {
00126   return CTBcomplex<T>(mf_re, -mf_im);
00127 }
00128 
00129 //------------------------------------------+-----------------------------------
00131 
00132 template <class T>
00133 inline CTBcomplex<T> CTBcomplex<T>::TimesI() const
00134 {
00135   return CTBcomplex<T>(-mf_im, mf_re);
00136 }
00137 
00138 //------------------------------------------+-----------------------------------
00140 
00141 template <class T>
00142 inline CTBcomplex<T>& CTBcomplex<T>::operator=(T f_r)
00143 {
00144   mf_re = f_r;
00145   mf_im = 0.;
00146   return *this;
00147 }
00148 
00149 //------------------------------------------+-----------------------------------
00151 
00152 template <class T>
00153 inline bool CTBcomplex<T>::operator!() const
00154 {
00155   return (mf_re == 0. && mf_im == 0.);
00156 }
00157 
00158 //------------------------------------------+-----------------------------------
00160 
00164 template <class T>
00165 inline CTBcomplex<T>::operator void* () const
00166 {
00167   return (mf_re != 0. || mf_im != 0.) ? (void*) this : 0;
00168 }
00169 
00170 //------------------------------------------+-----------------------------------
00172 
00173 template <class T>
00174 inline CTBcomplex<T> CTBcomplex<T>::operator+() const
00175 {
00176   return *this;
00177 }
00178 
00179 //------------------------------------------+-----------------------------------
00181 
00182 template <class T>
00183 inline CTBcomplex<T> CTBcomplex<T>::operator-() const
00184 {
00185   return CTBcomplex<T>(-mf_re, -mf_im);
00186 }
00187 
00188 //------------------------------------------+-----------------------------------
00190 
00191 template <class T>
00192 inline CTBcomplex<T>& CTBcomplex<T>::operator+=(const CTBcomplex<T>& z)
00193 {
00194   mf_re += z.mf_re;
00195   mf_im += z.mf_im;
00196   return *this;
00197 }
00198 
00199 //------------------------------------------+-----------------------------------
00201 
00202 template <class T>
00203 inline CTBcomplex<T>& CTBcomplex<T>::operator+=(T f_r)
00204 {
00205   mf_re += f_r;
00206   return *this;
00207 }
00208 
00209 //------------------------------------------+-----------------------------------
00211 
00212 template <class T>
00213 inline CTBcomplex<T>& CTBcomplex<T>::operator-=(const CTBcomplex<T>& z)
00214 {
00215   mf_re -= z.mf_re;
00216   mf_im -= z.mf_im;
00217   return *this;
00218 }
00219 
00220 //------------------------------------------+-----------------------------------
00222 
00223 template <class T>
00224 inline CTBcomplex<T>& CTBcomplex<T>::operator-=(T f_r)
00225 {
00226   mf_re -= f_r;
00227   return *this;
00228 }
00229 
00230 //------------------------------------------+-----------------------------------
00232 
00233 template <class T>
00234 inline CTBcomplex<T>& CTBcomplex<T>::operator*=(const CTBcomplex<T>& z)
00235 {
00236   T f_re = mf_re * z.Re() - mf_im * z.Im();
00237   T f_im = mf_im * z.Re() + mf_re * z.Im();
00238 
00239   mf_re = f_re;
00240   mf_im = f_im;
00241   return *this;
00242 }
00243 
00244 //------------------------------------------+-----------------------------------
00246 
00247 template <class T>
00248 inline CTBcomplex<T>& CTBcomplex<T>::operator*=(T f_r)
00249 {
00250   mf_re *= f_r;
00251   mf_im *= f_r;
00252   return *this;
00253 }
00254 
00255 //------------------------------------------+-----------------------------------
00257 
00258 template <class T>
00259 inline CTBcomplex<T>& CTBcomplex<T>::operator/=(const CTBcomplex<T>& z)
00260 {
00261   CTBcomplex<T> zt = (*this) / z;
00262   (*this) = zt;
00263   return *this;
00264 }
00265 
00266 //------------------------------------------+-----------------------------------
00268 
00269 template <class T>
00270 inline CTBcomplex<T>& CTBcomplex<T>::operator/=(T f_r)
00271 {
00272   mf_re /= f_r;
00273   mf_im /= f_r;
00274   return *this;
00275 }
00276 
00277 //------------------------------------------+-----------------------------------
00283 template <class T>
00284 inline CTBcomplex<T> operator+(const CTBcomplex<T>& lhs,
00285                                const CTBcomplex<T>& rhs)
00286 {  
00287   return CTBcomplex<T>(lhs.Re()+rhs.Re(), lhs.Im()+rhs.Im());
00288 }
00289 
00290 //------------------------------------------+-----------------------------------
00296 template <class T>
00297 inline CTBcomplex<T> operator+(const CTBcomplex<T>& lhs, T f_rhs)
00298 {  
00299   return CTBcomplex<T>(lhs.Re()+f_rhs, lhs.Im());
00300 }
00301 
00302 //------------------------------------------+-----------------------------------
00308 template <class T>
00309 inline CTBcomplex<T> operator+(T f_lhs, const CTBcomplex<T>& rhs)
00310 {  
00311   return CTBcomplex<T>(f_lhs+rhs.Re(), rhs.Im());
00312 }
00313 
00314 //------------------------------------------+-----------------------------------
00320 template <class T>
00321 inline CTBcomplex<T> operator-(const CTBcomplex<T>& lhs,
00322                                const CTBcomplex<T>& rhs)
00323 {  
00324   return CTBcomplex<T>(lhs.Re()-rhs.Re(), lhs.Im()-rhs.Im());
00325 }
00326 
00327 //------------------------------------------+-----------------------------------
00333 template <class T>
00334 inline CTBcomplex<T> operator-(const CTBcomplex<T>& lhs, T f_rhs)
00335 {  
00336   return CTBcomplex<T>(lhs.Re()-f_rhs, lhs.Im());
00337 }
00338 
00339 //------------------------------------------+-----------------------------------
00345 template <class T>
00346 inline CTBcomplex<T> operator-(T f_lhs, const CTBcomplex<T>& rhs)
00347 {  
00348   return CTBcomplex<T>(f_lhs-rhs.Re(), -rhs.Im());
00349 }
00350 
00351 //------------------------------------------+-----------------------------------
00374 template <class T>
00375 inline CTBcomplex<T> operator*(const CTBcomplex<T>& lhs,
00376                                const CTBcomplex<T>& rhs)
00377 {
00378   return CTBcomplex<T>(lhs.Re() * rhs.Re() - lhs.Im() * rhs.Im(),
00379                        lhs.Im() * rhs.Re() + lhs.Re() * rhs.Im());
00380 }
00381 
00382 //------------------------------------------+-----------------------------------
00388 template <class T>
00389 inline CTBcomplex<T> operator*(const CTBcomplex<T>& lhs, T f_rhs)
00390 {  
00391   return CTBcomplex<T>(lhs.Re()*f_rhs, lhs.Im()*f_rhs);
00392 }
00393 
00394 //------------------------------------------+-----------------------------------
00400 template <class T>
00401 inline CTBcomplex<T> operator*(T f_lhs, const CTBcomplex<T>& rhs)
00402 {  
00403   return CTBcomplex<T>(f_lhs*rhs.Re(), f_lhs*rhs.Im());
00404 }
00405 
00406 //------------------------------------------+-----------------------------------
00412 template <class T>
00413 inline CTBcomplex<T> operator/(const CTBcomplex<T>& lhs,
00414                                const CTBcomplex<T>& rhs)
00415 {
00416   return lhs.Divide(rhs);
00417 }
00418 
00419 //------------------------------------------+-----------------------------------
00425 template <class T>
00426 inline CTBcomplex<T> operator/(const CTBcomplex<T>& lhs, T f_rhs)
00427 {  
00428   return CTBcomplex<T>(lhs.Re()/f_rhs, lhs.Im()/f_rhs);
00429 }
00430 
00431 //------------------------------------------+-----------------------------------
00437 template <class T>
00438 CTBcomplex<T> operator/(T f_lhs, const CTBcomplex<T>& rhs)
00439 {  
00440   return rhs.Invert(f_lhs);
00441 }
00442 
00443 //------------------------------------------+-----------------------------------
00449 template <class T>
00450 inline bool operator==(const CTBcomplex<T>& lhs, const CTBcomplex<T>& rhs)
00451 {  
00452   return (lhs.Re() == rhs.Re() && lhs.Im() == rhs.Im());
00453 }
00454 
00455 //------------------------------------------+-----------------------------------
00461 template <class T>
00462 inline bool operator==(const CTBcomplex<T>& lhs, T f_rhs)
00463 {  
00464   return (lhs.Re() == f_rhs && lhs.Im() == 0.);
00465 }
00466 
00467 //------------------------------------------+-----------------------------------
00473 template <class T>
00474 inline bool operator==(T f_lhs, const CTBcomplex<T>& rhs)
00475 {  
00476   return (f_lhs == rhs.Re() && 0. == rhs.Im());
00477 }
00478 
00479 //------------------------------------------+-----------------------------------
00485 template <class T>
00486 inline ostream& operator<<(ostream& os, const CTBcomplex<T>& obj)
00487 {
00488   obj.ToStream(os);
00489   return os;
00490 }
00491 
00492 //------------------------------------------+-----------------------------------
00498 template <class T>
00499 inline istream& operator>>(istream& is, CTBcomplex<T>& obj)
00500 {
00501   obj.FromStream(is);
00502   return is;
00503 }
00504 
00505 //------------------------------------------+-----------------------------------
00511 template <class T>
00512 inline T CTBabs(const CTBcomplex<T>& z)
00513 {  
00514   return z.Abs();
00515 }
00516 
00517 //------------------------------------------+-----------------------------------
00523 template <class T>
00524 inline T CTBabsm(const CTBcomplex<T>& z)
00525 {  
00526   return CTBmax(fabs(z.Re()), fabs(z.Im()));
00527 }
00528 
00529 //------------------------------------------+-----------------------------------
00535 template <class T>
00536 inline T CTBabs2(const CTBcomplex<T>& z)
00537 {  
00538   return z.Re()*z.Re() + z.Im()*z.Im();
00539 }
00540 
00541 //------------------------------------------+-----------------------------------
00547 template <class T>
00548 inline T CTBarg(const CTBcomplex<T>& z)
00549 {  
00550   return z.Arg();
00551 }
00552 
00553 //------------------------------------------+-----------------------------------
00559 template <class T>
00560 inline T CTBreal(const CTBcomplex<T>& z)
00561 {  
00562   return z.Re();
00563 }
00564 
00565 //------------------------------------------+-----------------------------------
00571 template <class T>
00572 inline T CTBimag(const CTBcomplex<T>& z)
00573 {  
00574   return z.Im();
00575 }
00576 
00577 //------------------------------------------+-----------------------------------
00583 template <class T>
00584 inline CTBcomplex<T> CTBconj(const CTBcomplex<T>& z)
00585 {  
00586   return CTBcomplex<T>(z.Re(), -z.Im());
00587 }
00588 
00589 //------------------------------------------+-----------------------------------
00595 template <class T>
00596 inline CTBcomplex<T> CTBtimesI(const CTBcomplex<T>& z)
00597 {  
00598   return CTBcomplex<T>(-z.Im(), z.Re());
00599 }
00600 
00601 //------------------------------------------+-----------------------------------
00607 template <class T>
00608 inline CTBcomplex<T> CTBsqrt(const CTBcomplex<T>& z)
00609 {  
00610   return z.Sqrt();
00611 }
00612 
00613 //------------------------------------------+-----------------------------------
00619 template <class T>
00620 inline CTBcomplex<T> CTBexp(const CTBcomplex<T>& z)
00621 {  
00622   return z.Exp();
00623 }
00624 
00625 //------------------------------------------+-----------------------------------
00631 template <class T>
00632 inline CTBcomplex<T> CTBlog(const CTBcomplex<T>& z)
00633 {  
00634   return z.Log();
00635 }
00636 
00637 //------------------------------------------+-----------------------------------
00643 template <class T>
00644 inline CTBcomplex<T> CTBsin(const CTBcomplex<T>& z)
00645 {  
00646   return z.Sin();
00647 }
00648 
00649 //------------------------------------------+-----------------------------------
00655 template <class T>
00656 inline CTBcomplex<T> CTBcos(const CTBcomplex<T>& z)
00657 {  
00658   return z.Cos();
00659 }
00660 
00661 //------------------------------------------+-----------------------------------
00667 template <class T>
00668 inline CTBcomplex<T> CTBtan(const CTBcomplex<T>& z)
00669 {  
00670   return z.Tan();
00671 }
00672 
00673 //------------------------------------------+-----------------------------------
00679 template <class T>
00680 inline CTBcomplex<T> CTBasin(const CTBcomplex<T>& z)
00681 {  
00682   return z.Asin();
00683 }
00684 
00685 //------------------------------------------+-----------------------------------
00691 template <class T>
00692 inline CTBcomplex<T> CTBacos(const CTBcomplex<T>& z)
00693 {  
00694   return z.Acos();
00695 }
00696 
00697 //------------------------------------------+-----------------------------------
00703 template <class T>
00704 inline CTBcomplex<T> CTBatan(const CTBcomplex<T>& z)
00705 {  
00706   return z.Atan();
00707 }
00708 
00709 //------------------------------------------+-----------------------------------
00715 template <class T>
00716 inline CTBcomplex<T> CTBsinh(const CTBcomplex<T>& z)
00717 {  
00718   return z.Sinh();
00719 }
00720 
00721 //------------------------------------------+-----------------------------------
00727 template <class T>
00728 inline CTBcomplex<T> CTBcosh(const CTBcomplex<T>& z)
00729 {  
00730   return z.Cosh();
00731 }
00732 
00733 //------------------------------------------+-----------------------------------
00739 template <class T>
00740 inline CTBcomplex<T> CTBtanh(const CTBcomplex<T>& z)
00741 {  
00742   return z.Tanh();
00743 }
00744 
00745 //------------------------------------------+-----------------------------------
00751 template <class T>
00752 inline CTBcomplex<T> CTBasinh(const CTBcomplex<T>& z)
00753 {  
00754   return z.Asinh();
00755 }
00756 
00757 //------------------------------------------+-----------------------------------
00763 template <class T>
00764 inline CTBcomplex<T> CTBacosh(const CTBcomplex<T>& z)
00765 {  
00766   return z.Acosh();
00767 }
00768 
00769 //------------------------------------------+-----------------------------------
00775 template <class T>
00776 inline CTBcomplex<T> CTBatanh(const CTBcomplex<T>& z)
00777 {  
00778   return z.Atanh();
00779 }
00780 
00781 //------------------------------------------+-----------------------------------
00787 template <class T>
00788 inline CTBcomplex<T> CTBpow(const CTBcomplex<T>& z_x, int i_y)
00789 {  
00790   return z_x.Pow(i_y);
00791 }
00792 
00793 //------------------------------------------+-----------------------------------
00799 template <class T>
00800 inline CTBcomplex<T> CTBpow(const CTBcomplex<T>& z_x, const CTBcomplex<T>& z_y)
00801 {  
00802   return z_x.Pow(z_y);
00803 }
00804 
00805 //------------------------------------------+-----------------------------------
00819 template <class T>
00820 inline CTBprintfS<CTBcomplex<T> > CTBprintf(CTBcomplex<T> value, 
00821                                             const char* c_format,
00822                                             int i_width, int i_precision)
00823 {
00824   return CTBprintfS<CTBcomplex<T> >(value,c_format,i_width,i_precision);
00825 }
00826 

Generated at Fri Oct 24 18:11:28 2003 for CTBbase by doxygen1.2.9-20010812 written by Dimitri van Heesch, © 1997-2001