/home/ntakagi/work/STLport-5.1.5/stlport/stl/_complex.h

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



Generated on Mon Mar 10 15:32:20 2008 by  doxygen 1.5.1