_complex.h

00001 /*
00002  * Copyright (c) 1999
00003  * Silicon Graphics Computer Systems, Inc.
00004  *
00005  * Copyright (c) 1999 
00006  * Boris Fomitchev
00007  *
00008  * This material is provided "as is", with absolutely no warranty expressed
00009  * or implied. Any use is at your own risk.
00010  *
00011  * Permission to use or copy this software for any purpose is hereby granted 
00012  * without fee, provided the above notices are retained on all copies.
00013  * Permission to modify the code and to distribute modified code is granted,
00014  * provided the above notices are retained, and a notice that the code was
00015  * modified is included with the above copyright notice.
00016  *
00017  */ 
00018 #ifndef _STLP_internal_complex_h
00019 #define _STLP_internal_complex_h
00020 
00021 // This header declares the template class complex, as described in 
00022 // in the draft C++ standard.  Single-precision complex numbers
00023 // are complex<float>, double-precision are complex<double>, and
00024 // quad precision are complex<long double>.
00025 
00026 // Note that the template class complex is declared within namespace
00027 // std, as called for by the draft C++ standard.  
00028 
00029 #include <cmath>
00030 #include <iosfwd>
00031 
00032 _STLP_BEGIN_NAMESPACE
00033 
00034 #if !defined(_STLP_NO_COMPLEX_SPECIALIZATIONS)          //*TY 02/25/2000 - added for MPW compiler workaround
00035 
00036 template <class _Tp> struct complex;
00037 
00038 _STLP_TEMPLATE_NULL  struct _STLP_CLASS_DECLSPEC complex<float>;
00039 _STLP_TEMPLATE_NULL  struct _STLP_CLASS_DECLSPEC complex<double>;
00040 # ifndef _STLP_NO_LONG_DOUBLE
00041 _STLP_TEMPLATE_NULL  struct _STLP_CLASS_DECLSPEC complex<long double>;
00042 # endif
00043 # endif
00044 
00045 template <class _Tp>
00046 struct complex {
00047   typedef _Tp value_type;
00048   typedef complex<_Tp> _Self;
00049 
00050   // Constructors, destructor, assignment operator.
00051   complex() : _M_re(0), _M_im(0) {}
00052   complex(const value_type& __x)
00053     : _M_re(__x), _M_im(0) {}
00054   complex(const value_type& __x, const value_type& __y)
00055     : _M_re(__x), _M_im(__y) {}
00056   complex(const _Self& __z)
00057     : _M_re(__z._M_re), _M_im(__z._M_im) {}
00058 
00059   _Self& operator=(const _Self& __z) {
00060     _M_re = __z._M_re;
00061     _M_im = __z._M_im;
00062     return *this;
00063   }
00064 
00065 #if defined (_STLP_MEMBER_TEMPLATES) && ( defined (_STLP_FUNCTION_TMPL_PARTIAL_ORDER) || defined(_STLP_NO_COMPLEX_SPECIALIZATIONS))
00066   template <class _Tp2>
00067   explicit complex(const complex<_Tp2>& __z)
00068     : _M_re(__z._M_re), _M_im(__z._M_im) {}
00069 
00070   template <class _Tp2>
00071   _Self& operator=(const complex<_Tp2>& __z) {
00072     _M_re = __z._M_re;
00073     _M_im = __z._M_im;
00074     return *this;
00075   }
00076 #endif /* _STLP_MEMBER_TEMPLATES */
00077 
00078   // Element access.
00079   value_type real() const { return _M_re; }
00080   value_type imag() const { return _M_im; }
00081 
00082   // Arithmetic op= operations involving one real argument.
00083 
00084   _Self& operator= (const value_type& __x) {
00085     _M_re = __x;
00086     _M_im = 0;
00087     return *this;
00088   }
00089   _Self& operator+= (const value_type& __x) {
00090     _M_re += __x;
00091     return *this;
00092   }
00093   _Self& operator-= (const value_type& __x) {
00094     _M_re -= __x;
00095     return *this;
00096   }
00097   _Self& operator*= (const value_type& __x) {
00098     _M_re *= __x;
00099     _M_im *= __x;
00100     return *this;
00101   }
00102   _Self& operator/= (const value_type& __x) {
00103     _M_re /= __x;
00104     _M_im /= __x;
00105     return *this;
00106   }
00107 
00108   // Arithmetic op= operations involving two complex arguments.
00109 
00110   static void  _STLP_CALL _div(const value_type& __z1_r, const value_type& __z1_i,
00111                    const value_type& __z2_r, const value_type& __z2_i,
00112                    value_type& __res_r, value_type& __res_i);
00113 
00114   static void _STLP_CALL _div(const value_type& __z1_r, 
00115                    const value_type& __z2_r, const value_type& __z2_i,
00116                    value_type& __res_r, value_type& __res_i);
00117 
00118 #if defined ( _STLP_MEMBER_TEMPLATES ) // && defined (_STLP_FUNCTION_TMPL_PARTIAL_ORDER)
00119 
00120   template <class _Tp2> _Self& operator+= (const complex<_Tp2>& __z) {
00121     _M_re += __z._M_re;
00122     _M_im += __z._M_im;
00123     return *this;
00124   }
00125 
00126   template <class _Tp2> _Self& operator-= (const complex<_Tp2>& __z) {
00127     _M_re -= __z._M_re;
00128     _M_im -= __z._M_im;
00129     return *this;
00130   }
00131 
00132   template <class _Tp2> _Self& operator*= (const complex<_Tp2>& __z) {
00133     value_type __r = _M_re * __z._M_re - _M_im * __z._M_im;
00134     value_type __i = _M_re * __z._M_im + _M_im * __z._M_re;
00135     _M_re = __r;
00136     _M_im = __i;
00137     return *this;
00138   }
00139 
00140   template <class _Tp2> _Self& operator/= (const complex<_Tp2>& __z) {
00141     value_type __r;
00142     value_type __i;
00143     _div(_M_re, _M_im, __z._M_re, __z._M_im, __r, __i);
00144     _M_re = __r;
00145     _M_im = __i;
00146     return *this;
00147   }
00148 
00149 #endif /* _STLP_MEMBER_TEMPLATES */
00150 
00151   _Self& operator+= (const _Self& __z) {
00152     _M_re += __z._M_re;
00153     _M_im += __z._M_im;
00154     return *this;
00155   }
00156 
00157   _Self& operator-= (const _Self& __z) {
00158     _M_re -= __z._M_re;
00159     _M_im -= __z._M_im;
00160     return *this;
00161   }
00162   
00163   _Self& operator*= (const _Self& __z) {
00164     value_type __r = _M_re * __z._M_re - _M_im * __z._M_im;
00165     value_type __i = _M_re * __z._M_im + _M_im * __z._M_re;
00166     _M_re = __r;
00167     _M_im = __i;
00168     return *this;
00169   }
00170 
00171   _Self& operator/= (const _Self& __z) {
00172     value_type __r;
00173     value_type __i;
00174     _div(_M_re, _M_im, __z._M_re, __z._M_im, __r, __i);
00175     _M_re = __r;
00176     _M_im = __i;
00177     return *this;
00178   }
00179 
00180   // Data members.
00181   value_type _M_re;
00182   value_type _M_im;
00183 };
00184 
00185 #if !defined(_STLP_NO_COMPLEX_SPECIALIZATIONS)          //*TY 02/25/2000 - added for MPW compiler workaround
00186 // Explicit specializations for float, double, long double.  The only
00187 // reason for these specializations is to enable automatic conversions
00188 // from complex<float> to complex<double>, and complex<double> to
00189 // complex<long double>.
00190 
00191 
00192 _STLP_TEMPLATE_NULL
00193 struct _STLP_CLASS_DECLSPEC complex<float> {
00194   typedef float value_type;
00195   typedef complex<float> _Self;
00196   // Constructors, destructor, assignment operator.
00197 
00198   complex(value_type __x = 0.0, value_type __y = 0.0)
00199     : _M_re(__x), _M_im(__y) {}
00200 
00201   complex(const complex<float>& __z)    : _M_re(__z._M_re), _M_im(__z._M_im) {} 
00202 
00203   inline explicit complex(const complex<double>& __z);
00204 # ifndef _STLP_NO_LONG_DOUBLE
00205   inline explicit complex(const complex<long double>& __z);
00206 # endif
00207   // Element access.
00208   value_type real() const { return _M_re; }
00209   value_type imag() const { return _M_im; }
00210 
00211   // Arithmetic op= operations involving one real argument.
00212 
00213   _Self& operator= (value_type __x) {
00214     _M_re = __x;
00215     _M_im = 0;
00216     return *this;
00217   }
00218   _Self& operator+= (value_type __x) {
00219     _M_re += __x;
00220     return *this;
00221   }
00222   _Self& operator-= (value_type __x) {
00223     _M_re -= __x;
00224     return *this;
00225   }
00226   _Self& operator*= (value_type __x) {
00227     _M_re *= __x;
00228     _M_im *= __x;
00229     return *this;
00230   }
00231   _Self& operator/= (value_type __x) {
00232     _M_re /= __x;
00233     _M_im /= __x;
00234     return *this;
00235   }
00236 
00237   // Arithmetic op= operations involving two complex arguments.
00238 
00239   static void _STLP_CALL _div(const float& __z1_r, const float& __z1_i,
00240                               const float& __z2_r, const float& __z2_i,
00241                               float& __res_r, float& __res_i);
00242     
00243   static void _STLP_CALL _div(const float& __z1_r, 
00244                               const float& __z2_r, const float& __z2_i,
00245                               float& __res_r, float& __res_i);
00246     
00247 #if defined (_STLP_MEMBER_TEMPLATES)
00248 
00249   template <class _Tp2>
00250   complex<float>& operator=(const complex<_Tp2>& __z) {
00251     _M_re = __z._M_re;
00252     _M_im = __z._M_im;
00253     return *this;
00254   }
00255 
00256   template <class _Tp2>
00257   complex<float>& operator+= (const complex<_Tp2>& __z) {
00258     _M_re += __z._M_re;
00259     _M_im += __z._M_im;
00260     return *this;
00261   }
00262 
00263   template <class _Tp2>
00264   complex<float>& operator-= (const complex<_Tp2>& __z) {
00265     _M_re -= __z._M_re;
00266     _M_im -= __z._M_im;
00267     return *this;
00268   }
00269 
00270   template <class _Tp2>
00271   complex<float>& operator*= (const complex<_Tp2>& __z) {
00272     float __r = _M_re * __z._M_re - _M_im * __z._M_im;
00273     float __i = _M_re * __z._M_im + _M_im * __z._M_re;
00274     _M_re = __r;
00275     _M_im = __i;
00276     return *this;
00277   }
00278 
00279   template <class _Tp2>
00280   complex<float>& operator/= (const complex<_Tp2>& __z) {
00281     float __r;
00282     float __i;
00283     _div(_M_re, _M_im, __z._M_re, __z._M_im, __r, __i);
00284     _M_re = __r;
00285     _M_im = __i;
00286     return *this;
00287   }
00288 
00289 #endif /* _STLP_MEMBER_TEMPLATES */
00290 
00291   _Self& operator=(const _Self& __z) {
00292     _M_re = __z._M_re;
00293     _M_im = __z._M_im;
00294     return *this;
00295   }
00296 
00297   _Self& operator+= (const _Self& __z) {
00298     _M_re += __z._M_re;
00299     _M_im += __z._M_im;
00300     return *this;
00301   }
00302 
00303   _Self& operator-= (const _Self& __z) {
00304     _M_re -= __z._M_re;
00305     _M_im -= __z._M_im;
00306     return *this;
00307   }
00308   
00309   _Self& operator*= (const _Self& __z) {
00310     value_type __r = _M_re * __z._M_re - _M_im * __z._M_im;
00311     value_type __i = _M_re * __z._M_im + _M_im * __z._M_re;
00312     _M_re = __r;
00313     _M_im = __i;
00314     return *this;
00315   }
00316 
00317   _Self& operator/= (const _Self& __z) {
00318     value_type __r;
00319     value_type __i;
00320     _div(_M_re, _M_im, __z._M_re, __z._M_im, __r, __i);
00321     _M_re = __r;
00322     _M_im = __i;
00323     return *this;
00324   }
00325 
00326   // Data members.
00327   value_type _M_re;
00328   value_type _M_im;
00329 };
00330 
00331 _STLP_TEMPLATE_NULL struct _STLP_CLASS_DECLSPEC complex<double> {
00332   typedef double value_type;
00333   typedef complex<double> _Self;
00334 
00335   // Constructors, destructor, assignment operator.
00336 
00337   complex(value_type __x = 0.0, value_type __y = 0.0)
00338     : _M_re(__x), _M_im(__y) {}
00339 
00340   complex(const complex<double>& __z)
00341     : _M_re(__z._M_re), _M_im(__z._M_im) {}
00342   inline complex(const complex<float>& __z);
00343 # ifndef _STLP_NO_LONG_DOUBLE
00344   explicit inline complex(const complex<long double>& __z);
00345 # endif
00346   // Element access.
00347   value_type real() const { return _M_re; }
00348   value_type imag() const { return _M_im; }
00349 
00350   // Arithmetic op= operations involving one real argument.
00351 
00352   _Self& operator= (value_type __x) {
00353     _M_re = __x;
00354     _M_im = 0;
00355     return *this;
00356   }
00357   _Self& operator+= (value_type __x) {
00358     _M_re += __x;
00359     return *this;
00360   }
00361   _Self& operator-= (value_type __x) {
00362     _M_re -= __x;
00363     return *this;
00364   }
00365   _Self& operator*= (value_type __x) {
00366     _M_re *= __x;
00367     _M_im *= __x;
00368     return *this;
00369   }
00370   _Self& operator/= (value_type __x) {
00371     _M_re /= __x;
00372     _M_im /= __x;
00373     return *this;
00374   }
00375 
00376   // Arithmetic op= operations involving two complex arguments.
00377 
00378   static void _STLP_CALL _div(const double& __z1_r, const double& __z1_i,
00379                               const double& __z2_r, const double& __z2_i,
00380                               double& __res_r, double& __res_i);
00381   static void _STLP_CALL _div(const double& __z1_r, 
00382                               const double& __z2_r, const double& __z2_i,
00383                               double& __res_r, double& __res_i);
00384     
00385 #if defined (_STLP_MEMBER_TEMPLATES) && defined (_STLP_FUNCTION_TMPL_PARTIAL_ORDER)
00386 
00387   template <class _Tp2>
00388   complex<double>& operator=(const complex<_Tp2>& __z) {
00389     _M_re = __z._M_re;
00390     _M_im = __z._M_im;
00391     return *this;
00392   }
00393 
00394   template <class _Tp2>
00395   complex<double>& operator+= (const complex<_Tp2>& __z) {
00396     _M_re += __z._M_re;
00397     _M_im += __z._M_im;
00398     return *this;
00399   }
00400 
00401   template <class _Tp2>
00402   complex<double>& operator-= (const complex<_Tp2>& __z) {
00403     _M_re -= __z._M_re;
00404     _M_im -= __z._M_im;
00405     return *this;
00406   }
00407 
00408   template <class _Tp2>
00409   complex<double>& operator*= (const complex<_Tp2>& __z) {
00410     double __r = _M_re * __z._M_re - _M_im * __z._M_im;
00411     double __i = _M_re * __z._M_im + _M_im * __z._M_re;
00412     _M_re = __r;
00413     _M_im = __i;
00414     return *this;
00415   }
00416 
00417   template <class _Tp2>
00418   complex<double>& operator/= (const complex<_Tp2>& __z) {
00419     double __r;
00420     double __i;
00421     _div(_M_re, _M_im, __z._M_re, __z._M_im, __r, __i);
00422     _M_re = __r;
00423     _M_im = __i;
00424     return *this;
00425   }
00426 
00427 #endif /* _STLP_MEMBER_TEMPLATES */
00428 
00429   _Self& operator=(const _Self& __z) {
00430     _M_re = __z._M_re;
00431     _M_im = __z._M_im;
00432     return *this;
00433   }
00434 
00435   _Self& operator+= (const _Self& __z) {
00436     _M_re += __z._M_re;
00437     _M_im += __z._M_im;
00438     return *this;
00439   }
00440 
00441   _Self& operator-= (const _Self& __z) {
00442     _M_re -= __z._M_re;
00443     _M_im -= __z._M_im;
00444     return *this;
00445   }
00446   
00447   _Self& operator*= (const _Self& __z) {
00448     value_type __r = _M_re * __z._M_re - _M_im * __z._M_im;
00449     value_type __i = _M_re * __z._M_im + _M_im * __z._M_re;
00450     _M_re = __r;
00451     _M_im = __i;
00452     return *this;
00453   }
00454 
00455   _Self& operator/= (const _Self& __z) {
00456     value_type __r;
00457     value_type __i;
00458     _div(_M_re, _M_im, __z._M_re, __z._M_im, __r, __i);
00459     _M_re = __r;
00460     _M_im = __i;
00461     return *this;
00462   }
00463 
00464   // Data members.
00465   value_type _M_re;
00466   value_type _M_im;
00467 };
00468 
00469 # ifndef _STLP_NO_LONG_DOUBLE
00470 
00471 _STLP_TEMPLATE_NULL struct _STLP_CLASS_DECLSPEC complex<long double> {
00472   typedef long double value_type;
00473   typedef complex<long double> _Self;
00474 
00475   // Constructors, destructor, assignment operator.
00476   complex(value_type __x = 0.0, value_type __y = 0.0)
00477     : _M_re(__x), _M_im(__y) {}
00478 
00479   complex(const complex<long double>& __z)
00480     : _M_re(__z._M_re), _M_im(__z._M_im) {}
00481   inline complex(const complex<float>& __z);
00482   inline complex(const complex<double>& __z);
00483 
00484   // Element access.
00485   value_type real() const { return _M_re; }
00486   value_type imag() const { return _M_im; }
00487 
00488   // Arithmetic op= operations involving one real argument.
00489 
00490   _Self& operator= (value_type __x) {
00491     _M_re = __x;
00492     _M_im = 0;
00493     return *this;
00494   }
00495   _Self& operator+= (value_type __x) {
00496     _M_re += __x;
00497     return *this;
00498   }
00499   _Self& operator-= (value_type __x) {
00500     _M_re -= __x;
00501     return *this;
00502   }
00503   _Self& operator*= (value_type __x) {
00504     _M_re *= __x;
00505     _M_im *= __x;
00506     return *this;
00507   }
00508   _Self& operator/= (value_type __x) {
00509     _M_re /= __x;
00510     _M_im /= __x;
00511     return *this;
00512   }
00513 
00514   // Arithmetic op= operations involving two complex arguments.
00515 
00516   static void _STLP_CALL _div(const long double& __z1_r, const long double& __z1_i,
00517                               const long double& __z2_r, const long double& __z2_i,
00518                               long double& __res_r, long double& __res_i);
00519 
00520   static void _STLP_CALL _div(const long double& __z1_r, 
00521                               const long double& __z2_r, const long double& __z2_i,
00522                               long double& __res_r, long double& __res_i);
00523 
00524 #if defined (_STLP_MEMBER_TEMPLATES) && defined (_STLP_FUNCTION_TMPL_PARTIAL_ORDER)
00525 
00526   template <class _Tp2>
00527   complex<long double>& operator=(const complex<_Tp2>& __z) {
00528     _M_re = __z._M_re;
00529     _M_im = __z._M_im;
00530     return *this;
00531   }
00532 
00533   template <class _Tp2>
00534   complex<long double>& operator+= (const complex<_Tp2>& __z) {
00535     _M_re += __z._M_re;
00536     _M_im += __z._M_im;
00537     return *this;
00538   }
00539 
00540   template <class _Tp2>
00541   complex<long double>& operator-= (const complex<_Tp2>& __z) {
00542     _M_re -= __z._M_re;
00543     _M_im -= __z._M_im;
00544     return *this;
00545   }
00546 
00547   template <class _Tp2>
00548   complex<long double>& operator*= (const complex<_Tp2>& __z) {
00549     long double __r = _M_re * __z._M_re - _M_im * __z._M_im;
00550     long double __i = _M_re * __z._M_im + _M_im * __z._M_re;
00551     _M_re = __r;
00552     _M_im = __i;
00553     return *this;
00554   }
00555 
00556   template <class _Tp2>
00557   complex<long double>& operator/= (const complex<_Tp2>& __z) {
00558     long double __r;
00559     long double __i;
00560     _div(_M_re, _M_im, __z._M_re, __z._M_im, __r, __i);
00561     _M_re = __r;
00562     _M_im = __i;
00563     return *this;
00564   }
00565 
00566 #endif /* _STLP_MEMBER_TEMPLATES */
00567 
00568   _Self& operator=(const _Self& __z) {
00569     _M_re = __z._M_re;
00570     _M_im = __z._M_im;
00571     return *this;
00572   }
00573 
00574   _Self& operator+= (const _Self& __z) {
00575     _M_re += __z._M_re;
00576     _M_im += __z._M_im;
00577     return *this;
00578   }
00579 
00580   _Self& operator-= (const _Self& __z) {
00581     _M_re -= __z._M_re;
00582     _M_im -= __z._M_im;
00583     return *this;
00584   }
00585   
00586   _Self& operator*= (const _Self& __z) {
00587     value_type __r = _M_re * __z._M_re - _M_im * __z._M_im;
00588     value_type __i = _M_re * __z._M_im + _M_im * __z._M_re;
00589     _M_re = __r;
00590     _M_im = __i;
00591     return *this;
00592   }
00593 
00594   _Self& operator/= (const _Self& __z) {
00595     value_type __r;
00596     value_type __i;
00597     _div(_M_re, _M_im, __z._M_re, __z._M_im, __r, __i);
00598     _M_re = __r;
00599     _M_im = __i;
00600     return *this;
00601   }
00602 
00603   // Data members.
00604   value_type _M_re;
00605   value_type _M_im;
00606 };
00607 
00608 # endif /* _STLP_NO_LONG_DOUBLE */
00609 
00610 // Converting constructors from one of these three specialized types
00611 // to another.
00612 
00613 inline complex<float>::complex(const complex<double>& __z)
00614   : _M_re(__z._M_re), _M_im(__z._M_im) {}
00615 inline complex<double>::complex(const complex<float>& __z)
00616   : _M_re(__z._M_re), _M_im(__z._M_im) {}
00617 # ifndef _STLP_NO_LONG_DOUBLE
00618 inline complex<float>::complex(const complex<long double>& __z)
00619   : _M_re(__z._M_re), _M_im(__z._M_im) {}
00620 inline complex<double>::complex(const complex<long double>& __z)
00621   : _M_re(__z._M_re), _M_im(__z._M_im) {}
00622 inline complex<long double>::complex(const complex<float>& __z)
00623   : _M_re(__z._M_re), _M_im(__z._M_im) {}
00624 inline complex<long double>::complex(const complex<double>& __z)
00625   : _M_re(__z._M_re), _M_im(__z._M_im) {}
00626 # endif
00627 
00628 # endif /* SPECIALIZATIONS */
00629 
00630 // Unary non-member arithmetic operators.
00631 
00632 template <class _Tp>
00633 inline complex<_Tp> _STLP_CALL operator+(const complex<_Tp>& __z) {
00634   return __z;
00635 }
00636 
00637 template <class _Tp>
00638 inline complex<_Tp> _STLP_CALL  operator-(const complex<_Tp>& __z) {
00639   return complex<_Tp>(-__z._M_re, -__z._M_im);
00640 }
00641 
00642 // Non-member arithmetic operations involving one real argument.
00643 
00644 template <class _Tp> 
00645 inline complex<_Tp> _STLP_CALL operator+(const _Tp& __x, const complex<_Tp>& __z) {
00646   return complex<_Tp>(__x + __z._M_re, __z._M_im);
00647 }
00648 
00649 template <class _Tp> 
00650 inline complex<_Tp> _STLP_CALL operator+(const complex<_Tp>& __z, const _Tp& __x) {
00651   return complex<_Tp>(__z._M_re + __x, __z._M_im);
00652 }
00653 
00654 template <class _Tp> 
00655 inline complex<_Tp> _STLP_CALL operator-(const _Tp& __x, const complex<_Tp>& __z) {
00656   return complex<_Tp>(__x - __z._M_re, -__z._M_im);
00657 }
00658 
00659 template <class _Tp> 
00660 inline complex<_Tp> _STLP_CALL operator-(const complex<_Tp>& __z, const _Tp& __x) {
00661   return complex<_Tp>(__z._M_re - __x, __z._M_im);
00662 }
00663 
00664 template <class _Tp> 
00665 inline complex<_Tp> _STLP_CALL operator*(const _Tp& __x, const complex<_Tp>& __z) {
00666   return complex<_Tp>(__x * __z._M_re, __x * __z._M_im);
00667 }
00668 
00669 template <class _Tp> 
00670 inline complex<_Tp> _STLP_CALL operator*(const complex<_Tp>& __z, const _Tp& __x) {
00671   return complex<_Tp>(__z._M_re * __x, __z._M_im * __x);
00672 }
00673 
00674 template <class _Tp> 
00675 inline complex<_Tp> _STLP_CALL operator/(const _Tp& __x, const complex<_Tp>& __z) {
00676   complex<_Tp> __result;
00677   complex<_Tp>::_div(__x,
00678                      __z._M_re, __z._M_im,
00679                      __result._M_re, __result._M_im);
00680   return __result;
00681 }
00682 
00683 template <class _Tp> 
00684 inline complex<_Tp> _STLP_CALL operator/(const complex<_Tp>& __z, const _Tp& __x) {
00685   return complex<_Tp>(__z._M_re / __x, __z._M_im / __x);
00686 }
00687 
00688 // Non-member arithmetic operations involving two complex arguments
00689 
00690 template <class _Tp> 
00691 inline complex<_Tp> _STLP_CALL 
00692 operator+(const complex<_Tp>& __z1, const complex<_Tp>& __z2) {
00693   return complex<_Tp>(__z1._M_re + __z2._M_re, __z1._M_im + __z2._M_im);
00694 }
00695 
00696 template <class _Tp> 
00697 inline complex<_Tp> _STLP_CALL 
00698 operator-(const complex<_Tp>& __z1, const complex<_Tp>& __z2) {
00699   return complex<_Tp>(__z1._M_re - __z2._M_re, __z1._M_im - __z2._M_im);
00700 }
00701 
00702 template <class _Tp> 
00703 inline complex<_Tp> _STLP_CALL 
00704 operator*(const complex<_Tp>& __z1, const complex<_Tp>& __z2) {
00705   return complex<_Tp>(__z1._M_re * __z2._M_re - __z1._M_im * __z2._M_im,
00706                       __z1._M_re * __z2._M_im + __z1._M_im * __z2._M_re);
00707 }
00708 
00709 template <class _Tp> 
00710 inline complex<_Tp> _STLP_CALL 
00711 operator/(const complex<_Tp>& __z1, const complex<_Tp>& __z2) {
00712   complex<_Tp> __result;
00713   complex<_Tp>::_div(__z1._M_re, __z1._M_im,
00714                      __z2._M_re, __z2._M_im,
00715                      __result._M_re, __result._M_im);
00716   return __result;
00717 }
00718 
00719 // Comparison operators.
00720 
00721 template <class _Tp> 
00722 inline bool _STLP_CALL operator==(const complex<_Tp>& __z1, const complex<_Tp>& __z2) {
00723   return __z1._M_re == __z2._M_re && __z1._M_im == __z2._M_im;
00724 }
00725 
00726 template <class _Tp> 
00727 inline bool _STLP_CALL operator==(const complex<_Tp>& __z, const _Tp& __x) {
00728   return __z._M_re == __x && __z._M_im == 0;
00729 }
00730 
00731 template <class _Tp> 
00732 inline bool _STLP_CALL operator==(const _Tp& __x, const complex<_Tp>& __z) {
00733   return __x == __z._M_re && 0 == __z._M_im;
00734 }
00735 
00736 #ifdef _STLP_FUNCTION_TMPL_PARTIAL_ORDER
00737 
00738 template <class _Tp> 
00739 inline bool _STLP_CALL operator!=(const complex<_Tp>& __z1, const complex<_Tp>& __z2) {
00740   return __z1._M_re != __z2._M_re || __z1._M_im != __z2._M_im;
00741 }
00742 
00743 #endif /* _STLP_FUNCTION_TMPL_PARTIAL_ORDER */
00744 
00745 template <class _Tp> 
00746 inline bool _STLP_CALL operator!=(const complex<_Tp>& __z, const _Tp& __x) {
00747   return __z._M_re != __x || __z._M_im != 0;
00748 }
00749 
00750 template <class _Tp> 
00751 inline bool _STLP_CALL operator!=(const _Tp& __x, const complex<_Tp>& __z) {
00752   return __x != __z._M_re || 0 != __z._M_im;
00753 }
00754 
00755 // Other basic arithmetic operations
00756 
00757 template <class _Tp> 
00758 inline _Tp _STLP_CALL real(const complex<_Tp>& __z) {
00759   return __z._M_re;
00760 }
00761 
00762 template <class _Tp> 
00763 inline _Tp _STLP_CALL imag(const complex<_Tp>& __z) {
00764   return __z._M_im;
00765 }
00766 
00767 _STLP_DECLSPEC float  _STLP_CALL abs(const complex<float>&);
00768 _STLP_DECLSPEC double  _STLP_CALL abs(const complex<double>&);
00769 _STLP_DECLSPEC float  _STLP_CALL arg(const complex<float>&);
00770 _STLP_DECLSPEC double  _STLP_CALL arg(const complex<double>&);
00771 _STLP_DECLSPEC complex<float> _STLP_CALL polar(const float& __rho, const float& __phi);
00772 _STLP_DECLSPEC complex<double> _STLP_CALL polar(const double& __rho, const double& __phi);
00773 
00774 
00775 # ifndef _STLP_NO_LONG_DOUBLE
00776 _STLP_DECLSPEC long double  _STLP_CALL arg(const complex<long double>&);
00777 _STLP_DECLSPEC long double  _STLP_CALL abs(const complex<long double>&);
00778 _STLP_DECLSPEC complex<long double>  _STLP_CALL polar(const long double&, const long double&);
00779 # endif
00780 
00781 template <class _Tp>
00782 _Tp _STLP_CALL abs(const complex<_Tp>& __z) {
00783   return _Tp(abs(complex<double>(double(__z.real()), double(__z.imag()))));
00784 }
00785 
00786 template <class _Tp>
00787 _Tp _STLP_CALL arg(const complex<_Tp>& __z) {
00788   return _Tp(arg(complex<double>(double(__z.real()), double(__z.imag()))));
00789 }
00790 
00791 template <class _Tp>
00792 inline _Tp _STLP_CALL norm(const complex<_Tp>& __z) {
00793   return __z._M_re * __z._M_re + __z._M_im * __z._M_im;
00794 }
00795 
00796 template <class _Tp>
00797 inline complex<_Tp> _STLP_CALL conj(const complex<_Tp>& __z) {
00798   return complex<_Tp>(__z._M_re, -__z._M_im);
00799 }
00800 
00801 template <class _Tp>
00802 complex<_Tp> _STLP_CALL polar(const _Tp& __rho) {
00803   return complex<_Tp>(__rho, 0);
00804 }
00805 
00806 template <class _Tp>
00807 complex<_Tp> _STLP_CALL polar(const _Tp& __rho, const _Tp& __phi) {
00808   complex<double> __tmp = polar(double(__rho), double(__phi));
00809   return complex<_Tp>(_Tp(__tmp.real()), _Tp(__tmp.imag()));
00810 }
00811 
00812 #ifdef _STLP_USE_NEW_IOSTREAMS
00813 
00814 // Complex output, in the form (re,im).  We use a two-step process 
00815 // involving stringstream so that we get the padding right.  
00816 template <class _Tp, class _CharT, class _Traits>
00817 basic_ostream<_CharT, _Traits>&  _STLP_CALL 
00818 operator<<(basic_ostream<_CharT, _Traits>& __os, const complex<_Tp>& __z);
00819 
00820 template <class _Tp, class _CharT, class _Traits>
00821 basic_istream<_CharT, _Traits>& _STLP_CALL 
00822 operator>>(basic_istream<_CharT, _Traits>& __is, complex<_Tp>& __z);
00823 
00824 // Specializations for narrow characters; lets us avoid widen.
00825 
00826 _STLP_OPERATOR_TEMPLATE
00827 _STLP_DECLSPEC basic_istream<char, char_traits<char> >& _STLP_CALL 
00828 operator>>(basic_istream<char, char_traits<char> >& __is, complex<float>& __z);
00829 
00830 _STLP_OPERATOR_TEMPLATE
00831 _STLP_DECLSPEC basic_istream<char, char_traits<char> >& _STLP_CALL 
00832 operator>>(basic_istream<char, char_traits<char> >& __is, complex<double>& __z);
00833 
00834 
00835 _STLP_OPERATOR_TEMPLATE
00836 _STLP_DECLSPEC basic_ostream<char, char_traits<char> >& _STLP_CALL 
00837 operator<<(basic_ostream<char, char_traits<char> >& __is, const complex<float>& __z);
00838 
00839 _STLP_OPERATOR_TEMPLATE
00840 _STLP_DECLSPEC basic_ostream<char, char_traits<char> >& _STLP_CALL 
00841 operator<<(basic_ostream<char, char_traits<char> >& __is, const complex<double>& __z);
00842 
00843 #  if ! defined (_STLP_NO_LONG_DOUBLE)
00844 _STLP_OPERATOR_TEMPLATE
00845 _STLP_DECLSPEC basic_istream<char, char_traits<char> >& _STLP_CALL 
00846 operator>>(basic_istream<char, char_traits<char> >& __is, complex<long double>& __z);
00847 
00848 _STLP_OPERATOR_TEMPLATE
00849 _STLP_DECLSPEC basic_ostream<char, char_traits<char> >& _STLP_CALL 
00850 operator<<(basic_ostream<char, char_traits<char> >& __is, const complex<long double>& __z);
00851 
00852 # endif
00853 
00854 # if defined (_STLP_USE_TEMPLATE_EXPORT) && ! defined (_STLP_NO_WCHAR_T)
00855 
00856 _STLP_EXPORT_TEMPLATE basic_istream<wchar_t, char_traits<wchar_t> >& _STLP_CALL operator>>(
00857         basic_istream<wchar_t, char_traits<wchar_t> >&, complex<double>&);
00858 _STLP_EXPORT_TEMPLATE basic_ostream<wchar_t, char_traits<wchar_t> >& _STLP_CALL operator<<(
00859         basic_ostream<wchar_t, char_traits<wchar_t> >&, const complex<double>&);
00860 _STLP_EXPORT_TEMPLATE basic_istream<wchar_t, char_traits<wchar_t> >& _STLP_CALL operator>>(
00861         basic_istream<wchar_t, char_traits<wchar_t> >&, complex<float>&);
00862 _STLP_EXPORT_TEMPLATE basic_ostream<wchar_t, char_traits<wchar_t> >& _STLP_CALL operator<<(
00863         basic_ostream<wchar_t, char_traits<wchar_t> >&, const complex<float>&);
00864 
00865 #  ifndef _STLP_NO_LONG_DOUBLE
00866 _STLP_EXPORT_TEMPLATE basic_istream<wchar_t, char_traits<wchar_t> >& _STLP_CALL operator>>(
00867         basic_istream<wchar_t, char_traits<wchar_t> >&, complex<long double>&);
00868 _STLP_EXPORT_TEMPLATE basic_ostream<wchar_t, char_traits<wchar_t> >& _STLP_CALL operator<<(
00869         basic_ostream<wchar_t, char_traits<wchar_t> >&, const complex<long double>&);
00870 #  endif
00871 
00872 # endif /* USE_TEMPLATE_EXPORT */
00873 
00874 #else /* _STLP_USE_NEW_IOSTREAMS */
00875 
00876 template <class _Tp>
00877 ostream& _STLP_CALL operator<<(ostream& s, const complex<_Tp>& __z);
00878 
00879 template <class _Tp>
00880 istream& _STLP_CALL  operator>>(istream& s, complex<_Tp>& a);
00881 
00882 #endif /* _STLP_USE_NEW_IOSTREAMS */
00883 
00884 
00885 // Transcendental functions.  These are defined only for float, 
00886 //  double, and long double.  (Sqrt isn't transcendental, of course,
00887 //  but it's included in this section anyway.)
00888 
00889 _STLP_DECLSPEC complex<float> _STLP_CALL sqrt(const complex<float>&);
00890 
00891 _STLP_DECLSPEC complex<float> _STLP_CALL exp(const complex<float>&);
00892 _STLP_DECLSPEC complex<float> _STLP_CALL  log(const complex<float>&);
00893 _STLP_DECLSPEC complex<float> _STLP_CALL log10(const complex<float>&);
00894 
00895 _STLP_DECLSPEC complex<float> _STLP_CALL pow(const complex<float>&, int);
00896 _STLP_DECLSPEC complex<float> _STLP_CALL pow(const complex<float>&, const float&);
00897 _STLP_DECLSPEC complex<float> _STLP_CALL pow(const float&, const complex<float>&);
00898 _STLP_DECLSPEC complex<float> _STLP_CALL pow(const complex<float>&, const complex<float>&);
00899 
00900 _STLP_DECLSPEC complex<float> _STLP_CALL sin(const complex<float>&);
00901 _STLP_DECLSPEC complex<float> _STLP_CALL cos(const complex<float>&);
00902 _STLP_DECLSPEC complex<float> _STLP_CALL tan(const complex<float>&);
00903 
00904 _STLP_DECLSPEC complex<float> _STLP_CALL sinh(const complex<float>&);
00905 _STLP_DECLSPEC complex<float> _STLP_CALL cosh(const complex<float>&);
00906 _STLP_DECLSPEC complex<float> _STLP_CALL tanh(const complex<float>&);
00907 
00908 _STLP_DECLSPEC complex<double> _STLP_CALL sqrt(const complex<double>&);
00909 
00910 _STLP_DECLSPEC complex<double> _STLP_CALL exp(const complex<double>&);
00911 _STLP_DECLSPEC complex<double> _STLP_CALL log(const complex<double>&);
00912 _STLP_DECLSPEC complex<double> _STLP_CALL log10(const complex<double>&);
00913 
00914 _STLP_DECLSPEC complex<double> _STLP_CALL pow(const complex<double>&, int);
00915 _STLP_DECLSPEC complex<double> _STLP_CALL pow(const complex<double>&, const double&);
00916 _STLP_DECLSPEC complex<double> _STLP_CALL pow(const double&, const complex<double>&);
00917 _STLP_DECLSPEC complex<double> _STLP_CALL pow(const complex<double>&, const complex<double>&);
00918 
00919 _STLP_DECLSPEC complex<double> _STLP_CALL sin(const complex<double>&);
00920 _STLP_DECLSPEC complex<double> _STLP_CALL cos(const complex<double>&);
00921 _STLP_DECLSPEC complex<double> _STLP_CALL tan(const complex<double>&);
00922 
00923 _STLP_DECLSPEC complex<double> _STLP_CALL sinh(const complex<double>&);
00924 _STLP_DECLSPEC complex<double> _STLP_CALL cosh(const complex<double>&);
00925 _STLP_DECLSPEC complex<double> _STLP_CALL tanh(const complex<double>&);
00926 
00927 # ifndef _STLP_NO_LONG_DOUBLE
00928 _STLP_DECLSPEC complex<long double> _STLP_CALL sqrt(const complex<long double>&);
00929 _STLP_DECLSPEC complex<long double> _STLP_CALL exp(const complex<long double>&);
00930 _STLP_DECLSPEC complex<long double> _STLP_CALL log(const complex<long double>&);
00931 _STLP_DECLSPEC complex<long double> _STLP_CALL log10(const complex<long double>&);
00932 
00933 _STLP_DECLSPEC complex<long double> _STLP_CALL pow(const complex<long double>&, int);
00934 _STLP_DECLSPEC complex<long double> _STLP_CALL pow(const complex<long double>&, const long double&);
00935 _STLP_DECLSPEC complex<long double> _STLP_CALL pow(const long double&, const complex<long double>&);
00936 _STLP_DECLSPEC complex<long double> _STLP_CALL pow(const complex<long double>&,
00937                                                    const complex<long double>&);
00938 
00939 _STLP_DECLSPEC complex<long double> _STLP_CALL sin(const complex<long double>&);
00940 _STLP_DECLSPEC complex<long double> _STLP_CALL cos(const complex<long double>&);
00941 _STLP_DECLSPEC complex<long double> _STLP_CALL tan(const complex<long double>&);
00942 
00943 _STLP_DECLSPEC complex<long double> _STLP_CALL sinh(const complex<long double>&);
00944 _STLP_DECLSPEC complex<long double> _STLP_CALL cosh(const complex<long double>&);
00945 _STLP_DECLSPEC complex<long double> _STLP_CALL tanh(const complex<long double>&);
00946 # endif
00947 
00948 _STLP_END_NAMESPACE
00949 
00950 # ifndef _STLP_LINK_TIME_INSTANTIATION
00951 #  include <stl/_complex.c>
00952 # endif
00953 
00954 #endif /* _STLP_template_complex */
00955 
00956 // Local Variables:
00957 // mode:C++
00958 // End:

Generated on Mon Jun 5 10:20:45 2006 for Intelligence.kdevelop by  doxygen 1.4.6