epoc32/include/stdapis/stlport/stl/_complex.h
author William Roberts <williamr@symbian.org>
Tue, 16 Mar 2010 16:12:26 +0000
branchSymbian2
changeset 2 2fe1408b6811
parent 0 061f57f2323e
permissions -rw-r--r--
Final list of Symbian^2 public API header files
     1 /*
     2  * Copyright (c) 1999
     3  * Silicon Graphics Computer Systems, Inc.
     4  *
     5  * Copyright (c) 1999 
     6  * Boris Fomitchev
     7  *
     8  * This material is provided "as is", with absolutely no warranty expressed
     9  * or implied. Any use is at your own risk.
    10  *
    11  * Permission to use or copy this software for any purpose is hereby granted 
    12  * without fee, provided the above notices are retained on all copies.
    13  * Permission to modify the code and to distribute modified code is granted,
    14  * provided the above notices are retained, and a notice that the code was
    15  * modified is included with the above copyright notice.
    16  *
    17  */ 
    18 #ifndef _STLP_internal_complex_h
    19 #define _STLP_internal_complex_h
    20 
    21 // This header declares the template class complex, as described in 
    22 // in the draft C++ standard.  Single-precision complex numbers
    23 // are complex<float>, double-precision are complex<double>, and
    24 // quad precision are complex<long double>.
    25 
    26 // Note that the template class complex is declared within namespace
    27 // std, as called for by the draft C++ standard.  
    28 
    29 #include <stl/_cmath.h>
    30 #include <iosfwd>
    31 
    32 _STLP_BEGIN_NAMESPACE
    33 
    34 #if !defined(_STLP_NO_COMPLEX_SPECIALIZATIONS)		//*TY 02/25/2000 - added for MPW compiler workaround
    35 
    36 template <class _Tp> struct complex;
    37 
    38 _STLP_TEMPLATE_NULL  struct _STLP_CLASS_DECLSPEC complex<float>;
    39 _STLP_TEMPLATE_NULL  struct _STLP_CLASS_DECLSPEC complex<double>;
    40 # ifndef _STLP_NO_LONG_DOUBLE
    41 _STLP_TEMPLATE_NULL  struct _STLP_CLASS_DECLSPEC complex<long double>;
    42 # endif
    43 # endif
    44 
    45 template <class _Tp>
    46 struct complex {
    47   typedef _Tp value_type;
    48   typedef complex<_Tp> _Self;
    49 
    50   // Constructors, destructor, assignment operator.
    51   complex() : _M_re(0), _M_im(0) {}
    52   complex(const value_type& __x)
    53     : _M_re(__x), _M_im(0) {}
    54   complex(const value_type& __x, const value_type& __y)
    55     : _M_re(__x), _M_im(__y) {}
    56   complex(const _Self& __z)
    57     : _M_re(__z._M_re), _M_im(__z._M_im) {}
    58 
    59   _Self& operator=(const _Self& __z) {
    60     _M_re = __z._M_re;
    61     _M_im = __z._M_im;
    62     return *this;
    63   }
    64 
    65 #if defined (_STLP_MEMBER_TEMPLATES) && ( defined (_STLP_FUNCTION_TMPL_PARTIAL_ORDER) || defined(_STLP_NO_COMPLEX_SPECIALIZATIONS))
    66   template <class _Tp2>
    67   explicit complex(const complex<_Tp2>& __z)
    68     : _M_re(__z._M_re), _M_im(__z._M_im) {}
    69 
    70   template <class _Tp2>
    71   _Self& operator=(const complex<_Tp2>& __z) {
    72     _M_re = __z._M_re;
    73     _M_im = __z._M_im;
    74     return *this;
    75   }
    76 #endif /* _STLP_MEMBER_TEMPLATES */
    77 
    78   // Element access.
    79   value_type real() const { return _M_re; }
    80   value_type imag() const { return _M_im; }
    81 
    82   // Arithmetic op= operations involving one real argument.
    83 
    84   _Self& operator= (const value_type& __x) {
    85     _M_re = __x;
    86     _M_im = 0;
    87     return *this;
    88   }
    89   _Self& operator+= (const value_type& __x) {
    90     _M_re += __x;
    91     return *this;
    92   }
    93   _Self& operator-= (const value_type& __x) {
    94     _M_re -= __x;
    95     return *this;
    96   }
    97   _Self& operator*= (const value_type& __x) {
    98     _M_re *= __x;
    99     _M_im *= __x;
   100     return *this;
   101   }
   102   _Self& operator/= (const value_type& __x) {
   103     _M_re /= __x;
   104     _M_im /= __x;
   105     return *this;
   106   }
   107 
   108   // Arithmetic op= operations involving two complex arguments.
   109 
   110   static void  _STLP_CALL _div(const value_type& __z1_r, const value_type& __z1_i,
   111                    const value_type& __z2_r, const value_type& __z2_i,
   112                    value_type& __res_r, value_type& __res_i);
   113 
   114   static void _STLP_CALL _div(const value_type& __z1_r, 
   115                    const value_type& __z2_r, const value_type& __z2_i,
   116                    value_type& __res_r, value_type& __res_i);
   117 
   118 #if defined ( _STLP_MEMBER_TEMPLATES ) // && defined (_STLP_FUNCTION_TMPL_PARTIAL_ORDER)
   119 
   120   template <class _Tp2> _Self& operator+= (const complex<_Tp2>& __z) {
   121     _M_re += __z._M_re;
   122     _M_im += __z._M_im;
   123     return *this;
   124   }
   125 
   126   template <class _Tp2> _Self& operator-= (const complex<_Tp2>& __z) {
   127     _M_re -= __z._M_re;
   128     _M_im -= __z._M_im;
   129     return *this;
   130   }
   131 
   132   template <class _Tp2> _Self& operator*= (const complex<_Tp2>& __z) {
   133     value_type __r = _M_re * __z._M_re - _M_im * __z._M_im;
   134     value_type __i = _M_re * __z._M_im + _M_im * __z._M_re;
   135     _M_re = __r;
   136     _M_im = __i;
   137     return *this;
   138   }
   139 
   140   template <class _Tp2> _Self& operator/= (const complex<_Tp2>& __z) {
   141     value_type __r;
   142     value_type __i;
   143     _div(_M_re, _M_im, __z._M_re, __z._M_im, __r, __i);
   144     _M_re = __r;
   145     _M_im = __i;
   146     return *this;
   147   }
   148 
   149 #endif /* _STLP_MEMBER_TEMPLATES */
   150 
   151   _Self& operator+= (const _Self& __z) {
   152     _M_re += __z._M_re;
   153     _M_im += __z._M_im;
   154     return *this;
   155   }
   156 
   157   _Self& operator-= (const _Self& __z) {
   158     _M_re -= __z._M_re;
   159     _M_im -= __z._M_im;
   160     return *this;
   161   }
   162   
   163   _Self& operator*= (const _Self& __z) {
   164     value_type __r = _M_re * __z._M_re - _M_im * __z._M_im;
   165     value_type __i = _M_re * __z._M_im + _M_im * __z._M_re;
   166     _M_re = __r;
   167     _M_im = __i;
   168     return *this;
   169   }
   170 
   171   _Self& operator/= (const _Self& __z) {
   172     value_type __r;
   173     value_type __i;
   174     _div(_M_re, _M_im, __z._M_re, __z._M_im, __r, __i);
   175     _M_re = __r;
   176     _M_im = __i;
   177     return *this;
   178   }
   179 
   180   // Data members.
   181   value_type _M_re;
   182   value_type _M_im;
   183 };
   184 
   185 #if !defined(_STLP_NO_COMPLEX_SPECIALIZATIONS)		//*TY 02/25/2000 - added for MPW compiler workaround
   186 // Explicit specializations for float, double, long double.  The only
   187 // reason for these specializations is to enable automatic conversions
   188 // from complex<float> to complex<double>, and complex<double> to
   189 // complex<long double>.
   190 
   191 
   192 _STLP_TEMPLATE_NULL
   193 struct _STLP_CLASS_DECLSPEC complex<float> {
   194   typedef float value_type;
   195   typedef complex<float> _Self;
   196   // Constructors, destructor, assignment operator.
   197 
   198   complex(value_type __x = 0.0, value_type __y = 0.0)
   199     : _M_re(__x), _M_im(__y) {}
   200 
   201   complex(const complex<float>& __z)    : _M_re(__z._M_re), _M_im(__z._M_im) {} 
   202 
   203   inline explicit complex(const complex<double>& __z);
   204 # ifndef _STLP_NO_LONG_DOUBLE
   205   inline explicit complex(const complex<long double>& __z);
   206 # endif
   207   // Element access.
   208   value_type real() const { return _M_re; }
   209   value_type imag() const { return _M_im; }
   210 
   211   // Arithmetic op= operations involving one real argument.
   212 
   213   _Self& operator= (value_type __x) {
   214     _M_re = __x;
   215     _M_im = 0;
   216     return *this;
   217   }
   218   _Self& operator+= (value_type __x) {
   219     _M_re += __x;
   220     return *this;
   221   }
   222   _Self& operator-= (value_type __x) {
   223     _M_re -= __x;
   224     return *this;
   225   }
   226   _Self& operator*= (value_type __x) {
   227     _M_re *= __x;
   228     _M_im *= __x;
   229     return *this;
   230   }
   231   _Self& operator/= (value_type __x) {
   232     _M_re /= __x;
   233     _M_im /= __x;
   234     return *this;
   235   }
   236 
   237   // Arithmetic op= operations involving two complex arguments.
   238 
   239    _STLP_DECLSPEC static void _STLP_CALL _div(const float& __z1_r, const float& __z1_i,
   240                               const float& __z2_r, const float& __z2_i,
   241                               float& __res_r, float& __res_i);
   242     
   243    _STLP_DECLSPEC static void _STLP_CALL _div(const float& __z1_r, 
   244                               const float& __z2_r, const float& __z2_i,
   245                               float& __res_r, float& __res_i);
   246     
   247 #if defined (_STLP_MEMBER_TEMPLATES)
   248 
   249   template <class _Tp2>
   250   complex<float>& operator=(const complex<_Tp2>& __z) {
   251     _M_re = __z._M_re;
   252     _M_im = __z._M_im;
   253     return *this;
   254   }
   255 
   256   template <class _Tp2>
   257   complex<float>& operator+= (const complex<_Tp2>& __z) {
   258     _M_re += __z._M_re;
   259     _M_im += __z._M_im;
   260     return *this;
   261   }
   262 
   263   template <class _Tp2>
   264   complex<float>& operator-= (const complex<_Tp2>& __z) {
   265     _M_re -= __z._M_re;
   266     _M_im -= __z._M_im;
   267     return *this;
   268   }
   269 
   270   template <class _Tp2>
   271   complex<float>& operator*= (const complex<_Tp2>& __z) {
   272     float __r = _M_re * __z._M_re - _M_im * __z._M_im;
   273     float __i = _M_re * __z._M_im + _M_im * __z._M_re;
   274     _M_re = __r;
   275     _M_im = __i;
   276     return *this;
   277   }
   278 
   279   template <class _Tp2>
   280   complex<float>& operator/= (const complex<_Tp2>& __z) {
   281     float __r;
   282     float __i;
   283     _div(_M_re, _M_im, __z._M_re, __z._M_im, __r, __i);
   284     _M_re = __r;
   285     _M_im = __i;
   286     return *this;
   287   }
   288 
   289 #endif /* _STLP_MEMBER_TEMPLATES */
   290 
   291   _Self& operator=(const _Self& __z) {
   292     _M_re = __z._M_re;
   293     _M_im = __z._M_im;
   294     return *this;
   295   }
   296 
   297   _Self& operator+= (const _Self& __z) {
   298     _M_re += __z._M_re;
   299     _M_im += __z._M_im;
   300     return *this;
   301   }
   302 
   303   _Self& operator-= (const _Self& __z) {
   304     _M_re -= __z._M_re;
   305     _M_im -= __z._M_im;
   306     return *this;
   307   }
   308   
   309   _Self& operator*= (const _Self& __z) {
   310     value_type __r = _M_re * __z._M_re - _M_im * __z._M_im;
   311     value_type __i = _M_re * __z._M_im + _M_im * __z._M_re;
   312     _M_re = __r;
   313     _M_im = __i;
   314     return *this;
   315   }
   316 
   317   _Self& operator/= (const _Self& __z) {
   318     value_type __r;
   319     value_type __i;
   320     _div(_M_re, _M_im, __z._M_re, __z._M_im, __r, __i);
   321     _M_re = __r;
   322     _M_im = __i;
   323     return *this;
   324   }
   325 
   326   // Data members.
   327   value_type _M_re;
   328   value_type _M_im;
   329 };
   330 
   331 _STLP_TEMPLATE_NULL struct _STLP_CLASS_DECLSPEC complex<double> {
   332   typedef double value_type;
   333   typedef complex<double> _Self;
   334 
   335   // Constructors, destructor, assignment operator.
   336 
   337   complex(value_type __x = 0.0, value_type __y = 0.0)
   338     : _M_re(__x), _M_im(__y) {}
   339 
   340   complex(const complex<double>& __z)
   341     : _M_re(__z._M_re), _M_im(__z._M_im) {}
   342   inline complex(const complex<float>& __z);
   343 # ifndef _STLP_NO_LONG_DOUBLE
   344   explicit inline complex(const complex<long double>& __z);
   345 # endif
   346   // Element access.
   347   value_type real() const { return _M_re; }
   348   value_type imag() const { return _M_im; }
   349 
   350   // Arithmetic op= operations involving one real argument.
   351 
   352   _Self& operator= (value_type __x) {
   353     _M_re = __x;
   354     _M_im = 0;
   355     return *this;
   356   }
   357   _Self& operator+= (value_type __x) {
   358     _M_re += __x;
   359     return *this;
   360   }
   361   _Self& operator-= (value_type __x) {
   362     _M_re -= __x;
   363     return *this;
   364   }
   365   _Self& operator*= (value_type __x) {
   366     _M_re *= __x;
   367     _M_im *= __x;
   368     return *this;
   369   }
   370   _Self& operator/= (value_type __x) {
   371     _M_re /= __x;
   372     _M_im /= __x;
   373     return *this;
   374   }
   375 
   376   // Arithmetic op= operations involving two complex arguments.
   377 
   378   _STLP_DECLSPEC static void _STLP_CALL _div(const double& __z1_r, const double& __z1_i,
   379                               const double& __z2_r, const double& __z2_i,
   380                               double& __res_r, double& __res_i);
   381   _STLP_DECLSPEC static void _STLP_CALL _div(const double& __z1_r, 
   382                               const double& __z2_r, const double& __z2_i,
   383                               double& __res_r, double& __res_i);
   384     
   385 #if defined (_STLP_MEMBER_TEMPLATES) && defined (_STLP_FUNCTION_TMPL_PARTIAL_ORDER)
   386 
   387   template <class _Tp2>
   388   complex<double>& operator=(const complex<_Tp2>& __z) {
   389     _M_re = __z._M_re;
   390     _M_im = __z._M_im;
   391     return *this;
   392   }
   393 
   394   template <class _Tp2>
   395   complex<double>& operator+= (const complex<_Tp2>& __z) {
   396     _M_re += __z._M_re;
   397     _M_im += __z._M_im;
   398     return *this;
   399   }
   400 
   401   template <class _Tp2>
   402   complex<double>& operator-= (const complex<_Tp2>& __z) {
   403     _M_re -= __z._M_re;
   404     _M_im -= __z._M_im;
   405     return *this;
   406   }
   407 
   408   template <class _Tp2>
   409   complex<double>& operator*= (const complex<_Tp2>& __z) {
   410     double __r = _M_re * __z._M_re - _M_im * __z._M_im;
   411     double __i = _M_re * __z._M_im + _M_im * __z._M_re;
   412     _M_re = __r;
   413     _M_im = __i;
   414     return *this;
   415   }
   416 
   417   template <class _Tp2>
   418   complex<double>& operator/= (const complex<_Tp2>& __z) {
   419     double __r;
   420     double __i;
   421     _div(_M_re, _M_im, __z._M_re, __z._M_im, __r, __i);
   422     _M_re = __r;
   423     _M_im = __i;
   424     return *this;
   425   }
   426 
   427 #endif /* _STLP_MEMBER_TEMPLATES */
   428 
   429   _Self& operator=(const _Self& __z) {
   430     _M_re = __z._M_re;
   431     _M_im = __z._M_im;
   432     return *this;
   433   }
   434 
   435   _Self& operator+= (const _Self& __z) {
   436     _M_re += __z._M_re;
   437     _M_im += __z._M_im;
   438     return *this;
   439   }
   440 
   441   _Self& operator-= (const _Self& __z) {
   442     _M_re -= __z._M_re;
   443     _M_im -= __z._M_im;
   444     return *this;
   445   }
   446   
   447   _Self& operator*= (const _Self& __z) {
   448     value_type __r = _M_re * __z._M_re - _M_im * __z._M_im;
   449     value_type __i = _M_re * __z._M_im + _M_im * __z._M_re;
   450     _M_re = __r;
   451     _M_im = __i;
   452     return *this;
   453   }
   454 
   455   _Self& operator/= (const _Self& __z) {
   456     value_type __r;
   457     value_type __i;
   458     _div(_M_re, _M_im, __z._M_re, __z._M_im, __r, __i);
   459     _M_re = __r;
   460     _M_im = __i;
   461     return *this;
   462   }
   463 
   464   // Data members.
   465   value_type _M_re;
   466   value_type _M_im;
   467 };
   468 
   469 # ifndef _STLP_NO_LONG_DOUBLE
   470 
   471 _STLP_TEMPLATE_NULL struct _STLP_CLASS_DECLSPEC complex<long double> {
   472   typedef long double value_type;
   473   typedef complex<long double> _Self;
   474 
   475   // Constructors, destructor, assignment operator.
   476   complex(value_type __x = 0.0, value_type __y = 0.0)
   477     : _M_re(__x), _M_im(__y) {}
   478 
   479   complex(const complex<long double>& __z)
   480     : _M_re(__z._M_re), _M_im(__z._M_im) {}
   481   inline complex(const complex<float>& __z);
   482   inline complex(const complex<double>& __z);
   483 
   484   // Element access.
   485   value_type real() const { return _M_re; }
   486   value_type imag() const { return _M_im; }
   487 
   488   // Arithmetic op= operations involving one real argument.
   489 
   490   _Self& operator= (value_type __x) {
   491     _M_re = __x;
   492     _M_im = 0;
   493     return *this;
   494   }
   495   _Self& operator+= (value_type __x) {
   496     _M_re += __x;
   497     return *this;
   498   }
   499   _Self& operator-= (value_type __x) {
   500     _M_re -= __x;
   501     return *this;
   502   }
   503   _Self& operator*= (value_type __x) {
   504     _M_re *= __x;
   505     _M_im *= __x;
   506     return *this;
   507   }
   508   _Self& operator/= (value_type __x) {
   509     _M_re /= __x;
   510     _M_im /= __x;
   511     return *this;
   512   }
   513 
   514   // Arithmetic op= operations involving two complex arguments.
   515 
   516   _STLP_DECLSPEC static void _STLP_CALL _div(const long double& __z1_r, const long double& __z1_i,
   517                               const long double& __z2_r, const long double& __z2_i,
   518                               long double& __res_r, long double& __res_i);
   519 
   520   _STLP_DECLSPEC static void _STLP_CALL _div(const long double& __z1_r, 
   521                               const long double& __z2_r, const long double& __z2_i,
   522                               long double& __res_r, long double& __res_i);
   523 
   524 #if defined (_STLP_MEMBER_TEMPLATES) && defined (_STLP_FUNCTION_TMPL_PARTIAL_ORDER)
   525 
   526   template <class _Tp2>
   527   complex<long double>& operator=(const complex<_Tp2>& __z) {
   528     _M_re = __z._M_re;
   529     _M_im = __z._M_im;
   530     return *this;
   531   }
   532 
   533   template <class _Tp2>
   534   complex<long double>& operator+= (const complex<_Tp2>& __z) {
   535     _M_re += __z._M_re;
   536     _M_im += __z._M_im;
   537     return *this;
   538   }
   539 
   540   template <class _Tp2>
   541   complex<long double>& operator-= (const complex<_Tp2>& __z) {
   542     _M_re -= __z._M_re;
   543     _M_im -= __z._M_im;
   544     return *this;
   545   }
   546 
   547   template <class _Tp2>
   548   complex<long double>& operator*= (const complex<_Tp2>& __z) {
   549     long double __r = _M_re * __z._M_re - _M_im * __z._M_im;
   550     long double __i = _M_re * __z._M_im + _M_im * __z._M_re;
   551     _M_re = __r;
   552     _M_im = __i;
   553     return *this;
   554   }
   555 
   556   template <class _Tp2>
   557   complex<long double>& operator/= (const complex<_Tp2>& __z) {
   558     long double __r;
   559     long double __i;
   560     _div(_M_re, _M_im, __z._M_re, __z._M_im, __r, __i);
   561     _M_re = __r;
   562     _M_im = __i;
   563     return *this;
   564   }
   565 
   566 #endif /* _STLP_MEMBER_TEMPLATES */
   567 
   568   _Self& operator=(const _Self& __z) {
   569     _M_re = __z._M_re;
   570     _M_im = __z._M_im;
   571     return *this;
   572   }
   573 
   574   _Self& operator+= (const _Self& __z) {
   575     _M_re += __z._M_re;
   576     _M_im += __z._M_im;
   577     return *this;
   578   }
   579 
   580   _Self& operator-= (const _Self& __z) {
   581     _M_re -= __z._M_re;
   582     _M_im -= __z._M_im;
   583     return *this;
   584   }
   585   
   586   _Self& operator*= (const _Self& __z) {
   587     value_type __r = _M_re * __z._M_re - _M_im * __z._M_im;
   588     value_type __i = _M_re * __z._M_im + _M_im * __z._M_re;
   589     _M_re = __r;
   590     _M_im = __i;
   591     return *this;
   592   }
   593 
   594   _Self& operator/= (const _Self& __z) {
   595     value_type __r;
   596     value_type __i;
   597     _div(_M_re, _M_im, __z._M_re, __z._M_im, __r, __i);
   598     _M_re = __r;
   599     _M_im = __i;
   600     return *this;
   601   }
   602 
   603   // Data members.
   604   value_type _M_re;
   605   value_type _M_im;
   606 };
   607 
   608 # endif /* _STLP_NO_LONG_DOUBLE */
   609 
   610 // Converting constructors from one of these three specialized types
   611 // to another.
   612 
   613 inline complex<float>::complex(const complex<double>& __z)
   614   : _M_re(__z._M_re), _M_im(__z._M_im) {}
   615 inline complex<double>::complex(const complex<float>& __z)
   616   : _M_re(__z._M_re), _M_im(__z._M_im) {}
   617 # ifndef _STLP_NO_LONG_DOUBLE
   618 inline complex<float>::complex(const complex<long double>& __z)
   619   : _M_re(__z._M_re), _M_im(__z._M_im) {}
   620 inline complex<double>::complex(const complex<long double>& __z)
   621   : _M_re(__z._M_re), _M_im(__z._M_im) {}
   622 inline complex<long double>::complex(const complex<float>& __z)
   623   : _M_re(__z._M_re), _M_im(__z._M_im) {}
   624 inline complex<long double>::complex(const complex<double>& __z)
   625   : _M_re(__z._M_re), _M_im(__z._M_im) {}
   626 # endif
   627 
   628 # endif /* SPECIALIZATIONS */
   629 
   630 // Unary non-member arithmetic operators.
   631 
   632 template <class _Tp>
   633 inline complex<_Tp> _STLP_CALL operator+(const complex<_Tp>& __z) {
   634   return __z;
   635 }
   636 
   637 template <class _Tp>
   638 inline complex<_Tp> _STLP_CALL  operator-(const complex<_Tp>& __z) {
   639   return complex<_Tp>(-__z._M_re, -__z._M_im);
   640 }
   641 
   642 // Non-member arithmetic operations involving one real argument.
   643 
   644 template <class _Tp> 
   645 inline complex<_Tp> _STLP_CALL operator+(const _Tp& __x, const complex<_Tp>& __z) {
   646   return complex<_Tp>(__x + __z._M_re, __z._M_im);
   647 }
   648 
   649 template <class _Tp> 
   650 inline complex<_Tp> _STLP_CALL operator+(const complex<_Tp>& __z, const _Tp& __x) {
   651   return complex<_Tp>(__z._M_re + __x, __z._M_im);
   652 }
   653 
   654 template <class _Tp> 
   655 inline complex<_Tp> _STLP_CALL operator-(const _Tp& __x, const complex<_Tp>& __z) {
   656   return complex<_Tp>(__x - __z._M_re, -__z._M_im);
   657 }
   658 
   659 template <class _Tp> 
   660 inline complex<_Tp> _STLP_CALL operator-(const complex<_Tp>& __z, const _Tp& __x) {
   661   return complex<_Tp>(__z._M_re - __x, __z._M_im);
   662 }
   663 
   664 template <class _Tp> 
   665 inline complex<_Tp> _STLP_CALL operator*(const _Tp& __x, const complex<_Tp>& __z) {
   666   return complex<_Tp>(__x * __z._M_re, __x * __z._M_im);
   667 }
   668 
   669 template <class _Tp> 
   670 inline complex<_Tp> _STLP_CALL operator*(const complex<_Tp>& __z, const _Tp& __x) {
   671   return complex<_Tp>(__z._M_re * __x, __z._M_im * __x);
   672 }
   673 
   674 template <class _Tp> 
   675 inline complex<_Tp> _STLP_CALL operator/(const _Tp& __x, const complex<_Tp>& __z) {
   676   complex<_Tp> __result;
   677   complex<_Tp>::_div(__x,
   678                      __z._M_re, __z._M_im,
   679                      __result._M_re, __result._M_im);
   680   return __result;
   681 }
   682 
   683 template <class _Tp> 
   684 inline complex<_Tp> _STLP_CALL operator/(const complex<_Tp>& __z, const _Tp& __x) {
   685   return complex<_Tp>(__z._M_re / __x, __z._M_im / __x);
   686 }
   687 
   688 // Non-member arithmetic operations involving two complex arguments
   689 
   690 template <class _Tp> 
   691 inline complex<_Tp> _STLP_CALL 
   692 operator+(const complex<_Tp>& __z1, const complex<_Tp>& __z2) {
   693   return complex<_Tp>(__z1._M_re + __z2._M_re, __z1._M_im + __z2._M_im);
   694 }
   695 
   696 template <class _Tp> 
   697 inline complex<_Tp> _STLP_CALL 
   698 operator-(const complex<_Tp>& __z1, const complex<_Tp>& __z2) {
   699   return complex<_Tp>(__z1._M_re - __z2._M_re, __z1._M_im - __z2._M_im);
   700 }
   701 
   702 template <class _Tp> 
   703 inline complex<_Tp> _STLP_CALL 
   704 operator*(const complex<_Tp>& __z1, const complex<_Tp>& __z2) {
   705   return complex<_Tp>(__z1._M_re * __z2._M_re - __z1._M_im * __z2._M_im,
   706                       __z1._M_re * __z2._M_im + __z1._M_im * __z2._M_re);
   707 }
   708 
   709 template <class _Tp> 
   710 inline complex<_Tp> _STLP_CALL 
   711 operator/(const complex<_Tp>& __z1, const complex<_Tp>& __z2) {
   712   complex<_Tp> __result;
   713   complex<_Tp>::_div(__z1._M_re, __z1._M_im,
   714                      __z2._M_re, __z2._M_im,
   715                      __result._M_re, __result._M_im);
   716   return __result;
   717 }
   718 
   719 // Comparison operators.
   720 
   721 template <class _Tp> 
   722 inline bool _STLP_CALL operator==(const complex<_Tp>& __z1, const complex<_Tp>& __z2) {
   723   return __z1._M_re == __z2._M_re && __z1._M_im == __z2._M_im;
   724 }
   725 
   726 template <class _Tp> 
   727 inline bool _STLP_CALL operator==(const complex<_Tp>& __z, const _Tp& __x) {
   728   return __z._M_re == __x && __z._M_im == 0;
   729 }
   730 
   731 template <class _Tp> 
   732 inline bool _STLP_CALL operator==(const _Tp& __x, const complex<_Tp>& __z) {
   733   return __x == __z._M_re && 0 == __z._M_im;
   734 }
   735 
   736 #ifdef _STLP_FUNCTION_TMPL_PARTIAL_ORDER
   737 
   738 template <class _Tp> 
   739 inline bool _STLP_CALL operator!=(const complex<_Tp>& __z1, const complex<_Tp>& __z2) {
   740   return __z1._M_re != __z2._M_re || __z1._M_im != __z2._M_im;
   741 }
   742 
   743 #endif /* _STLP_FUNCTION_TMPL_PARTIAL_ORDER */
   744 
   745 template <class _Tp> 
   746 inline bool _STLP_CALL operator!=(const complex<_Tp>& __z, const _Tp& __x) {
   747   return __z._M_re != __x || __z._M_im != 0;
   748 }
   749 
   750 template <class _Tp> 
   751 inline bool _STLP_CALL operator!=(const _Tp& __x, const complex<_Tp>& __z) {
   752   return __x != __z._M_re || 0 != __z._M_im;
   753 }
   754 
   755 // Other basic arithmetic operations
   756 
   757 template <class _Tp> 
   758 inline _Tp _STLP_CALL real(const complex<_Tp>& __z) {
   759   return __z._M_re;
   760 }
   761 
   762 template <class _Tp> 
   763 inline _Tp _STLP_CALL imag(const complex<_Tp>& __z) {
   764   return __z._M_im;
   765 }
   766 
   767 #ifdef __SYMBIAN32__
   768 template <class _Tp>
   769 #ifdef __WINSCW__
   770 _STLP_DECLSPEC 
   771 #endif
   772 _Tp  _STLP_CALL abs_tp(const complex<_Tp>&);
   773 
   774 template <class _Tp>
   775 #ifdef __WINSCW__
   776 _STLP_DECLSPEC 
   777 #endif
   778 _Tp  _STLP_CALL arg_tp(const complex<_Tp>&);
   779 
   780 template <class _Tp>
   781 #ifdef __WINSCW__
   782 _STLP_DECLSPEC 
   783 #endif
   784 complex<_Tp> _STLP_CALL polar_tp(const _Tp& __rho, const _Tp& __phi);
   785 
   786 template <class _Tp>
   787 _Tp _STLP_CALL abs(const complex<_Tp>& __z)
   788  {
   789  return abs_tp(__z);
   790  }
   791 
   792 template <class _Tp>
   793 _Tp _STLP_CALL arg(const complex<_Tp>& __z)
   794  {
   795  return arg_tp(__z);
   796  }
   797 
   798 template <class _Tp>
   799 complex<_Tp> _STLP_CALL polar(const _Tp& __rho, const _Tp& __phi) {
   800  return polar_tp(__rho, __phi);
   801 }
   802 
   803 #else
   804 template <class _Tp>
   805 _Tp _STLP_CALL abs(const complex<_Tp>& __z) {
   806   return _Tp(abs(complex<double>(double(__z.real()), double(__z.imag()))));
   807 }
   808 
   809 template <class _Tp>
   810 _Tp _STLP_CALL arg(const complex<_Tp>& __z) {
   811   return _Tp(arg(complex<double>(double(__z.real()), double(__z.imag()))));
   812 }
   813 
   814 #endif
   815 
   816 
   817 template <class _Tp>
   818 inline _Tp _STLP_CALL norm(const complex<_Tp>& __z) {
   819   return __z._M_re * __z._M_re + __z._M_im * __z._M_im;
   820 }
   821 
   822 template <class _Tp>
   823 inline complex<_Tp> _STLP_CALL conj(const complex<_Tp>& __z) {
   824   return complex<_Tp>(__z._M_re, -__z._M_im);
   825 }
   826 
   827 template <class _Tp>
   828 complex<_Tp> _STLP_CALL polar(const _Tp& __rho) {
   829   return complex<_Tp>(__rho, 0);
   830 }
   831 
   832 #ifndef __SYMBIAN32__
   833 template <class _Tp>
   834 complex<_Tp> _STLP_CALL polar(const _Tp& __rho, const _Tp& __phi) {
   835   complex<double> __tmp = polar(double(__rho), double(__phi));
   836   return complex<_Tp>(_Tp(__tmp.real()), _Tp(__tmp.imag()));
   837 }
   838 
   839 
   840 _STLP_TEMPLATE_NULL
   841 _STLP_DECLSPEC float  _STLP_CALL abs(const complex<float>&);
   842 #ifndef _STLP_COMPLEX_SPECIALIZATION_BUG
   843 _STLP_TEMPLATE_NULL
   844 _STLP_DECLSPEC double  _STLP_CALL abs(const complex<double>&);
   845 _STLP_TEMPLATE_NULL
   846 _STLP_DECLSPEC double  _STLP_CALL arg(const complex<double>&);
   847 _STLP_TEMPLATE_NULL
   848 _STLP_DECLSPEC complex<double> _STLP_CALL polar(const double& __rho, const double& __phi);
   849 #endif
   850 _STLP_TEMPLATE_NULL
   851 _STLP_DECLSPEC float  _STLP_CALL arg(const complex<float>&);
   852 _STLP_TEMPLATE_NULL
   853 _STLP_DECLSPEC complex<float> _STLP_CALL polar(const float& __rho, const float& __phi);
   854 
   855 
   856 # ifndef _STLP_NO_LONG_DOUBLE
   857 _STLP_TEMPLATE_NULL
   858 _STLP_DECLSPEC long double  _STLP_CALL arg(const complex<long double>&);
   859 _STLP_TEMPLATE_NULL
   860 _STLP_DECLSPEC long double  _STLP_CALL abs(const complex<long double>&);
   861 _STLP_TEMPLATE_NULL
   862 _STLP_DECLSPEC complex<long double> _STLP_CALL polar(const long double&, const long double&);
   863 # endif
   864 #endif
   865 
   866 
   867 #ifdef _STLP_USE_NEW_IOSTREAMS
   868 
   869 // Complex output, in the form (re,im).  We use a two-step process 
   870 // involving stringstream so that we get the padding right.  
   871 template <class _Tp, class _CharT, class _Traits>
   872 basic_ostream<_CharT, _Traits>&  _STLP_CALL 
   873 operator<<(basic_ostream<_CharT, _Traits>& __os, const complex<_Tp>& __z);
   874 
   875 template <class _Tp, class _CharT, class _Traits>
   876 basic_istream<_CharT, _Traits>& _STLP_CALL 
   877 operator>>(basic_istream<_CharT, _Traits>& __is, complex<_Tp>& __z);
   878 
   879 // Specializations for narrow characters; lets us avoid widen.
   880 
   881 _STLP_OPERATOR_TEMPLATE
   882 _STLP_DECLSPEC basic_istream<char, char_traits<char> >& _STLP_CALL 
   883 operator>>(basic_istream<char, char_traits<char> >& __is, complex<float>& __z);
   884 
   885 _STLP_OPERATOR_TEMPLATE
   886 _STLP_DECLSPEC basic_istream<char, char_traits<char> >& _STLP_CALL 
   887 operator>>(basic_istream<char, char_traits<char> >& __is, complex<double>& __z);
   888 
   889 
   890 _STLP_OPERATOR_TEMPLATE
   891 _STLP_DECLSPEC basic_ostream<char, char_traits<char> >& _STLP_CALL 
   892 operator<<(basic_ostream<char, char_traits<char> >& __is, const complex<float>& __z);
   893 
   894 _STLP_OPERATOR_TEMPLATE
   895 _STLP_DECLSPEC basic_ostream<char, char_traits<char> >& _STLP_CALL 
   896 operator<<(basic_ostream<char, char_traits<char> >& __is, const complex<double>& __z);
   897 
   898 #  if ! defined (_STLP_NO_LONG_DOUBLE)
   899 _STLP_OPERATOR_TEMPLATE
   900 _STLP_DECLSPEC basic_istream<char, char_traits<char> >& _STLP_CALL 
   901 operator>>(basic_istream<char, char_traits<char> >& __is, complex<long double>& __z);
   902 
   903 _STLP_OPERATOR_TEMPLATE
   904 _STLP_DECLSPEC basic_ostream<char, char_traits<char> >& _STLP_CALL 
   905 operator<<(basic_ostream<char, char_traits<char> >& __is, const complex<long double>& __z);
   906 
   907 # endif
   908 
   909 # if defined (_STLP_USE_TEMPLATE_EXPORT) && ! defined (_STLP_NO_WCHAR_T)
   910 
   911 _STLP_EXPORT_TEMPLATE basic_istream<wchar_t, char_traits<wchar_t> >& _STLP_CALL operator>>(
   912         basic_istream<wchar_t, char_traits<wchar_t> >&, complex<double>&);
   913 _STLP_EXPORT_TEMPLATE basic_ostream<wchar_t, char_traits<wchar_t> >& _STLP_CALL operator<<(
   914         basic_ostream<wchar_t, char_traits<wchar_t> >&, const complex<double>&);
   915 _STLP_EXPORT_TEMPLATE basic_istream<wchar_t, char_traits<wchar_t> >& _STLP_CALL operator>>(
   916         basic_istream<wchar_t, char_traits<wchar_t> >&, complex<float>&);
   917 _STLP_EXPORT_TEMPLATE basic_ostream<wchar_t, char_traits<wchar_t> >& _STLP_CALL operator<<(
   918         basic_ostream<wchar_t, char_traits<wchar_t> >&, const complex<float>&);
   919 
   920 #  ifndef _STLP_NO_LONG_DOUBLE
   921 _STLP_EXPORT_TEMPLATE basic_istream<wchar_t, char_traits<wchar_t> >& _STLP_CALL operator>>(
   922         basic_istream<wchar_t, char_traits<wchar_t> >&, complex<long double>&);
   923 _STLP_EXPORT_TEMPLATE basic_ostream<wchar_t, char_traits<wchar_t> >& _STLP_CALL operator<<(
   924         basic_ostream<wchar_t, char_traits<wchar_t> >&, const complex<long double>&);
   925 #  endif
   926 
   927 # endif /* USE_TEMPLATE_EXPORT */
   928 
   929 #else /* _STLP_USE_NEW_IOSTREAMS */
   930 
   931 template <class _Tp>
   932 ostream& _STLP_CALL operator<<(ostream& s, const complex<_Tp>& __z);
   933 
   934 template <class _Tp>
   935 istream& _STLP_CALL  operator>>(istream& s, complex<_Tp>& a);
   936 
   937 #endif /* _STLP_USE_NEW_IOSTREAMS */
   938 
   939 
   940 // Transcendental functions.  These are defined only for float, 
   941 //  double, and long double.  (Sqrt isn't transcendental, of course,
   942 //  but it's included in this section anyway.)
   943 
   944 _STLP_DECLSPEC complex<float> _STLP_CALL sqrt(const complex<float>&);
   945 
   946 _STLP_DECLSPEC complex<float> _STLP_CALL exp(const complex<float>&);
   947 _STLP_DECLSPEC complex<float> _STLP_CALL  log(const complex<float>&);
   948 _STLP_DECLSPEC complex<float> _STLP_CALL log10(const complex<float>&);
   949 
   950 _STLP_DECLSPEC complex<float> _STLP_CALL pow(const complex<float>&, int);
   951 _STLP_DECLSPEC complex<float> _STLP_CALL pow(const complex<float>&, const float&);
   952 _STLP_DECLSPEC complex<float> _STLP_CALL pow(const float&, const complex<float>&);
   953 _STLP_DECLSPEC complex<float> _STLP_CALL pow(const complex<float>&, const complex<float>&);
   954 
   955 _STLP_DECLSPEC complex<float> _STLP_CALL sin(const complex<float>&);
   956 _STLP_DECLSPEC complex<float> _STLP_CALL cos(const complex<float>&);
   957 _STLP_DECLSPEC complex<float> _STLP_CALL tan(const complex<float>&);
   958 
   959 _STLP_DECLSPEC complex<float> _STLP_CALL sinh(const complex<float>&);
   960 _STLP_DECLSPEC complex<float> _STLP_CALL cosh(const complex<float>&);
   961 _STLP_DECLSPEC complex<float> _STLP_CALL tanh(const complex<float>&);
   962 
   963 _STLP_DECLSPEC complex<double> _STLP_CALL sqrt(const complex<double>&);
   964 
   965 _STLP_DECLSPEC complex<double> _STLP_CALL exp(const complex<double>&);
   966 _STLP_DECLSPEC complex<double> _STLP_CALL log(const complex<double>&);
   967 _STLP_DECLSPEC complex<double> _STLP_CALL log10(const complex<double>&);
   968 
   969 _STLP_DECLSPEC complex<double> _STLP_CALL pow(const complex<double>&, int);
   970 _STLP_DECLSPEC complex<double> _STLP_CALL pow(const complex<double>&, const double&);
   971 _STLP_DECLSPEC complex<double> _STLP_CALL pow(const double&, const complex<double>&);
   972 _STLP_DECLSPEC complex<double> _STLP_CALL pow(const complex<double>&, const complex<double>&);
   973 
   974 _STLP_DECLSPEC complex<double> _STLP_CALL sin(const complex<double>&);
   975 _STLP_DECLSPEC complex<double> _STLP_CALL cos(const complex<double>&);
   976 _STLP_DECLSPEC complex<double> _STLP_CALL tan(const complex<double>&);
   977 
   978 _STLP_DECLSPEC complex<double> _STLP_CALL sinh(const complex<double>&);
   979 _STLP_DECLSPEC complex<double> _STLP_CALL cosh(const complex<double>&);
   980 _STLP_DECLSPEC complex<double> _STLP_CALL tanh(const complex<double>&);
   981 
   982 # ifndef _STLP_NO_LONG_DOUBLE
   983 _STLP_DECLSPEC complex<long double> _STLP_CALL sqrt(const complex<long double>&);
   984 _STLP_DECLSPEC complex<long double> _STLP_CALL exp(const complex<long double>&);
   985 _STLP_DECLSPEC complex<long double> _STLP_CALL log(const complex<long double>&);
   986 _STLP_DECLSPEC complex<long double> _STLP_CALL log10(const complex<long double>&);
   987 
   988 _STLP_DECLSPEC complex<long double> _STLP_CALL pow(const complex<long double>&, int);
   989 _STLP_DECLSPEC complex<long double> _STLP_CALL pow(const complex<long double>&, const long double&);
   990 _STLP_DECLSPEC complex<long double> _STLP_CALL pow(const long double&, const complex<long double>&);
   991 _STLP_DECLSPEC complex<long double> _STLP_CALL pow(const complex<long double>&,
   992                                                    const complex<long double>&);
   993 
   994 _STLP_DECLSPEC complex<long double> _STLP_CALL sin(const complex<long double>&);
   995 _STLP_DECLSPEC complex<long double> _STLP_CALL cos(const complex<long double>&);
   996 _STLP_DECLSPEC complex<long double> _STLP_CALL tan(const complex<long double>&);
   997 
   998 _STLP_DECLSPEC complex<long double> _STLP_CALL sinh(const complex<long double>&);
   999 _STLP_DECLSPEC complex<long double> _STLP_CALL cosh(const complex<long double>&);
  1000 _STLP_DECLSPEC complex<long double> _STLP_CALL tanh(const complex<long double>&);
  1001 # endif
  1002 
  1003 _STLP_END_NAMESPACE
  1004 
  1005 # ifndef _STLP_LINK_TIME_INSTANTIATION
  1006 #  include <stl/_complex.c>
  1007 # endif
  1008 
  1009 #endif /* _STLP_template_complex */
  1010 
  1011 // Local Variables:
  1012 // mode:C++
  1013 // End: