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