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>
38 #define _CPP_COMPLEX 1
40 #pragma GCC system_header
42 #include <bits/c++config.h>
43 #include <bits/std_cmath.h>
44 #include <bits/std_sstream.h>
48 // Forward declarations
49 template<typename _Tp
> class complex;
50 template<> class complex<float>;
51 template<> class complex<double>;
52 template<> class complex<long double>;
54 template<typename _Tp
> _Tp
abs(const complex<_Tp
>&);
55 template<typename _Tp
> _Tp
arg(const complex<_Tp
>&);
56 template<typename _Tp
> _Tp
norm(const complex<_Tp
>&);
58 template<typename _Tp
> complex<_Tp
> conj(const complex<_Tp
>&);
59 template<typename _Tp
> complex<_Tp
> polar(const _Tp
&, const _Tp
&);
62 template<typename _Tp
> complex<_Tp
> cos(const complex<_Tp
>&);
63 template<typename _Tp
> complex<_Tp
> cosh(const complex<_Tp
>&);
64 template<typename _Tp
> complex<_Tp
> exp(const complex<_Tp
>&);
65 template<typename _Tp
> complex<_Tp
> log(const complex<_Tp
>&);
66 template<typename _Tp
> complex<_Tp
> log10(const complex<_Tp
>&);
67 template<typename _Tp
> complex<_Tp
> pow(const complex<_Tp
>&, int);
68 template<typename _Tp
> complex<_Tp
> pow(const complex<_Tp
>&, const _Tp
&);
69 template<typename _Tp
> complex<_Tp
> pow(const complex<_Tp
>&,
71 template<typename _Tp
> complex<_Tp
> pow(const _Tp
&, const complex<_Tp
>&);
72 template<typename _Tp
> complex<_Tp
> sin(const complex<_Tp
>&);
73 template<typename _Tp
> complex<_Tp
> sinh(const complex<_Tp
>&);
74 template<typename _Tp
> complex<_Tp
> sqrt(const complex<_Tp
>&);
75 template<typename _Tp
> complex<_Tp
> tan(const complex<_Tp
>&);
76 template<typename _Tp
> complex<_Tp
> tanh(const complex<_Tp
>&);
79 // 26.2.2 Primary template class complex
80 template<typename _Tp
>
84 typedef _Tp value_type
;
86 complex(const _Tp
& = _Tp(), const _Tp
& = _Tp());
88 // Let's the compiler synthetize the copy constructor
89 // complex (const complex<_Tp>&);
90 template<typename _Up
>
91 complex(const complex<_Up
>&);
96 complex<_Tp
>& operator=(const _Tp
&);
97 complex<_Tp
>& operator+=(const _Tp
&);
98 complex<_Tp
>& operator-=(const _Tp
&);
99 complex<_Tp
>& operator*=(const _Tp
&);
100 complex<_Tp
>& operator/=(const _Tp
&);
102 // Let's the compiler synthetize the
103 // copy and assignment operator
104 // complex<_Tp>& operator= (const complex<_Tp>&);
105 template<typename _Up
>
106 complex<_Tp
>& operator=(const complex<_Up
>&);
107 template<typename _Up
>
108 complex<_Tp
>& operator+=(const complex<_Up
>&);
109 template<typename _Up
>
110 complex<_Tp
>& operator-=(const complex<_Up
>&);
111 template<typename _Up
>
112 complex<_Tp
>& operator*=(const complex<_Up
>&);
113 template<typename _Up
>
114 complex<_Tp
>& operator/=(const complex<_Up
>&);
117 _Tp _M_real
, _M_imag
;
120 template<typename _Tp
>
122 complex<_Tp
>::real() const { return _M_real
; }
124 template<typename _Tp
>
126 complex<_Tp
>::imag() const { return _M_imag
; }
128 template<typename _Tp
>
130 complex<_Tp
>::complex(const _Tp
& __r
, const _Tp
& __i
)
131 : _M_real(__r
), _M_imag(__i
) { }
133 template<typename _Tp
>
134 template<typename _Up
>
136 complex<_Tp
>::complex(const complex<_Up
>& __z
)
137 : _M_real(__z
.real()), _M_imag(__z
.imag()) { }
139 template<typename _Tp
>
141 complex<_Tp
>::operator=(const _Tp
& __t
)
149 template<typename _Tp
>
151 complex<_Tp
>::operator+=(const _Tp
& __t
)
158 template<typename _Tp
>
160 complex<_Tp
>::operator-=(const _Tp
& __t
)
167 template<typename _Tp
>
169 complex<_Tp
>::operator*=(const _Tp
& __t
)
177 template<typename _Tp
>
179 complex<_Tp
>::operator/=(const _Tp
& __t
)
186 template<typename _Tp
>
187 template<typename _Up
>
189 complex<_Tp
>::operator=(const complex<_Up
>& __z
)
191 _M_real
= __z
.real();
192 _M_imag
= __z
.imag();
197 template<typename _Tp
>
198 template<typename _Up
>
200 complex<_Tp
>::operator+=(const complex<_Up
>& __z
)
202 _M_real
+= __z
.real();
203 _M_imag
+= __z
.imag();
208 template<typename _Tp
>
209 template<typename _Up
>
211 complex<_Tp
>::operator-=(const complex<_Up
>& __z
)
213 _M_real
-= __z
.real();
214 _M_imag
-= __z
.imag();
219 // XXX: This is a grammar school implementation.
220 template<typename _Tp
>
221 template<typename _Up
>
223 complex<_Tp
>::operator*=(const complex<_Up
>& __z
)
225 const _Tp __r
= _M_real
* __z
.real() - _M_imag
* __z
.imag();
226 _M_imag
= _M_real
* __z
.imag() + _M_imag
* __z
.real();
232 // XXX: This is a grammar school implementation.
233 template<typename _Tp
>
234 template<typename _Up
>
236 complex<_Tp
>::operator/=(const complex<_Up
>& __z
)
238 const _Tp __r
= _M_real
* __z
.real() + _M_imag
* __z
.imag();
239 const _Tp __n
= norm(__z
);
240 _M_imag
= (_M_real
* __z
.imag() - _M_imag
* __z
.real()) / __n
;
246 template<typename _Tp
>
248 operator+(const complex<_Tp
>& __x
, const complex<_Tp
>& __y
)
249 { return complex<_Tp
> (__x
) += __y
; }
251 template<typename _Tp
>
253 operator+(const complex<_Tp
>& __x
, const _Tp
& __y
)
254 { return complex<_Tp
> (__x
) += __y
; }
256 template<typename _Tp
>
258 operator+(const _Tp
& __x
, const complex<_Tp
>& __y
)
259 { return complex<_Tp
> (__y
) += __x
; }
261 template<typename _Tp
>
263 operator-(const complex<_Tp
>& __x
, const complex<_Tp
>& __y
)
264 { return complex<_Tp
> (__x
) -= __y
; }
266 template<typename _Tp
>
268 operator-(const complex<_Tp
>& __x
, const _Tp
& __y
)
269 { return complex<_Tp
> (__x
) -= __y
; }
271 template<typename _Tp
>
273 operator-(const _Tp
& __x
, const complex<_Tp
>& __y
)
274 { return complex<_Tp
> (__x
) -= __y
; }
276 template<typename _Tp
>
278 operator*(const complex<_Tp
>& __x
, const complex<_Tp
>& __y
)
279 { return complex<_Tp
> (__x
) *= __y
; }
281 template<typename _Tp
>
283 operator*(const complex<_Tp
>& __x
, const _Tp
& __y
)
284 { return complex<_Tp
> (__x
) *= __y
; }
286 template<typename _Tp
>
288 operator*(const _Tp
& __x
, const complex<_Tp
>& __y
)
289 { return complex<_Tp
> (__y
) *= __x
; }
291 template<typename _Tp
>
293 operator/(const complex<_Tp
>& __x
, const complex<_Tp
>& __y
)
294 { return complex<_Tp
> (__x
) /= __y
; }
296 template<typename _Tp
>
298 operator/(const complex<_Tp
>& __x
, const _Tp
& __y
)
299 { return complex<_Tp
> (__x
) /= __y
; }
301 template<typename _Tp
>
303 operator/(const _Tp
& __x
, const complex<_Tp
>& __y
)
304 { return complex<_Tp
> (__x
) /= __y
; }
306 template<typename _Tp
>
308 operator+(const complex<_Tp
>& __x
)
311 template<typename _Tp
>
313 operator-(const complex<_Tp
>& __x
)
314 { return complex<_Tp
>(-__x
.real(), -__x
.imag()); }
316 template<typename _Tp
>
318 operator==(const complex<_Tp
>& __x
, const complex<_Tp
>& __y
)
319 { return __x
.real() == __y
.real() && __x
.imag() == __y
.imag(); }
321 template<typename _Tp
>
323 operator==(const complex<_Tp
>& __x
, const _Tp
& __y
)
324 { return __x
.real() == __y
&& __x
.imag() == _Tp(); }
326 template<typename _Tp
>
328 operator==(const _Tp
& __x
, const complex<_Tp
>& __y
)
329 { return __x
== __y
.real() && _Tp() == __y
.imag(); }
331 template<typename _Tp
>
333 operator!=(const complex<_Tp
>& __x
, const complex<_Tp
>& __y
)
334 { return __x
.real() != __y
.real() || __x
.imag() != __y
.imag(); }
336 template<typename _Tp
>
338 operator!=(const complex<_Tp
>& __x
, const _Tp
& __y
)
339 { return __x
.real() != __y
|| __x
.imag() != _Tp(); }
341 template<typename _Tp
>
343 operator!=(const _Tp
& __x
, const complex<_Tp
>& __y
)
344 { return __x
!= __y
.real() || _Tp() != __y
.imag(); }
346 template<typename _Tp
, typename _CharT
, class _Traits
>
347 basic_istream
<_CharT
, _Traits
>&
348 operator>>(basic_istream
<_CharT
, _Traits
>& __is
, complex<_Tp
>& __x
)
355 __is
>> __re_x
>> __ch
;
358 __is
>> __im_x
>> __ch
;
360 __x
= complex<_Tp
>(__re_x
, __im_x
);
362 __is
.setstate(ios_base::failbit
);
364 else if (__ch
== ')')
365 __x
= complex<_Tp
>(__re_x
, _Tp(0));
367 __is
.setstate(ios_base::failbit
);
373 __x
= complex<_Tp
>(__re_x
, _Tp(0));
378 template<typename _Tp
, typename _CharT
, class _Traits
>
379 basic_ostream
<_CharT
, _Traits
>&
380 operator<<(basic_ostream
<_CharT
, _Traits
>& __os
, const complex<_Tp
>& __x
)
382 basic_ostringstream
<_CharT
, _Traits
> __s
;
383 __s
.flags(__os
.flags());
384 __s
.imbue(__os
.getloc());
385 __s
.precision(__os
.precision());
386 __s
<< '(' << __x
.real() << "," << __x
.imag() << ')';
387 return __os
<< __s
.str();
391 template<typename _Tp
>
393 real(const complex<_Tp
>& __z
)
394 { return __z
.real(); }
396 template<typename _Tp
>
398 imag(const complex<_Tp
>& __z
)
399 { return __z
.imag(); }
401 template<typename _Tp
>
403 abs(const complex<_Tp
>& __z
)
405 _Tp __x
= __z
.real();
406 _Tp __y
= __z
.imag();
407 const _Tp __s
= abs(__x
) + abs(__y
);
408 if (__s
== _Tp()) // well ...
412 return __s
* sqrt(__x
* __x
+ __y
* __y
);
415 template<typename _Tp
>
417 arg(const complex<_Tp
>& __z
)
418 { return atan2(__z
.imag(), __z
.real()); }
420 template<typename _Tp
>
422 norm(const complex<_Tp
>& __z
)
424 _Tp __res
= abs(__z
);
425 return __res
* __res
;
428 template<typename _Tp
>
430 polar(const _Tp
& __rho
, const _Tp
& __theta
)
431 { return complex<_Tp
>(__rho
* cos(__theta
), __rho
* sin(__theta
)); }
433 template<typename _Tp
>
435 conj(const complex<_Tp
>& __z
)
436 { return complex<_Tp
>(__z
.real(), -__z
.imag()); }
439 template<typename _Tp
>
441 cos(const complex<_Tp
>& __z
)
443 const _Tp __x
= __z
.real();
444 const _Tp __y
= __z
.imag();
445 return complex<_Tp
>(cos(__x
) * cosh(__y
), -sin(__x
) * sinh(__y
));
448 template<typename _Tp
>
450 cosh(const complex<_Tp
>& __z
)
452 const _Tp __x
= __z
.real();
453 const _Tp __y
= __z
.imag();
454 return complex<_Tp
>(cosh(__x
) * cos(__y
), sinh(__x
) * sin(__y
));
457 template<typename _Tp
>
459 exp(const complex<_Tp
>& __z
)
460 { return polar(exp(__z
.real()), __z
.imag()); }
462 template<typename _Tp
>
464 log(const complex<_Tp
>& __z
)
465 { return complex<_Tp
>(log(abs(__z
)), arg(__z
)); }
467 template<typename _Tp
>
469 log10(const complex<_Tp
>& __z
)
470 { return log(__z
) / log(_Tp(10.0)); }
472 template<typename _Tp
>
474 sin(const complex<_Tp
>& __z
)
476 const _Tp __x
= __z
.real();
477 const _Tp __y
= __z
.imag();
478 return complex<_Tp
>(sin(__x
) * cosh(__y
), cos(__x
) * sinh(__y
));
481 template<typename _Tp
>
483 sinh(const complex<_Tp
>& __z
)
485 const _Tp __x
= __z
.real();
486 const _Tp __y
= __z
.imag();
487 return complex<_Tp
>(sinh(__x
) * cos(__y
), cosh(__x
) * sin(__y
));
490 template<typename _Tp
>
492 sqrt(const complex<_Tp
>& __z
)
494 _Tp __x
= __z
.real();
495 _Tp __y
= __z
.imag();
499 _Tp __t
= sqrt(abs(__y
) / 2);
500 return complex<_Tp
>(__t
, __y
< _Tp() ? -__t
: __t
);
504 _Tp __t
= sqrt(2 * (abs(__z
) + abs(__x
)));
507 ? complex<_Tp
>(__u
, __y
/ __t
)
508 : complex<_Tp
>(abs(__y
) / __t
, __y
< _Tp() ? -__u
: __u
);
512 template<typename _Tp
>
514 tan(const complex<_Tp
>& __z
)
516 return sin(__z
) / cos(__z
);
519 template<typename _Tp
>
521 tanh(const complex<_Tp
>& __z
)
523 return sinh(__z
) / cosh(__z
);
526 template<typename _Tp
>
528 pow(const complex<_Tp
>& __z
, int __n
)
530 return __pow_helper(__z
, __n
);
533 template<typename _Tp
>
535 pow(const complex<_Tp
>& __x
, const _Tp
& __y
)
537 return exp(__y
* log(__x
));
540 template<typename _Tp
>
542 pow(const complex<_Tp
>& __x
, const complex<_Tp
>& __y
)
544 return exp(__y
* log(__x
));
547 template<typename _Tp
>
549 pow(const _Tp
& __x
, const complex<_Tp
>& __y
)
551 return exp(__y
* log(__x
));
554 // 26.2.3 complex specializations
555 // complex<float> specialization
556 template<> class complex<float>
559 typedef float value_type
;
561 complex(float = 0.0f
, float = 0.0f
);
562 #ifdef _GLIBCPP_BUGGY_COMPLEX
563 complex(const complex& __z
) : _M_value(__z
._M_value
) { }
565 explicit complex(const complex<double>&);
566 explicit complex(const complex<long double>&);
571 complex<float>& operator=(float);
572 complex<float>& operator+=(float);
573 complex<float>& operator-=(float);
574 complex<float>& operator*=(float);
575 complex<float>& operator/=(float);
577 // Let's the compiler synthetize the copy and assignment
578 // operator. It always does a pretty good job.
579 // complex& operator= (const complex&);
580 template<typename _Tp
>
581 complex<float>&operator=(const complex<_Tp
>&);
582 template<typename _Tp
>
583 complex<float>& operator+=(const complex<_Tp
>&);
585 complex<float>& operator-=(const complex<_Tp
>&);
587 complex<float>& operator*=(const complex<_Tp
>&);
589 complex<float>&operator/=(const complex<_Tp
>&);
592 typedef __complex__
float _ComplexT
;
595 complex(_ComplexT __z
) : _M_value(__z
) { }
597 friend class complex<double>;
598 friend class complex<long double>;
602 complex<float>::real() const
603 { return __real__ _M_value
; }
606 complex<float>::imag() const
607 { return __imag__ _M_value
; }
610 complex<float>::complex(float r
, float i
)
612 __real__ _M_value
= r
;
613 __imag__ _M_value
= i
;
616 inline complex<float>&
617 complex<float>::operator=(float __f
)
619 __real__ _M_value
= __f
;
620 __imag__ _M_value
= 0.0f
;
624 inline complex<float>&
625 complex<float>::operator+=(float __f
)
627 __real__ _M_value
+= __f
;
631 inline complex<float>&
632 complex<float>::operator-=(float __f
)
634 __real__ _M_value
-= __f
;
638 inline complex<float>&
639 complex<float>::operator*=(float __f
)
645 inline complex<float>&
646 complex<float>::operator/=(float __f
)
652 template<typename _Tp
>
653 inline complex<float>&
654 complex<float>::operator=(const complex<_Tp
>& __z
)
656 __real__ _M_value
= __z
.real();
657 __imag__ _M_value
= __z
.imag();
661 template<typename _Tp
>
662 inline complex<float>&
663 complex<float>::operator+=(const complex<_Tp
>& __z
)
665 __real__ _M_value
+= __z
.real();
666 __imag__ _M_value
+= __z
.imag();
670 template<typename _Tp
>
671 inline complex<float>&
672 complex<float>::operator-=(const complex<_Tp
>& __z
)
674 __real__ _M_value
-= __z
.real();
675 __imag__ _M_value
-= __z
.imag();
679 template<typename _Tp
>
680 inline complex<float>&
681 complex<float>::operator*=(const complex<_Tp
>& __z
)
684 __real__ __t
= __z
.real();
685 __imag__ __t
= __z
.imag();
690 template<typename _Tp
>
691 inline complex<float>&
692 complex<float>::operator/=(const complex<_Tp
>& __z
)
695 __real__ __t
= __z
.real();
696 __imag__ __t
= __z
.imag();
701 // 26.2.3 complex specializations
702 // complex<double> specialization
703 template<> class complex<double>
706 typedef double value_type
;
708 complex(double =0.0, double =0.0);
709 #ifdef _GLIBCPP_BUGGY_COMPLEX
710 complex(const complex& __z
) : _M_value(__z
._M_value
) { }
712 complex(const complex<float>&);
713 explicit complex(const complex<long double>&);
718 complex<double>& operator=(double);
719 complex<double>& operator+=(double);
720 complex<double>& operator-=(double);
721 complex<double>& operator*=(double);
722 complex<double>& operator/=(double);
724 // The compiler will synthetize this, efficiently.
725 // complex& operator= (const complex&);
726 template<typename _Tp
>
727 complex<double>& operator=(const complex<_Tp
>&);
728 template<typename _Tp
>
729 complex<double>& operator+=(const complex<_Tp
>&);
730 template<typename _Tp
>
731 complex<double>& operator-=(const complex<_Tp
>&);
732 template<typename _Tp
>
733 complex<double>& operator*=(const complex<_Tp
>&);
734 template<typename _Tp
>
735 complex<double>& operator/=(const complex<_Tp
>&);
738 typedef __complex__
double _ComplexT
;
741 complex(_ComplexT __z
) : _M_value(__z
) { }
743 friend class complex<float>;
744 friend class complex<long double>;
748 complex<double>::real() const
749 { return __real__ _M_value
; }
752 complex<double>::imag() const
753 { return __imag__ _M_value
; }
756 complex<double>::complex(double __r
, double __i
)
758 __real__ _M_value
= __r
;
759 __imag__ _M_value
= __i
;
762 inline complex<double>&
763 complex<double>::operator=(double __d
)
765 __real__ _M_value
= __d
;
766 __imag__ _M_value
= 0.0;
770 inline complex<double>&
771 complex<double>::operator+=(double __d
)
773 __real__ _M_value
+= __d
;
777 inline complex<double>&
778 complex<double>::operator-=(double __d
)
780 __real__ _M_value
-= __d
;
784 inline complex<double>&
785 complex<double>::operator*=(double __d
)
791 inline complex<double>&
792 complex<double>::operator/=(double __d
)
798 template<typename _Tp
>
799 inline complex<double>&
800 complex<double>::operator=(const complex<_Tp
>& __z
)
802 __real__ _M_value
= __z
.real();
803 __imag__ _M_value
= __z
.imag();
807 template<typename _Tp
>
808 inline complex<double>&
809 complex<double>::operator+=(const complex<_Tp
>& __z
)
811 __real__ _M_value
+= __z
.real();
812 __imag__ _M_value
+= __z
.imag();
816 template<typename _Tp
>
817 inline complex<double>&
818 complex<double>::operator-=(const complex<_Tp
>& __z
)
820 __real__ _M_value
-= __z
.real();
821 __imag__ _M_value
-= __z
.imag();
825 template<typename _Tp
>
826 inline complex<double>&
827 complex<double>::operator*=(const complex<_Tp
>& __z
)
830 __real__ __t
= __z
.real();
831 __imag__ __t
= __z
.imag();
836 template<typename _Tp
>
837 inline complex<double>&
838 complex<double>::operator/=(const complex<_Tp
>& __z
)
841 __real__ __t
= __z
.real();
842 __imag__ __t
= __z
.imag();
847 // 26.2.3 complex specializations
848 // complex<long double> specialization
849 template<> class complex<long double>
852 typedef long double value_type
;
854 complex(long double = 0.0L, long double = 0.0L);
855 #ifdef _GLIBCPP_BUGGY_COMPLEX
856 complex(const complex& __z
) : _M_value(__z
._M_value
) { }
858 complex(const complex<float>&);
859 complex(const complex<double>&);
861 long double real() const;
862 long double imag() const;
864 complex<long double>& operator= (long double);
865 complex<long double>& operator+= (long double);
866 complex<long double>& operator-= (long double);
867 complex<long double>& operator*= (long double);
868 complex<long double>& operator/= (long double);
870 // The compiler knows how to do this efficiently
871 // complex& operator= (const complex&);
872 template<typename _Tp
>
873 complex<long double>& operator=(const complex<_Tp
>&);
874 template<typename _Tp
>
875 complex<long double>& operator+=(const complex<_Tp
>&);
876 template<typename _Tp
>
877 complex<long double>& operator-=(const complex<_Tp
>&);
878 template<typename _Tp
>
879 complex<long double>& operator*=(const complex<_Tp
>&);
880 template<typename _Tp
>
881 complex<long double>& operator/=(const complex<_Tp
>&);
884 typedef __complex__
long double _ComplexT
;
887 complex(_ComplexT __z
) : _M_value(__z
) { }
889 friend class complex<float>;
890 friend class complex<double>;
894 complex<long double>::complex(long double __r
, long double __i
)
896 __real__ _M_value
= __r
;
897 __imag__ _M_value
= __i
;
901 complex<long double>::real() const
902 { return __real__ _M_value
; }
905 complex<long double>::imag() const
906 { return __imag__ _M_value
; }
908 inline complex<long double>&
909 complex<long double>::operator=(long double __r
)
911 __real__ _M_value
= __r
;
912 __imag__ _M_value
= 0.0L;
916 inline complex<long double>&
917 complex<long double>::operator+=(long double __r
)
919 __real__ _M_value
+= __r
;
923 inline complex<long double>&
924 complex<long double>::operator-=(long double __r
)
926 __real__ _M_value
-= __r
;
930 inline complex<long double>&
931 complex<long double>::operator*=(long double __r
)
937 inline complex<long double>&
938 complex<long double>::operator/=(long double __r
)
944 template<typename _Tp
>
945 inline complex<long double>&
946 complex<long double>::operator=(const complex<_Tp
>& __z
)
948 __real__ _M_value
= __z
.real();
949 __imag__ _M_value
= __z
.imag();
953 template<typename _Tp
>
954 inline complex<long double>&
955 complex<long double>::operator+=(const complex<_Tp
>& __z
)
957 __real__ _M_value
+= __z
.real();
958 __imag__ _M_value
+= __z
.imag();
962 template<typename _Tp
>
963 inline complex<long double>&
964 complex<long double>::operator-=(const complex<_Tp
>& __z
)
966 __real__ _M_value
-= __z
.real();
967 __imag__ _M_value
-= __z
.imag();
971 template<typename _Tp
>
972 inline complex<long double>&
973 complex<long double>::operator*=(const complex<_Tp
>& __z
)
976 __real__ __t
= __z
.real();
977 __imag__ __t
= __z
.imag();
982 template<typename _Tp
>
983 inline complex<long double>&
984 complex<long double>::operator/=(const complex<_Tp
>& __z
)
987 __real__ __t
= __z
.real();
988 __imag__ __t
= __z
.imag();
993 // These bits have to be at the end of this file, so that the
994 // specializations have all been defined.
995 // ??? No, they have to be there because of compiler limitation at
996 // inlining. It suffices that class specializations be defined.
998 complex<float>::complex(const complex<double>& __z
)
999 : _M_value(_ComplexT(__z
._M_value
)) { }
1002 complex<float>::complex(const complex<long double>& __z
)
1003 : _M_value(_ComplexT(__z
._M_value
)) { }
1006 complex<double>::complex(const complex<float>& __z
)
1007 : _M_value(_ComplexT(__z
._M_value
)) { }
1010 complex<double>::complex(const complex<long double>& __z
)
1012 __real__ _M_value
= __z
.real();
1013 __imag__ _M_value
= __z
.imag();
1017 complex<long double>::complex(const complex<float>& __z
)
1018 : _M_value(_ComplexT(__z
._M_value
)) { }
1021 complex<long double>::complex(const complex<double>& __z
)
1022 : _M_value(_ComplexT(__z
._M_value
)) { }
1025 #endif /* _CPP_COMPLEX */