1 // The template and inlines for the -*- C++ -*- complex number classes.
3 // Copyright (C) 1997, 1998, 1999, 2000, 2001 Free Software Foundation, Inc.
5 // This file is part of the GNU ISO C++ Library. This library is free
6 // software; you can redistribute it and/or modify it under the
7 // terms of the GNU General Public License as published by the
8 // Free Software Foundation; either version 2, or (at your option)
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License along
17 // with this library; see the file COPYING. If not, write to the Free
18 // Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
21 // As a special exception, you may use this file as part of a free software
22 // library without restriction. Specifically, if other files instantiate
23 // templates or use macros or inline functions from this file, or you compile
24 // this file and link it with other files to produce an executable, this
25 // file does not by itself cause the resulting executable to be covered by
26 // the GNU General Public License. This exception does not however
27 // invalidate any other reasons why the executable file might be covered by
28 // the GNU General Public License.
31 // ISO C++ 14882: 26.2 Complex Numbers
32 // Note: this is not a conforming implementation.
33 // Initially implemented by Ulrich Drepper <drepper@cygnus.com>
34 // Improved by Gabriel Dos Reis <dosreis@cmla.ens-cachan.fr>
37 /** @file std_complex.h
38 * This is an internal header file, included by other library headers.
39 * You should not attempt to use it directly.
43 #define _CPP_COMPLEX 1
45 #pragma GCC system_header
47 #include <bits/c++config.h>
48 #include <bits/cpp_type_traits.h>
49 #include <bits/std_cmath.h>
50 #include <bits/std_sstream.h>
54 // Forward declarations
55 template<typename _Tp
> class complex;
56 template<> class complex<float>;
57 template<> class complex<double>;
58 template<> class complex<long double>;
60 template<typename _Tp
> _Tp
abs(const complex<_Tp
>&);
61 template<typename _Tp
> _Tp
arg(const complex<_Tp
>&);
62 template<typename _Tp
> _Tp
norm(const complex<_Tp
>&);
64 template<typename _Tp
> complex<_Tp
> conj(const complex<_Tp
>&);
65 template<typename _Tp
> complex<_Tp
> polar(const _Tp
&, const _Tp
& = 0);
68 template<typename _Tp
> complex<_Tp
> cos(const complex<_Tp
>&);
69 template<typename _Tp
> complex<_Tp
> cosh(const complex<_Tp
>&);
70 template<typename _Tp
> complex<_Tp
> exp(const complex<_Tp
>&);
71 template<typename _Tp
> complex<_Tp
> log(const complex<_Tp
>&);
72 template<typename _Tp
> complex<_Tp
> log10(const complex<_Tp
>&);
73 template<typename _Tp
> complex<_Tp
> pow(const complex<_Tp
>&, int);
74 template<typename _Tp
> complex<_Tp
> pow(const complex<_Tp
>&, const _Tp
&);
75 template<typename _Tp
> complex<_Tp
> pow(const complex<_Tp
>&,
77 template<typename _Tp
> complex<_Tp
> pow(const _Tp
&, const complex<_Tp
>&);
78 template<typename _Tp
> complex<_Tp
> sin(const complex<_Tp
>&);
79 template<typename _Tp
> complex<_Tp
> sinh(const complex<_Tp
>&);
80 template<typename _Tp
> complex<_Tp
> sqrt(const complex<_Tp
>&);
81 template<typename _Tp
> complex<_Tp
> tan(const complex<_Tp
>&);
82 template<typename _Tp
> complex<_Tp
> tanh(const complex<_Tp
>&);
85 // 26.2.2 Primary template class complex
86 template<typename _Tp
>
90 typedef _Tp value_type
;
92 complex(const _Tp
& = _Tp(), const _Tp
& = _Tp());
94 // Let's the compiler synthetize the copy constructor
95 // complex (const complex<_Tp>&);
96 template<typename _Up
>
97 complex(const complex<_Up
>&);
102 complex<_Tp
>& operator=(const _Tp
&);
103 complex<_Tp
>& operator+=(const _Tp
&);
104 complex<_Tp
>& operator-=(const _Tp
&);
105 complex<_Tp
>& operator*=(const _Tp
&);
106 complex<_Tp
>& operator/=(const _Tp
&);
108 // Let's the compiler synthetize the
109 // copy and assignment operator
110 // complex<_Tp>& operator= (const complex<_Tp>&);
111 template<typename _Up
>
112 complex<_Tp
>& operator=(const complex<_Up
>&);
113 template<typename _Up
>
114 complex<_Tp
>& operator+=(const complex<_Up
>&);
115 template<typename _Up
>
116 complex<_Tp
>& operator-=(const complex<_Up
>&);
117 template<typename _Up
>
118 complex<_Tp
>& operator*=(const complex<_Up
>&);
119 template<typename _Up
>
120 complex<_Tp
>& operator/=(const complex<_Up
>&);
123 _Tp _M_real
, _M_imag
;
126 template<typename _Tp
>
128 complex<_Tp
>::real() const { return _M_real
; }
130 template<typename _Tp
>
132 complex<_Tp
>::imag() const { return _M_imag
; }
134 template<typename _Tp
>
136 complex<_Tp
>::complex(const _Tp
& __r
, const _Tp
& __i
)
137 : _M_real(__r
), _M_imag(__i
) { }
139 template<typename _Tp
>
140 template<typename _Up
>
142 complex<_Tp
>::complex(const complex<_Up
>& __z
)
143 : _M_real(__z
.real()), _M_imag(__z
.imag()) { }
145 template<typename _Tp
>
147 complex<_Tp
>::operator=(const _Tp
& __t
)
155 template<typename _Tp
>
157 complex<_Tp
>::operator+=(const _Tp
& __t
)
164 template<typename _Tp
>
166 complex<_Tp
>::operator-=(const _Tp
& __t
)
173 template<typename _Tp
>
175 complex<_Tp
>::operator*=(const _Tp
& __t
)
183 template<typename _Tp
>
185 complex<_Tp
>::operator/=(const _Tp
& __t
)
192 template<typename _Tp
>
193 template<typename _Up
>
195 complex<_Tp
>::operator=(const complex<_Up
>& __z
)
197 _M_real
= __z
.real();
198 _M_imag
= __z
.imag();
203 template<typename _Tp
>
204 template<typename _Up
>
206 complex<_Tp
>::operator+=(const complex<_Up
>& __z
)
208 _M_real
+= __z
.real();
209 _M_imag
+= __z
.imag();
214 template<typename _Tp
>
215 template<typename _Up
>
217 complex<_Tp
>::operator-=(const complex<_Up
>& __z
)
219 _M_real
-= __z
.real();
220 _M_imag
-= __z
.imag();
225 // XXX: This is a grammar school implementation.
226 template<typename _Tp
>
227 template<typename _Up
>
229 complex<_Tp
>::operator*=(const complex<_Up
>& __z
)
231 const _Tp __r
= _M_real
* __z
.real() - _M_imag
* __z
.imag();
232 _M_imag
= _M_real
* __z
.imag() + _M_imag
* __z
.real();
238 // XXX: This is a grammar school implementation.
239 template<typename _Tp
>
240 template<typename _Up
>
242 complex<_Tp
>::operator/=(const complex<_Up
>& __z
)
244 const _Tp __r
= _M_real
* __z
.real() + _M_imag
* __z
.imag();
245 const _Tp __n
= norm(__z
);
246 _M_imag
= (_M_imag
* __z
.real() - _M_real
* __z
.imag()) / __n
;
252 template<typename _Tp
>
254 operator+(const complex<_Tp
>& __x
, const complex<_Tp
>& __y
)
255 { return complex<_Tp
> (__x
) += __y
; }
257 template<typename _Tp
>
259 operator+(const complex<_Tp
>& __x
, const _Tp
& __y
)
260 { return complex<_Tp
> (__x
) += __y
; }
262 template<typename _Tp
>
264 operator+(const _Tp
& __x
, const complex<_Tp
>& __y
)
265 { return complex<_Tp
> (__y
) += __x
; }
267 template<typename _Tp
>
269 operator-(const complex<_Tp
>& __x
, const complex<_Tp
>& __y
)
270 { return complex<_Tp
> (__x
) -= __y
; }
272 template<typename _Tp
>
274 operator-(const complex<_Tp
>& __x
, const _Tp
& __y
)
275 { return complex<_Tp
> (__x
) -= __y
; }
277 template<typename _Tp
>
279 operator-(const _Tp
& __x
, const complex<_Tp
>& __y
)
280 { return complex<_Tp
> (__x
) -= __y
; }
282 template<typename _Tp
>
284 operator*(const complex<_Tp
>& __x
, const complex<_Tp
>& __y
)
285 { return complex<_Tp
> (__x
) *= __y
; }
287 template<typename _Tp
>
289 operator*(const complex<_Tp
>& __x
, const _Tp
& __y
)
290 { return complex<_Tp
> (__x
) *= __y
; }
292 template<typename _Tp
>
294 operator*(const _Tp
& __x
, const complex<_Tp
>& __y
)
295 { return complex<_Tp
> (__y
) *= __x
; }
297 template<typename _Tp
>
299 operator/(const complex<_Tp
>& __x
, const complex<_Tp
>& __y
)
300 { return complex<_Tp
> (__x
) /= __y
; }
302 template<typename _Tp
>
304 operator/(const complex<_Tp
>& __x
, const _Tp
& __y
)
305 { return complex<_Tp
> (__x
) /= __y
; }
307 template<typename _Tp
>
309 operator/(const _Tp
& __x
, const complex<_Tp
>& __y
)
310 { return complex<_Tp
> (__x
) /= __y
; }
312 template<typename _Tp
>
314 operator+(const complex<_Tp
>& __x
)
317 template<typename _Tp
>
319 operator-(const complex<_Tp
>& __x
)
320 { return complex<_Tp
>(-__x
.real(), -__x
.imag()); }
322 template<typename _Tp
>
324 operator==(const complex<_Tp
>& __x
, const complex<_Tp
>& __y
)
325 { return __x
.real() == __y
.real() && __x
.imag() == __y
.imag(); }
327 template<typename _Tp
>
329 operator==(const complex<_Tp
>& __x
, const _Tp
& __y
)
330 { return __x
.real() == __y
&& __x
.imag() == _Tp(); }
332 template<typename _Tp
>
334 operator==(const _Tp
& __x
, const complex<_Tp
>& __y
)
335 { return __x
== __y
.real() && _Tp() == __y
.imag(); }
337 template<typename _Tp
>
339 operator!=(const complex<_Tp
>& __x
, const complex<_Tp
>& __y
)
340 { return __x
.real() != __y
.real() || __x
.imag() != __y
.imag(); }
342 template<typename _Tp
>
344 operator!=(const complex<_Tp
>& __x
, const _Tp
& __y
)
345 { return __x
.real() != __y
|| __x
.imag() != _Tp(); }
347 template<typename _Tp
>
349 operator!=(const _Tp
& __x
, const complex<_Tp
>& __y
)
350 { return __x
!= __y
.real() || _Tp() != __y
.imag(); }
352 template<typename _Tp
, typename _CharT
, class _Traits
>
353 basic_istream
<_CharT
, _Traits
>&
354 operator>>(basic_istream
<_CharT
, _Traits
>& __is
, complex<_Tp
>& __x
)
361 __is
>> __re_x
>> __ch
;
364 __is
>> __im_x
>> __ch
;
366 __x
= complex<_Tp
>(__re_x
, __im_x
);
368 __is
.setstate(ios_base::failbit
);
370 else if (__ch
== ')')
371 __x
= complex<_Tp
>(__re_x
, _Tp(0));
373 __is
.setstate(ios_base::failbit
);
379 __x
= complex<_Tp
>(__re_x
, _Tp(0));
384 template<typename _Tp
, typename _CharT
, class _Traits
>
385 basic_ostream
<_CharT
, _Traits
>&
386 operator<<(basic_ostream
<_CharT
, _Traits
>& __os
, const complex<_Tp
>& __x
)
388 basic_ostringstream
<_CharT
, _Traits
> __s
;
389 __s
.flags(__os
.flags());
390 __s
.imbue(__os
.getloc());
391 __s
.precision(__os
.precision());
392 __s
<< '(' << __x
.real() << "," << __x
.imag() << ')';
393 return __os
<< __s
.str();
397 template<typename _Tp
>
399 real(const complex<_Tp
>& __z
)
400 { return __z
.real(); }
402 template<typename _Tp
>
404 imag(const complex<_Tp
>& __z
)
405 { return __z
.imag(); }
407 template<typename _Tp
>
409 abs(const complex<_Tp
>& __z
)
411 _Tp __x
= __z
.real();
412 _Tp __y
= __z
.imag();
413 const _Tp __s
= max(abs(__x
), abs(__y
));
414 if (__s
== _Tp()) // well ...
418 return __s
* sqrt(__x
* __x
+ __y
* __y
);
421 template<typename _Tp
>
423 arg(const complex<_Tp
>& __z
)
424 { return atan2(__z
.imag(), __z
.real()); }
426 // 26.2.7/5: norm(__z) returns the squared magintude of __z.
427 // As defined, norm() is -not- a norm is the common mathematical
428 // sens used in numerics. The helper class _Norm_helper<> tries to
429 // distinguish between builtin floating point and the rest, so as
430 // to deliver an answer as close as possible to the real value.
434 template<typename _Tp
>
435 static inline _Tp
_S_do_it(const complex<_Tp
>& __z
)
437 const _Tp __x
= __z
.real();
438 const _Tp __y
= __z
.imag();
439 return __x
* __x
+ __y
* __y
;
444 struct _Norm_helper
<true>
446 template<typename _Tp
>
447 static inline _Tp
_S_do_it(const complex<_Tp
>& __z
)
449 _Tp __res
= abs(__z
);
450 return __res
* __res
;
454 template<typename _Tp
>
456 norm(const complex<_Tp
>& __z
)
458 return _Norm_helper
<__is_floating
<_Tp
>::_M_type
>::_S_do_it(__z
);
461 template<typename _Tp
>
463 polar(const _Tp
& __rho
, const _Tp
& __theta
)
464 { return complex<_Tp
>(__rho
* cos(__theta
), __rho
* sin(__theta
)); }
466 template<typename _Tp
>
468 conj(const complex<_Tp
>& __z
)
469 { return complex<_Tp
>(__z
.real(), -__z
.imag()); }
472 template<typename _Tp
>
474 cos(const complex<_Tp
>& __z
)
476 const _Tp __x
= __z
.real();
477 const _Tp __y
= __z
.imag();
478 return complex<_Tp
>(cos(__x
) * cosh(__y
), -sin(__x
) * sinh(__y
));
481 template<typename _Tp
>
483 cosh(const complex<_Tp
>& __z
)
485 const _Tp __x
= __z
.real();
486 const _Tp __y
= __z
.imag();
487 return complex<_Tp
>(cosh(__x
) * cos(__y
), sinh(__x
) * sin(__y
));
490 template<typename _Tp
>
492 exp(const complex<_Tp
>& __z
)
493 { return polar(exp(__z
.real()), __z
.imag()); }
495 template<typename _Tp
>
497 log(const complex<_Tp
>& __z
)
498 { return complex<_Tp
>(log(abs(__z
)), arg(__z
)); }
500 template<typename _Tp
>
502 log10(const complex<_Tp
>& __z
)
503 { return log(__z
) / log(_Tp(10.0)); }
505 template<typename _Tp
>
507 sin(const complex<_Tp
>& __z
)
509 const _Tp __x
= __z
.real();
510 const _Tp __y
= __z
.imag();
511 return complex<_Tp
>(sin(__x
) * cosh(__y
), cos(__x
) * sinh(__y
));
514 template<typename _Tp
>
516 sinh(const complex<_Tp
>& __z
)
518 const _Tp __x
= __z
.real();
519 const _Tp __y
= __z
.imag();
520 return complex<_Tp
>(sinh(__x
) * cos(__y
), cosh(__x
) * sin(__y
));
523 template<typename _Tp
>
525 sqrt(const complex<_Tp
>& __z
)
527 _Tp __x
= __z
.real();
528 _Tp __y
= __z
.imag();
532 _Tp __t
= sqrt(abs(__y
) / 2);
533 return complex<_Tp
>(__t
, __y
< _Tp() ? -__t
: __t
);
537 _Tp __t
= sqrt(2 * (abs(__z
) + abs(__x
)));
540 ? complex<_Tp
>(__u
, __y
/ __t
)
541 : complex<_Tp
>(abs(__y
) / __t
, __y
< _Tp() ? -__u
: __u
);
545 template<typename _Tp
>
547 tan(const complex<_Tp
>& __z
)
549 return sin(__z
) / cos(__z
);
552 template<typename _Tp
>
554 tanh(const complex<_Tp
>& __z
)
556 return sinh(__z
) / cosh(__z
);
559 template<typename _Tp
>
561 pow(const complex<_Tp
>& __z
, int __n
)
563 return __pow_helper(__z
, __n
);
566 template<typename _Tp
>
568 pow(const complex<_Tp
>& __x
, const _Tp
& __y
)
570 return exp(__y
* log(__x
));
573 template<typename _Tp
>
575 pow(const complex<_Tp
>& __x
, const complex<_Tp
>& __y
)
577 return exp(__y
* log(__x
));
580 template<typename _Tp
>
582 pow(const _Tp
& __x
, const complex<_Tp
>& __y
)
584 return exp(__y
* log(__x
));
587 // 26.2.3 complex specializations
588 // complex<float> specialization
589 template<> class complex<float>
592 typedef float value_type
;
594 complex(float = 0.0f
, float = 0.0f
);
595 #ifdef _GLIBCPP_BUGGY_COMPLEX
596 complex(const complex& __z
) : _M_value(__z
._M_value
) { }
598 explicit complex(const complex<double>&);
599 explicit complex(const complex<long double>&);
604 complex<float>& operator=(float);
605 complex<float>& operator+=(float);
606 complex<float>& operator-=(float);
607 complex<float>& operator*=(float);
608 complex<float>& operator/=(float);
610 // Let's the compiler synthetize the copy and assignment
611 // operator. It always does a pretty good job.
612 // complex& operator= (const complex&);
613 template<typename _Tp
>
614 complex<float>&operator=(const complex<_Tp
>&);
615 template<typename _Tp
>
616 complex<float>& operator+=(const complex<_Tp
>&);
618 complex<float>& operator-=(const complex<_Tp
>&);
620 complex<float>& operator*=(const complex<_Tp
>&);
622 complex<float>&operator/=(const complex<_Tp
>&);
625 typedef __complex__
float _ComplexT
;
628 complex(_ComplexT __z
) : _M_value(__z
) { }
630 friend class complex<double>;
631 friend class complex<long double>;
635 complex<float>::real() const
636 { return __real__ _M_value
; }
639 complex<float>::imag() const
640 { return __imag__ _M_value
; }
643 complex<float>::complex(float r
, float i
)
645 __real__ _M_value
= r
;
646 __imag__ _M_value
= i
;
649 inline complex<float>&
650 complex<float>::operator=(float __f
)
652 __real__ _M_value
= __f
;
653 __imag__ _M_value
= 0.0f
;
657 inline complex<float>&
658 complex<float>::operator+=(float __f
)
660 __real__ _M_value
+= __f
;
664 inline complex<float>&
665 complex<float>::operator-=(float __f
)
667 __real__ _M_value
-= __f
;
671 inline complex<float>&
672 complex<float>::operator*=(float __f
)
678 inline complex<float>&
679 complex<float>::operator/=(float __f
)
685 template<typename _Tp
>
686 inline complex<float>&
687 complex<float>::operator=(const complex<_Tp
>& __z
)
689 __real__ _M_value
= __z
.real();
690 __imag__ _M_value
= __z
.imag();
694 template<typename _Tp
>
695 inline complex<float>&
696 complex<float>::operator+=(const complex<_Tp
>& __z
)
698 __real__ _M_value
+= __z
.real();
699 __imag__ _M_value
+= __z
.imag();
703 template<typename _Tp
>
704 inline complex<float>&
705 complex<float>::operator-=(const complex<_Tp
>& __z
)
707 __real__ _M_value
-= __z
.real();
708 __imag__ _M_value
-= __z
.imag();
712 template<typename _Tp
>
713 inline complex<float>&
714 complex<float>::operator*=(const complex<_Tp
>& __z
)
717 __real__ __t
= __z
.real();
718 __imag__ __t
= __z
.imag();
723 template<typename _Tp
>
724 inline complex<float>&
725 complex<float>::operator/=(const complex<_Tp
>& __z
)
728 __real__ __t
= __z
.real();
729 __imag__ __t
= __z
.imag();
734 // 26.2.3 complex specializations
735 // complex<double> specialization
736 template<> class complex<double>
739 typedef double value_type
;
741 complex(double =0.0, double =0.0);
742 #ifdef _GLIBCPP_BUGGY_COMPLEX
743 complex(const complex& __z
) : _M_value(__z
._M_value
) { }
745 complex(const complex<float>&);
746 explicit complex(const complex<long double>&);
751 complex<double>& operator=(double);
752 complex<double>& operator+=(double);
753 complex<double>& operator-=(double);
754 complex<double>& operator*=(double);
755 complex<double>& operator/=(double);
757 // The compiler will synthetize this, efficiently.
758 // complex& operator= (const complex&);
759 template<typename _Tp
>
760 complex<double>& operator=(const complex<_Tp
>&);
761 template<typename _Tp
>
762 complex<double>& operator+=(const complex<_Tp
>&);
763 template<typename _Tp
>
764 complex<double>& operator-=(const complex<_Tp
>&);
765 template<typename _Tp
>
766 complex<double>& operator*=(const complex<_Tp
>&);
767 template<typename _Tp
>
768 complex<double>& operator/=(const complex<_Tp
>&);
771 typedef __complex__
double _ComplexT
;
774 complex(_ComplexT __z
) : _M_value(__z
) { }
776 friend class complex<float>;
777 friend class complex<long double>;
781 complex<double>::real() const
782 { return __real__ _M_value
; }
785 complex<double>::imag() const
786 { return __imag__ _M_value
; }
789 complex<double>::complex(double __r
, double __i
)
791 __real__ _M_value
= __r
;
792 __imag__ _M_value
= __i
;
795 inline complex<double>&
796 complex<double>::operator=(double __d
)
798 __real__ _M_value
= __d
;
799 __imag__ _M_value
= 0.0;
803 inline complex<double>&
804 complex<double>::operator+=(double __d
)
806 __real__ _M_value
+= __d
;
810 inline complex<double>&
811 complex<double>::operator-=(double __d
)
813 __real__ _M_value
-= __d
;
817 inline complex<double>&
818 complex<double>::operator*=(double __d
)
824 inline complex<double>&
825 complex<double>::operator/=(double __d
)
831 template<typename _Tp
>
832 inline complex<double>&
833 complex<double>::operator=(const complex<_Tp
>& __z
)
835 __real__ _M_value
= __z
.real();
836 __imag__ _M_value
= __z
.imag();
840 template<typename _Tp
>
841 inline complex<double>&
842 complex<double>::operator+=(const complex<_Tp
>& __z
)
844 __real__ _M_value
+= __z
.real();
845 __imag__ _M_value
+= __z
.imag();
849 template<typename _Tp
>
850 inline complex<double>&
851 complex<double>::operator-=(const complex<_Tp
>& __z
)
853 __real__ _M_value
-= __z
.real();
854 __imag__ _M_value
-= __z
.imag();
858 template<typename _Tp
>
859 inline complex<double>&
860 complex<double>::operator*=(const complex<_Tp
>& __z
)
863 __real__ __t
= __z
.real();
864 __imag__ __t
= __z
.imag();
869 template<typename _Tp
>
870 inline complex<double>&
871 complex<double>::operator/=(const complex<_Tp
>& __z
)
874 __real__ __t
= __z
.real();
875 __imag__ __t
= __z
.imag();
880 // 26.2.3 complex specializations
881 // complex<long double> specialization
882 template<> class complex<long double>
885 typedef long double value_type
;
887 complex(long double = 0.0L, long double = 0.0L);
888 #ifdef _GLIBCPP_BUGGY_COMPLEX
889 complex(const complex& __z
) : _M_value(__z
._M_value
) { }
891 complex(const complex<float>&);
892 complex(const complex<double>&);
894 long double real() const;
895 long double imag() const;
897 complex<long double>& operator= (long double);
898 complex<long double>& operator+= (long double);
899 complex<long double>& operator-= (long double);
900 complex<long double>& operator*= (long double);
901 complex<long double>& operator/= (long double);
903 // The compiler knows how to do this efficiently
904 // complex& operator= (const complex&);
905 template<typename _Tp
>
906 complex<long double>& operator=(const complex<_Tp
>&);
907 template<typename _Tp
>
908 complex<long double>& operator+=(const complex<_Tp
>&);
909 template<typename _Tp
>
910 complex<long double>& operator-=(const complex<_Tp
>&);
911 template<typename _Tp
>
912 complex<long double>& operator*=(const complex<_Tp
>&);
913 template<typename _Tp
>
914 complex<long double>& operator/=(const complex<_Tp
>&);
917 typedef __complex__
long double _ComplexT
;
920 complex(_ComplexT __z
) : _M_value(__z
) { }
922 friend class complex<float>;
923 friend class complex<double>;
927 complex<long double>::complex(long double __r
, long double __i
)
929 __real__ _M_value
= __r
;
930 __imag__ _M_value
= __i
;
934 complex<long double>::real() const
935 { return __real__ _M_value
; }
938 complex<long double>::imag() const
939 { return __imag__ _M_value
; }
941 inline complex<long double>&
942 complex<long double>::operator=(long double __r
)
944 __real__ _M_value
= __r
;
945 __imag__ _M_value
= 0.0L;
949 inline complex<long double>&
950 complex<long double>::operator+=(long double __r
)
952 __real__ _M_value
+= __r
;
956 inline complex<long double>&
957 complex<long double>::operator-=(long double __r
)
959 __real__ _M_value
-= __r
;
963 inline complex<long double>&
964 complex<long double>::operator*=(long double __r
)
970 inline complex<long double>&
971 complex<long double>::operator/=(long double __r
)
977 template<typename _Tp
>
978 inline complex<long double>&
979 complex<long double>::operator=(const complex<_Tp
>& __z
)
981 __real__ _M_value
= __z
.real();
982 __imag__ _M_value
= __z
.imag();
986 template<typename _Tp
>
987 inline complex<long double>&
988 complex<long double>::operator+=(const complex<_Tp
>& __z
)
990 __real__ _M_value
+= __z
.real();
991 __imag__ _M_value
+= __z
.imag();
995 template<typename _Tp
>
996 inline complex<long double>&
997 complex<long double>::operator-=(const complex<_Tp
>& __z
)
999 __real__ _M_value
-= __z
.real();
1000 __imag__ _M_value
-= __z
.imag();
1004 template<typename _Tp
>
1005 inline complex<long double>&
1006 complex<long double>::operator*=(const complex<_Tp
>& __z
)
1009 __real__ __t
= __z
.real();
1010 __imag__ __t
= __z
.imag();
1015 template<typename _Tp
>
1016 inline complex<long double>&
1017 complex<long double>::operator/=(const complex<_Tp
>& __z
)
1020 __real__ __t
= __z
.real();
1021 __imag__ __t
= __z
.imag();
1026 // These bits have to be at the end of this file, so that the
1027 // specializations have all been defined.
1028 // ??? No, they have to be there because of compiler limitation at
1029 // inlining. It suffices that class specializations be defined.
1031 complex<float>::complex(const complex<double>& __z
)
1032 : _M_value(_ComplexT(__z
._M_value
)) { }
1035 complex<float>::complex(const complex<long double>& __z
)
1036 : _M_value(_ComplexT(__z
._M_value
)) { }
1039 complex<double>::complex(const complex<float>& __z
)
1040 : _M_value(_ComplexT(__z
._M_value
)) { }
1043 complex<double>::complex(const complex<long double>& __z
)
1045 __real__ _M_value
= __z
.real();
1046 __imag__ _M_value
= __z
.imag();
1050 complex<long double>::complex(const complex<float>& __z
)
1051 : _M_value(_ComplexT(__z
._M_value
)) { }
1054 complex<long double>::complex(const complex<double>& __z
)
1055 : _M_value(_ComplexT(__z
._M_value
)) { }
1058 #endif /* _CPP_COMPLEX */