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