OSDN Git Service

2005-01-25 Benjamin Kosnik <bkoz@redhat.com>
[pf3gnuchains/gcc-fork.git] / libstdc++-v3 / include / std / std_complex.h
1 // The template and inlines for the -*- C++ -*- complex number classes.
2
3 // Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005
4 // Free Software Foundation, Inc.
5 //
6 // This file is part of the GNU ISO C++ Library.  This library is free
7 // software; you can redistribute it and/or modify it under the
8 // terms of the GNU General Public License as published by the
9 // Free Software Foundation; either version 2, or (at your option)
10 // any later version.
11
12 // This library is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 // GNU General Public License for more details.
16
17 // You should have received a copy of the GNU General Public License along
18 // with this library; see the file COPYING.  If not, write to the Free
19 // Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
20 // USA.
21
22 // As a special exception, you may use this file as part of a free software
23 // library without restriction.  Specifically, if other files instantiate
24 // templates or use macros or inline functions from this file, or you compile
25 // this file and link it with other files to produce an executable, this
26 // file does not by itself cause the resulting executable to be covered by
27 // the GNU General Public License.  This exception does not however
28 // invalidate any other reasons why the executable file might be covered by
29 // the GNU General Public License.
30
31 //
32 // ISO C++ 14882: 26.2  Complex Numbers
33 // Note: this is not a conforming implementation.
34 // Initially implemented by Ulrich Drepper <drepper@cygnus.com>
35 // Improved by Gabriel Dos Reis <dosreis@cmla.ens-cachan.fr>
36 //
37
38 /** @file complex
39  *  This is a Standard C++ Library header.
40  */
41
42 #ifndef _GLIBCXX_COMPLEX
43 #define _GLIBCXX_COMPLEX 1
44
45 #pragma GCC system_header
46
47 #include <bits/c++config.h>
48 #include <bits/cpp_type_traits.h>
49 #include <cmath>
50 #include <sstream>
51
52 namespace std
53 {
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>;
59
60   ///  Return magnitude of @a z.
61   template<typename _Tp> _Tp abs(const complex<_Tp>&);
62   ///  Return phase angle of @a z.
63   template<typename _Tp> _Tp arg(const complex<_Tp>&);
64   ///  Return @a z magnitude squared.
65   template<typename _Tp> _Tp norm(const complex<_Tp>&);
66
67   ///  Return complex conjugate of @a z.
68   template<typename _Tp> complex<_Tp> conj(const complex<_Tp>&);
69   ///  Return complex with magnitude @a rho and angle @a theta.
70   template<typename _Tp> complex<_Tp> polar(const _Tp&, const _Tp& = 0);
71
72   // Transcendentals:
73   /// Return complex cosine of @a z.
74   template<typename _Tp> complex<_Tp> cos(const complex<_Tp>&);
75   /// Return complex hyperbolic cosine of @a z.
76   template<typename _Tp> complex<_Tp> cosh(const complex<_Tp>&);
77   /// Return complex base e exponential of @a z.
78   template<typename _Tp> complex<_Tp> exp(const complex<_Tp>&);
79   /// Return complex natural logarithm of @a z.
80   template<typename _Tp> complex<_Tp> log(const complex<_Tp>&);
81   /// Return complex base 10 logarithm of @a z.
82   template<typename _Tp> complex<_Tp> log10(const complex<_Tp>&);
83   /// Return complex cosine of @a z.
84   template<typename _Tp> complex<_Tp> pow(const complex<_Tp>&, int);
85   /// Return @a x to the @a y'th power.
86   template<typename _Tp> complex<_Tp> pow(const complex<_Tp>&, const _Tp&);
87   /// Return @a x to the @a y'th power.
88   template<typename _Tp> complex<_Tp> pow(const complex<_Tp>&, 
89                                           const complex<_Tp>&);
90   /// Return @a x to the @a y'th power.
91   template<typename _Tp> complex<_Tp> pow(const _Tp&, const complex<_Tp>&);
92   /// Return complex sine of @a z.
93   template<typename _Tp> complex<_Tp> sin(const complex<_Tp>&);
94   /// Return complex hyperbolic sine of @a z.
95   template<typename _Tp> complex<_Tp> sinh(const complex<_Tp>&);
96   /// Return complex square root of @a z.
97   template<typename _Tp> complex<_Tp> sqrt(const complex<_Tp>&);
98   /// Return complex tangent of @a z.
99   template<typename _Tp> complex<_Tp> tan(const complex<_Tp>&);
100   /// Return complex hyperbolic tangent of @a z.
101   template<typename _Tp> complex<_Tp> tanh(const complex<_Tp>&);
102   //@}
103     
104     
105   // 26.2.2  Primary template class complex
106   /**
107    *  Template to represent complex numbers.
108    *
109    *  Specializations for float, double, and long double are part of the
110    *  library.  Results with any other type are not guaranteed.
111    *
112    *  @param  Tp  Type of real and imaginary values.
113   */
114   template<typename _Tp>
115     struct complex
116     {
117       /// Value typedef.
118       typedef _Tp value_type;
119       
120       ///  Default constructor.  First parameter is x, second parameter is y.
121       ///  Unspecified parameters default to 0.
122       complex(const _Tp& = _Tp(), const _Tp & = _Tp());
123
124       // Lets the compiler synthesize the copy constructor   
125       // complex (const complex<_Tp>&);
126       ///  Copy constructor.
127       template<typename _Up>
128         complex(const complex<_Up>&);
129
130       ///  Return real part of complex number.
131       _Tp& real(); 
132       ///  Return real part of complex number.
133       const _Tp& real() const;
134       ///  Return imaginary part of complex number.
135       _Tp& imag();
136       ///  Return imaginary part of complex number.
137       const _Tp& imag() const;
138
139       /// Assign this complex number to scalar @a t.
140       complex<_Tp>& operator=(const _Tp&);
141       /// Add @a t to this complex number.
142       complex<_Tp>& operator+=(const _Tp&);
143       /// Subtract @a t from this complex number.
144       complex<_Tp>& operator-=(const _Tp&);
145       /// Multiply this complex number by @a t.
146       complex<_Tp>& operator*=(const _Tp&);
147       /// Divide this complex number by @a t.
148       complex<_Tp>& operator/=(const _Tp&);
149
150       // Lets the compiler synthesize the
151       // copy and assignment operator
152       // complex<_Tp>& operator= (const complex<_Tp>&);
153       /// Assign this complex number to complex @a z.
154       template<typename _Up>
155         complex<_Tp>& operator=(const complex<_Up>&);
156       /// Add @a z to this complex number.
157       template<typename _Up>
158         complex<_Tp>& operator+=(const complex<_Up>&);
159       /// Subtract @a z from this complex number.
160       template<typename _Up>
161         complex<_Tp>& operator-=(const complex<_Up>&);
162       /// Multiply this complex number by @a z.
163       template<typename _Up>
164         complex<_Tp>& operator*=(const complex<_Up>&);
165       /// Divide this complex number by @a z.
166       template<typename _Up>
167         complex<_Tp>& operator/=(const complex<_Up>&);
168
169       const complex& __rep() const;
170
171     private:
172       _Tp _M_real;
173       _Tp _M_imag;
174     };
175
176   template<typename _Tp>
177     inline _Tp&
178     complex<_Tp>::real() { return _M_real; }
179
180   template<typename _Tp>
181     inline const _Tp&
182     complex<_Tp>::real() const { return _M_real; }
183
184   template<typename _Tp>
185     inline _Tp&
186     complex<_Tp>::imag() { return _M_imag; }
187
188   template<typename _Tp>
189     inline const _Tp&
190     complex<_Tp>::imag() const { return _M_imag; }
191
192   template<typename _Tp>
193     inline 
194     complex<_Tp>::complex(const _Tp& __r, const _Tp& __i)
195     : _M_real(__r), _M_imag(__i) { }
196
197   template<typename _Tp>
198     template<typename _Up>
199     inline 
200     complex<_Tp>::complex(const complex<_Up>& __z)
201     : _M_real(__z.real()), _M_imag(__z.imag()) { }
202         
203   template<typename _Tp>
204     complex<_Tp>&
205     complex<_Tp>::operator=(const _Tp& __t)
206     {
207      _M_real = __t;
208      _M_imag = _Tp();
209      return *this;
210     } 
211
212   // 26.2.5/1
213   template<typename _Tp>
214     inline complex<_Tp>&
215     complex<_Tp>::operator+=(const _Tp& __t)
216     {
217       _M_real += __t;
218       return *this;
219     }
220
221   // 26.2.5/3
222   template<typename _Tp>
223     inline complex<_Tp>&
224     complex<_Tp>::operator-=(const _Tp& __t)
225     {
226       _M_real -= __t;
227       return *this;
228     }
229
230   // 26.2.5/5
231   template<typename _Tp>
232     complex<_Tp>&
233     complex<_Tp>::operator*=(const _Tp& __t)
234     {
235       _M_real *= __t;
236       _M_imag *= __t;
237       return *this;
238     }
239
240   // 26.2.5/7
241   template<typename _Tp>
242     complex<_Tp>&
243     complex<_Tp>::operator/=(const _Tp& __t)
244     {
245       _M_real /= __t;
246       _M_imag /= __t;
247       return *this;
248     }
249
250   template<typename _Tp>
251     template<typename _Up>
252     complex<_Tp>&
253     complex<_Tp>::operator=(const complex<_Up>& __z)
254     {
255       _M_real = __z.real();
256       _M_imag = __z.imag();
257       return *this;
258     }
259
260   // 26.2.5/9
261   template<typename _Tp>
262     template<typename _Up>
263     complex<_Tp>&
264     complex<_Tp>::operator+=(const complex<_Up>& __z)
265     {
266       _M_real += __z.real();
267       _M_imag += __z.imag();
268       return *this;
269     }
270
271   // 26.2.5/11
272   template<typename _Tp>
273     template<typename _Up>
274     complex<_Tp>&
275     complex<_Tp>::operator-=(const complex<_Up>& __z)
276     {
277       _M_real -= __z.real();
278       _M_imag -= __z.imag();
279       return *this;
280     }
281
282   // 26.2.5/13
283   // XXX: This is a grammar school implementation.
284   template<typename _Tp>
285     template<typename _Up>
286     complex<_Tp>&
287     complex<_Tp>::operator*=(const complex<_Up>& __z)
288     {
289       const _Tp __r = _M_real * __z.real() - _M_imag * __z.imag();
290       _M_imag = _M_real * __z.imag() + _M_imag * __z.real();
291       _M_real = __r;
292       return *this;
293     }
294
295   // 26.2.5/15
296   // XXX: This is a grammar school implementation.
297   template<typename _Tp>
298     template<typename _Up>
299     complex<_Tp>&
300     complex<_Tp>::operator/=(const complex<_Up>& __z)
301     {
302       const _Tp __r =  _M_real * __z.real() + _M_imag * __z.imag();
303       const _Tp __n = std::norm(__z);
304       _M_imag = (_M_imag * __z.real() - _M_real * __z.imag()) / __n;
305       _M_real = __r / __n;
306       return *this;
307     }
308
309   template<typename _Tp>
310     inline const complex<_Tp>&
311     complex<_Tp>::__rep() const { return *this; }
312     
313   // Operators:
314   //@{
315   ///  Return new complex value @a x plus @a y.
316   template<typename _Tp>
317     inline complex<_Tp>
318     operator+(const complex<_Tp>& __x, const complex<_Tp>& __y)
319     {
320       complex<_Tp> __r = __x;
321       __r += __y;
322       return __r;
323     }
324
325   template<typename _Tp>
326     inline complex<_Tp>
327     operator+(const complex<_Tp>& __x, const _Tp& __y)
328     {
329       complex<_Tp> __r = __x;
330       __r.real() += __y;
331       return __r;
332     }
333
334   template<typename _Tp>
335     inline complex<_Tp>
336     operator+(const _Tp& __x, const complex<_Tp>& __y)
337     {
338       complex<_Tp> __r = __y;
339       __r.real() += __x;
340       return __r;
341     }
342   //@}
343
344   //@{
345   ///  Return new complex value @a x minus @a y.
346   template<typename _Tp>
347     inline complex<_Tp>
348     operator-(const complex<_Tp>& __x, const complex<_Tp>& __y)
349     {
350       complex<_Tp> __r = __x;
351       __r -= __y;
352       return __r;
353     }
354     
355   template<typename _Tp>
356     inline complex<_Tp>
357     operator-(const complex<_Tp>& __x, const _Tp& __y)
358     {
359       complex<_Tp> __r = __x;
360       __r.real() -= __y;
361       return __r;
362     }
363
364   template<typename _Tp>
365     inline complex<_Tp>
366     operator-(const _Tp& __x, const complex<_Tp>& __y)
367     {
368       complex<_Tp> __r(__x, -__y.imag());
369       __r.real() -= __y.real();
370       return __r;
371     }
372   //@}
373
374   //@{
375   ///  Return new complex value @a x times @a y.
376   template<typename _Tp>
377     inline complex<_Tp>
378     operator*(const complex<_Tp>& __x, const complex<_Tp>& __y)
379     {
380       complex<_Tp> __r = __x;
381       __r *= __y;
382       return __r;
383     }
384
385   template<typename _Tp>
386     inline complex<_Tp>
387     operator*(const complex<_Tp>& __x, const _Tp& __y)
388     {
389       complex<_Tp> __r = __x;
390       __r *= __y;
391       return __r;
392     }
393
394   template<typename _Tp>
395     inline complex<_Tp>
396     operator*(const _Tp& __x, const complex<_Tp>& __y)
397     {
398       complex<_Tp> __r = __y;
399       __r *= __x;
400       return __r;
401     }
402   //@}
403
404   //@{
405   ///  Return new complex value @a x divided by @a y.
406   template<typename _Tp>
407     inline complex<_Tp>
408     operator/(const complex<_Tp>& __x, const complex<_Tp>& __y)
409     {
410       complex<_Tp> __r = __x;
411       __r /= __y;
412       return __r;
413     }
414     
415   template<typename _Tp>
416     inline complex<_Tp>
417     operator/(const complex<_Tp>& __x, const _Tp& __y)
418     {
419       complex<_Tp> __r = __x;
420       __r /= __y;
421       return __r;
422     }
423
424   template<typename _Tp>
425     inline complex<_Tp>
426     operator/(const _Tp& __x, const complex<_Tp>& __y)
427     {
428       complex<_Tp> __r = __x;
429       __r /= __y;
430       return __r;
431     }
432   //@}
433
434   ///  Return @a x.
435   template<typename _Tp>
436     inline complex<_Tp>
437     operator+(const complex<_Tp>& __x)
438     { return __x; }
439
440   ///  Return complex negation of @a x.
441   template<typename _Tp>
442     inline complex<_Tp>
443     operator-(const complex<_Tp>& __x)
444     {  return complex<_Tp>(-__x.real(), -__x.imag()); }
445
446   //@{
447   ///  Return true if @a x is equal to @a y.
448   template<typename _Tp>
449     inline bool
450     operator==(const complex<_Tp>& __x, const complex<_Tp>& __y)
451     { return __x.real() == __y.real() && __x.imag() == __y.imag(); }
452
453   template<typename _Tp>
454     inline bool
455     operator==(const complex<_Tp>& __x, const _Tp& __y)
456     { return __x.real() == __y && __x.imag() == _Tp(); }
457
458   template<typename _Tp>
459     inline bool
460     operator==(const _Tp& __x, const complex<_Tp>& __y)
461     { return __x == __y.real() && _Tp() == __y.imag(); }
462   //@}
463
464   //@{
465   ///  Return false if @a x is equal to @a y.
466   template<typename _Tp>
467     inline bool
468     operator!=(const complex<_Tp>& __x, const complex<_Tp>& __y)
469     { return __x.real() != __y.real() || __x.imag() != __y.imag(); }
470
471   template<typename _Tp>
472     inline bool
473     operator!=(const complex<_Tp>& __x, const _Tp& __y)
474     { return __x.real() != __y || __x.imag() != _Tp(); }
475
476   template<typename _Tp>
477     inline bool
478     operator!=(const _Tp& __x, const complex<_Tp>& __y)
479     { return __x != __y.real() || _Tp() != __y.imag(); }
480   //@}
481
482   ///  Extraction operator for complex values.
483   template<typename _Tp, typename _CharT, class _Traits>
484     basic_istream<_CharT, _Traits>&
485     operator>>(basic_istream<_CharT, _Traits>& __is, complex<_Tp>& __x)
486     {
487       _Tp __re_x, __im_x;
488       _CharT __ch;
489       __is >> __ch;
490       if (__ch == '(') 
491         {
492           __is >> __re_x >> __ch;
493           if (__ch == ',') 
494             {
495               __is >> __im_x >> __ch;
496               if (__ch == ')') 
497                 __x = complex<_Tp>(__re_x, __im_x);
498               else
499                 __is.setstate(ios_base::failbit);
500             }
501           else if (__ch == ')') 
502             __x = __re_x;
503           else
504             __is.setstate(ios_base::failbit);
505         }
506       else 
507         {
508           __is.putback(__ch);
509           __is >> __re_x;
510           __x = __re_x;
511         }
512       return __is;
513     }
514
515   ///  Insertion operator for complex values.
516   template<typename _Tp, typename _CharT, class _Traits>
517     basic_ostream<_CharT, _Traits>&
518     operator<<(basic_ostream<_CharT, _Traits>& __os, const complex<_Tp>& __x)
519     {
520       basic_ostringstream<_CharT, _Traits> __s;
521       __s.flags(__os.flags());
522       __s.imbue(__os.getloc());
523       __s.precision(__os.precision());
524       __s << '(' << __x.real() << ',' << __x.imag() << ')';
525       return __os << __s.str();
526     }
527
528   // Values
529   template<typename _Tp>
530     inline _Tp&
531     real(complex<_Tp>& __z)
532     { return __z.real(); }
533     
534   template<typename _Tp>
535     inline const _Tp&
536     real(const complex<_Tp>& __z)
537     { return __z.real(); }
538     
539   template<typename _Tp>
540     inline _Tp&
541     imag(complex<_Tp>& __z)
542     { return __z.imag(); }
543     
544   template<typename _Tp>
545     inline const _Tp&
546     imag(const complex<_Tp>& __z)
547     { return __z.imag(); }
548
549   // 26.2.7/3 abs(__z):  Returns the magnitude of __z.
550   template<typename _Tp>
551     inline _Tp
552     __complex_abs(const complex<_Tp>& __z)
553     {
554       _Tp __x = __z.real();
555       _Tp __y = __z.imag();
556       const _Tp __s = std::max(abs(__x), abs(__y));
557       if (__s == _Tp())  // well ...
558         return __s;
559       __x /= __s; 
560       __y /= __s;
561       return __s * sqrt(__x * __x + __y * __y);
562     }
563
564 #if _GLIBCXX_USE_C99_COMPLEX_MATH
565   inline float
566   __complex_abs(__complex__ float __z) { return __builtin_cabsf(__z); }
567
568   inline double
569   __complex_abs(__complex__ double __z) { return __builtin_cabs(__z); }
570
571   inline long double
572   __complex_abs(const __complex__ long double& __z)
573   { return __builtin_cabsl(__z); }
574
575   template<typename _Tp>
576     inline _Tp
577     abs(const complex<_Tp>& __z) { return __complex_abs(__z.__rep()); }
578 #else
579   template<typename _Tp>
580     inline _Tp
581     abs(const complex<_Tp>& __z) { return __complex_abs(__z); }
582 #endif  
583
584
585   // 26.2.7/4: arg(__z): Returns the phase angle of __z.
586   template<typename _Tp>
587     inline _Tp
588     __complex_arg(const complex<_Tp>& __z)
589     { return  atan2(__z.imag(), __z.real()); }
590
591 #if _GLIBCXX_USE_C99_COMPLEX_MATH
592   inline float
593   __complex_arg(__complex__ float __z) { return __builtin_cargf(__z); }
594
595   inline double
596   __complex_arg(__complex__ double __z) { return __builtin_carg(__z); }
597
598   inline long double
599   __complex_arg(const __complex__ long double& __z)
600   { return __builtin_cargl(__z); }
601
602   template<typename _Tp>
603     inline _Tp
604     arg(const complex<_Tp>& __z) { return __complex_arg(__z.__rep()); }
605 #else
606   template<typename _Tp>
607     inline _Tp
608     arg(const complex<_Tp>& __z) { return __complex_arg(__z); }
609 #endif
610
611   // 26.2.7/5: norm(__z) returns the squared magintude of __z.
612   //     As defined, norm() is -not- a norm is the common mathematical
613   //     sens used in numerics.  The helper class _Norm_helper<> tries to
614   //     distinguish between builtin floating point and the rest, so as
615   //     to deliver an answer as close as possible to the real value.
616   template<bool>
617     struct _Norm_helper
618     {
619       template<typename _Tp>
620         static inline _Tp _S_do_it(const complex<_Tp>& __z)
621         {
622           const _Tp __x = __z.real();
623           const _Tp __y = __z.imag();
624           return __x * __x + __y * __y;
625         }
626     };
627
628   template<>
629     struct _Norm_helper<true>
630     {
631       template<typename _Tp>
632         static inline _Tp _S_do_it(const complex<_Tp>& __z)
633         {
634           _Tp __res = std::abs(__z);
635           return __res * __res;
636         }
637     };
638   
639   template<typename _Tp>
640     inline _Tp
641     norm(const complex<_Tp>& __z)
642     {
643       return _Norm_helper<__is_floating<_Tp>::_M_type 
644         && !_GLIBCXX_FAST_MATH>::_S_do_it(__z);
645     }
646
647   template<typename _Tp>
648     inline complex<_Tp>
649     polar(const _Tp& __rho, const _Tp& __theta)
650     { return complex<_Tp>(__rho * cos(__theta), __rho * sin(__theta)); }
651
652   template<typename _Tp>
653     inline complex<_Tp>
654     conj(const complex<_Tp>& __z)
655     { return complex<_Tp>(__z.real(), -__z.imag()); }
656   
657   // Transcendentals
658
659   // 26.2.8/1 cos(__z):  Returns the cosine of __z.
660   template<typename _Tp>
661     inline complex<_Tp>
662     __complex_cos(const complex<_Tp>& __z)
663     {
664       const _Tp __x = __z.real();
665       const _Tp __y = __z.imag();
666       return complex<_Tp>(cos(__x) * cosh(__y), -sin(__x) * sinh(__y));
667     }
668
669 #if _GLIBCXX_USE_C99_COMPLEX_MATH
670   inline __complex__ float
671   __complex_cos(__complex__ float __z) { return __builtin_ccosf(__z); }
672
673   inline __complex__ double
674   __complex_cos(__complex__ double __z) { return __builtin_ccos(__z); }
675
676   inline __complex__ long double
677   __complex_cos(const __complex__ long double& __z)
678   { return __builtin_ccosl(__z); }
679
680   template<typename _Tp>
681     inline complex<_Tp>
682     cos(const complex<_Tp>& __z) { return __complex_cos(__z.__rep()); }
683 #else
684   template<typename _Tp>
685     inline complex<_Tp>
686     cos(const complex<_Tp>& __z) { return __complex_cos(__z); }
687 #endif
688
689   // 26.2.8/2 cosh(__z): Returns the hyperbolic cosine of __z.
690   template<typename _Tp>
691     inline complex<_Tp>
692     __complex_cosh(const complex<_Tp>& __z)
693     {
694       const _Tp __x = __z.real();
695       const _Tp __y = __z.imag();
696       return complex<_Tp>(cosh(__x) * cos(__y), sinh(__x) * sin(__y));
697     }
698
699 #if _GLIBCXX_USE_C99_COMPLEX_MATH
700   inline __complex__ float
701   __complex_cosh(__complex__ float __z) { return __builtin_ccoshf(__z); }
702
703   inline __complex__ double
704   __complex_cosh(__complex__ double __z) { return __builtin_ccosh(__z); }
705
706   inline __complex__ long double
707   __complex_cosh(const __complex__ long double& __z)
708   { return __builtin_ccoshl(__z); }
709
710   template<typename _Tp>
711     inline complex<_Tp>
712     cosh(const complex<_Tp>& __z) { return __complex_cosh(__z.__rep()); }
713 #else
714   template<typename _Tp>
715     inline complex<_Tp>
716     cosh(const complex<_Tp>& __z) { return __complex_cosh(__z); }
717 #endif
718
719   // 26.2.8/3 exp(__z): Returns the complex base e exponential of x
720   template<typename _Tp>
721     inline complex<_Tp>
722     __complex_exp(const complex<_Tp>& __z)
723     { return std::polar(exp(__z.real()), __z.imag()); }
724
725 #if _GLIBCXX_USE_C99_COMPLEX_MATH
726   inline __complex__ float
727   __complex_exp(__complex__ float __z) { return __builtin_cexpf(__z); }
728
729   inline __complex__ double
730   __complex_exp(__complex__ double __z) { return __builtin_cexp(__z); }
731
732   inline __complex__ long double
733   __complex_exp(const __complex__ long double& __z)
734   { return __builtin_cexpl(__z); }
735
736   template<typename _Tp>
737     inline complex<_Tp>
738     exp(const complex<_Tp>& __z) { return __complex_exp(__z.__rep()); }
739 #else
740   template<typename _Tp>
741     inline complex<_Tp>
742     exp(const complex<_Tp>& __z) { return __complex_exp(__z); }
743 #endif
744
745   // 26.2.8/5 log(__z): Reurns the natural complex logaritm of __z.
746   //                    The branch cut is along the negative axis.
747   template<typename _Tp>
748     inline complex<_Tp>
749     __complex_log(const complex<_Tp>& __z)
750     { return complex<_Tp>(log(std::abs(__z)), std::arg(__z)); }
751
752   /*
753   inline __complex__ float
754   __complex_log(__complex__ float __z) { return __builtin_clogf(__z); }
755
756   inline __complex__ double
757   __complex_log(__complex__ double __z) { return __builtin_clog(__z); }
758
759   inline __complex__ long double
760   __complex_log(const __complex__ long double& __z)
761   { return __builtin_clogl(__z); } */
762
763   // FIXME: Currently we don't use built-ins for log() because of some
764   //        obscure user name-space issues.  So, we use the generic version
765   //        which is why we don't use __z.__rep() in the call below.
766   template<typename _Tp>
767     inline complex<_Tp>
768     log(const complex<_Tp>& __z) { return __complex_log(__z); }
769
770   template<typename _Tp>
771     inline complex<_Tp>
772     log10(const complex<_Tp>& __z)
773     { return std::log(__z) / log(_Tp(10.0)); }
774
775   // 26.2.8/10 sin(__z): Returns the sine of __z.
776   template<typename _Tp>
777     inline complex<_Tp>
778     __complex_sin(const complex<_Tp>& __z)
779     {
780       const _Tp __x = __z.real();
781       const _Tp __y = __z.imag();
782       return complex<_Tp>(sin(__x) * cosh(__y), cos(__x) * sinh(__y)); 
783     }
784
785 #if _GLIBCXX_USE_C99_COMPLEX_MATH
786   inline __complex__ float
787   __complex_sin(__complex__ float __z) { return __builtin_csinf(__z); }
788
789   inline __complex__ double
790   __complex_sin(__complex__ double __z) { return __builtin_csin(__z); }
791
792   inline __complex__ long double
793   __complex_sin(const __complex__ long double& __z)
794   { return __builtin_csinl(__z); }
795
796   template<typename _Tp>
797     inline complex<_Tp>
798     sin(const complex<_Tp>& __z) { return __complex_sin(__z.__rep()); }
799 #else
800   template<typename _Tp>
801     inline complex<_Tp>
802     sin(const complex<_Tp>& __z) { return __complex_sin(__z); }
803 #endif
804
805   // 26.2.8/11 sinh(__z): Returns the hyperbolic sine of __z.
806   template<typename _Tp>
807     inline complex<_Tp>
808     __complex_sinh(const complex<_Tp>& __z)
809     {
810       const _Tp __x = __z.real();
811       const _Tp  __y = __z.imag();
812       return complex<_Tp>(sinh(__x) * cos(__y), cosh(__x) * sin(__y));
813     }
814
815 #if _GLIBCXX_USE_C99_COMPLEX_MATH
816   inline __complex__ float
817   __complex_sinh(__complex__ float __z) { return __builtin_csinhf(__z); }      
818
819   inline __complex__ double
820   __complex_sinh(__complex__ double __z) { return __builtin_csinh(__z); }      
821
822   inline __complex__ long double
823   __complex_sinh(const __complex__ long double& __z)
824   { return __builtin_csinhl(__z); }      
825
826   template<typename _Tp>
827     inline complex<_Tp>
828     sinh(const complex<_Tp>& __z) { return __complex_sinh(__z.__rep()); }
829 #else
830   template<typename _Tp>
831     inline complex<_Tp>
832     sinh(const complex<_Tp>& __z) { return __complex_sinh(__z); }
833 #endif
834
835   // 26.2.8/13 sqrt(__z): Returns the complex square root of __z.
836   //                     The branch cut is on the negative axis.
837   template<typename _Tp>
838     complex<_Tp>
839     __complex_sqrt(const complex<_Tp>& __z)
840     {
841       _Tp __x = __z.real();
842       _Tp __y = __z.imag();
843
844       if (__x == _Tp())
845         {
846           _Tp __t = sqrt(abs(__y) / 2);
847           return complex<_Tp>(__t, __y < _Tp() ? -__t : __t);
848         }
849       else
850         {
851           _Tp __t = sqrt(2 * (std::abs(__z) + abs(__x)));
852           _Tp __u = __t / 2;
853           return __x > _Tp()
854             ? complex<_Tp>(__u, __y / __t)
855             : complex<_Tp>(abs(__y) / __t, __y < _Tp() ? -__u : __u);
856         }
857     }
858
859 #if _GLIBCXX_USE_C99_COMPLEX_MATH
860   inline __complex__ float
861   __complex_sqrt(__complex__ float __z) { return __builtin_csqrtf(__z); }
862
863   inline __complex__ double
864   __complex_sqrt(__complex__ double __z) { return __builtin_csqrt(__z); }
865
866   inline __complex__ long double
867   __complex_sqrt(const __complex__ long double& __z)
868   { return __builtin_csqrtl(__z); }
869
870   template<typename _Tp>
871     inline complex<_Tp>
872     sqrt(const complex<_Tp>& __z) { return __complex_sqrt(__z.__rep()); }
873 #else
874   template<typename _Tp>
875     inline complex<_Tp>
876     sqrt(const complex<_Tp>& __z) { return __complex_sqrt(__z); }
877 #endif
878
879   // 26.2.8/14 tan(__z):  Return the complex tangent of __z.
880   
881   template<typename _Tp>
882     inline complex<_Tp>
883     __complex_tan(const complex<_Tp>& __z)
884     { return std::sin(__z) / std::cos(__z); }
885
886 #if _GLIBCXX_USE_C99_COMPLEX_MATH
887   inline __complex__ float
888   __complex_tan(__complex__ float __z) { return __builtin_ctanf(__z); }
889
890   inline __complex__ double
891   __complex_tan(__complex__ double __z) { return __builtin_ctan(__z); }
892
893   inline __complex__ long double
894   __complex_tan(const __complex__ long double& __z)
895   { return __builtin_ctanl(__z); }
896
897   template<typename _Tp>
898     inline complex<_Tp>
899     tan(const complex<_Tp>& __z) { return __complex_tan(__z.__rep()); }
900 #else
901   template<typename _Tp>
902     inline complex<_Tp>
903     tan(const complex<_Tp>& __z) { return __complex_tan(__z); }
904 #endif
905
906
907   // 26.2.8/15 tanh(__z):  Returns the hyperbolic tangent of __z.
908   
909   template<typename _Tp>
910     inline complex<_Tp>
911     __complex_tanh(const complex<_Tp>& __z)
912     { return std::sinh(__z) / std::cosh(__z); }
913
914 #if _GLIBCXX_USE_C99_COMPLEX_MATH
915   inline __complex__ float
916   __complex_tanh(__complex__ float __z) { return __builtin_ctanhf(__z); }
917
918   inline __complex__ double
919   __complex_tanh(__complex__ double __z) { return __builtin_ctanh(__z); }
920
921   inline __complex__ long double
922   __complex_tanh(const __complex__ long double& __z)
923   { return __builtin_ctanhl(__z); }
924
925   template<typename _Tp>
926     inline complex<_Tp>
927     tanh(const complex<_Tp>& __z) { return __complex_tanh(__z.__rep()); }
928 #else
929   template<typename _Tp>
930     inline complex<_Tp>
931     tanh(const complex<_Tp>& __z) { return __complex_tanh(__z); }
932 #endif
933
934
935   // 26.2.8/9  pow(__x, __y): Returns the complex power base of __x
936   //                          raised to the __y-th power.  The branch
937   //                          cut is on the negative axis.
938   template<typename _Tp>
939     inline complex<_Tp>
940     pow(const complex<_Tp>& __z, int __n)
941     { return std::__pow_helper(__z, __n); }
942
943   template<typename _Tp>
944     complex<_Tp>
945     pow(const complex<_Tp>& __x, const _Tp& __y)
946     {
947       if (__x.imag() == _Tp() && __x.real() > _Tp())
948         return pow(__x.real(), __y);
949
950       complex<_Tp> __t = std::log(__x);
951       return std::polar(exp(__y * __t.real()), __y * __t.imag());
952     }
953
954   template<typename _Tp>
955     inline complex<_Tp>
956     __complex_pow(const complex<_Tp>& __x, const complex<_Tp>& __y)
957     { return __x == _Tp() ? _Tp() : std::exp(__y * std::log(__x)); }
958
959 #if _GLIBCXX_USE_C99_COMPLEX_MATH
960   inline __complex__ float
961   __complex_pow(__complex__ float __x, __complex__ float __y)
962   { return __builtin_cpowf(__x, __y); }
963
964   inline __complex__ double
965   __complex_pow(__complex__ double __x, __complex__ double __y)
966   { return __builtin_cpow(__x, __y); }
967
968   inline __complex__ long double
969   __complex_pow(__complex__ long double& __x, __complex__ long double& __y)
970   { return __builtin_cpowl(__x, __y); }
971 #endif
972
973   template<typename _Tp>
974     inline complex<_Tp>
975     pow(const complex<_Tp>& __x, const complex<_Tp>& __y)
976     { return __complex_pow(__x, __y); }
977
978   template<typename _Tp>
979     inline complex<_Tp>
980     pow(const _Tp& __x, const complex<_Tp>& __y)
981     {
982       return __x > _Tp() ? std::polar(pow(__x, __y.real()),
983                                       __y.imag() * log(__x))
984                          : std::pow(complex<_Tp>(__x, _Tp()), __y);
985     }
986
987   // 26.2.3  complex specializations
988   // complex<float> specialization
989   template<>
990     struct complex<float>
991     {
992       typedef float value_type;
993       typedef __complex__ float _ComplexT;
994
995       complex(_ComplexT __z) : _M_value(__z) { }
996
997       complex(float = 0.0f, float = 0.0f);
998 #if _GLIBCXX_BUGGY_COMPLEX
999       complex(const complex& __z) : _M_value(__z._M_value) { }
1000 #endif
1001       explicit complex(const complex<double>&);
1002       explicit complex(const complex<long double>&);
1003
1004       float& real();
1005       const float& real() const;
1006       float& imag();
1007       const float& imag() const;
1008
1009       complex<float>& operator=(float);
1010       complex<float>& operator+=(float);
1011       complex<float>& operator-=(float);
1012       complex<float>& operator*=(float);
1013       complex<float>& operator/=(float);
1014
1015       // Let's the compiler synthetize the copy and assignment
1016       // operator.  It always does a pretty good job.
1017       // complex& operator= (const complex&);
1018       template<typename _Tp>
1019         complex<float>&operator=(const complex<_Tp>&);
1020       template<typename _Tp>
1021         complex<float>& operator+=(const complex<_Tp>&);
1022       template<class _Tp>
1023         complex<float>& operator-=(const complex<_Tp>&);
1024       template<class _Tp>
1025         complex<float>& operator*=(const complex<_Tp>&);
1026       template<class _Tp>
1027         complex<float>&operator/=(const complex<_Tp>&);
1028
1029       const _ComplexT& __rep() const { return _M_value; }
1030
1031     private:
1032       _ComplexT _M_value;
1033     };
1034
1035   inline float&
1036   complex<float>::real()
1037   { return __real__ _M_value; }
1038
1039   inline const float&
1040   complex<float>::real() const
1041   { return __real__ _M_value; }
1042
1043   inline float&
1044   complex<float>::imag()
1045   { return __imag__ _M_value; }
1046
1047   inline const float&
1048   complex<float>::imag() const
1049   { return __imag__ _M_value; }
1050
1051   inline
1052   complex<float>::complex(float r, float i)
1053   {
1054     __real__ _M_value = r;
1055     __imag__ _M_value = i;
1056   }
1057
1058   inline complex<float>&
1059   complex<float>::operator=(float __f)
1060   {
1061     __real__ _M_value = __f;
1062     __imag__ _M_value = 0.0f;
1063     return *this;
1064   }
1065
1066   inline complex<float>&
1067   complex<float>::operator+=(float __f)
1068   {
1069     __real__ _M_value += __f;
1070     return *this;
1071   }
1072
1073   inline complex<float>&
1074   complex<float>::operator-=(float __f)
1075   {
1076     __real__ _M_value -= __f;
1077     return *this;
1078   }
1079
1080   inline complex<float>&
1081   complex<float>::operator*=(float __f)
1082   {
1083     _M_value *= __f;
1084     return *this;
1085   }
1086
1087   inline complex<float>&
1088   complex<float>::operator/=(float __f)
1089   {
1090     _M_value /= __f;
1091     return *this;
1092   }
1093
1094   template<typename _Tp>
1095   inline complex<float>&
1096   complex<float>::operator=(const complex<_Tp>& __z)
1097   {
1098     __real__ _M_value = __z.real();
1099     __imag__ _M_value = __z.imag();
1100     return *this;
1101   }
1102
1103   template<typename _Tp>
1104   inline complex<float>&
1105   complex<float>::operator+=(const complex<_Tp>& __z)
1106   {
1107     __real__ _M_value += __z.real();
1108     __imag__ _M_value += __z.imag();
1109     return *this;
1110   }
1111     
1112   template<typename _Tp>
1113     inline complex<float>&
1114     complex<float>::operator-=(const complex<_Tp>& __z)
1115     {
1116      __real__ _M_value -= __z.real();
1117      __imag__ _M_value -= __z.imag();
1118      return *this;
1119     } 
1120
1121   template<typename _Tp>
1122     inline complex<float>&
1123     complex<float>::operator*=(const complex<_Tp>& __z)
1124     {
1125       _ComplexT __t;
1126       __real__ __t = __z.real();
1127       __imag__ __t = __z.imag();
1128       _M_value *= __t;
1129       return *this;
1130     }
1131
1132   template<typename _Tp>
1133     inline complex<float>&
1134     complex<float>::operator/=(const complex<_Tp>& __z)
1135     {
1136       _ComplexT __t;
1137       __real__ __t = __z.real();
1138       __imag__ __t = __z.imag();
1139       _M_value /= __t;
1140       return *this;
1141     }
1142
1143   // 26.2.3  complex specializations
1144   // complex<double> specialization
1145   template<>
1146     struct complex<double>
1147     {
1148       typedef double value_type;
1149       typedef __complex__ double _ComplexT;
1150
1151       complex(_ComplexT __z) : _M_value(__z) { }
1152
1153       complex(double  = 0.0, double = 0.0);
1154 #if _GLIBCXX_BUGGY_COMPLEX
1155       complex(const complex& __z) : _M_value(__z._M_value) { }
1156 #endif
1157       complex(const complex<float>&);
1158       explicit complex(const complex<long double>&);
1159
1160       double& real();
1161       const double& real() const;
1162       double& imag();
1163       const double& imag() const;
1164
1165       complex<double>& operator=(double);
1166       complex<double>& operator+=(double);
1167       complex<double>& operator-=(double);
1168       complex<double>& operator*=(double);
1169       complex<double>& operator/=(double);
1170
1171       // The compiler will synthetize this, efficiently.
1172       // complex& operator= (const complex&);
1173       template<typename _Tp>
1174         complex<double>& operator=(const complex<_Tp>&);
1175       template<typename _Tp>
1176         complex<double>& operator+=(const complex<_Tp>&);
1177       template<typename _Tp>
1178         complex<double>& operator-=(const complex<_Tp>&);
1179       template<typename _Tp>
1180         complex<double>& operator*=(const complex<_Tp>&);
1181       template<typename _Tp>
1182         complex<double>& operator/=(const complex<_Tp>&);
1183
1184       const _ComplexT& __rep() const { return _M_value; }
1185
1186     private:
1187       _ComplexT _M_value;
1188     };
1189
1190   inline double&
1191   complex<double>::real()
1192   { return __real__ _M_value; }
1193
1194   inline const double&
1195   complex<double>::real() const
1196   { return __real__ _M_value; }
1197
1198   inline double&
1199   complex<double>::imag()
1200   { return __imag__ _M_value; }
1201
1202   inline const double&
1203   complex<double>::imag() const
1204   { return __imag__ _M_value; }
1205
1206   inline
1207   complex<double>::complex(double __r, double __i)
1208   {
1209     __real__ _M_value = __r;
1210     __imag__ _M_value = __i;
1211   }
1212
1213   inline complex<double>&
1214   complex<double>::operator=(double __d)
1215   {
1216     __real__ _M_value = __d;
1217     __imag__ _M_value = 0.0;
1218     return *this;
1219   }
1220
1221   inline complex<double>&
1222   complex<double>::operator+=(double __d)
1223   {
1224     __real__ _M_value += __d;
1225     return *this;
1226   }
1227
1228   inline complex<double>&
1229   complex<double>::operator-=(double __d)
1230   {
1231     __real__ _M_value -= __d;
1232     return *this;
1233   }
1234
1235   inline complex<double>&
1236   complex<double>::operator*=(double __d)
1237   {
1238     _M_value *= __d;
1239     return *this;
1240   }
1241
1242   inline complex<double>&
1243   complex<double>::operator/=(double __d)
1244   {
1245     _M_value /= __d;
1246     return *this;
1247   }
1248
1249   template<typename _Tp>
1250     inline complex<double>&
1251     complex<double>::operator=(const complex<_Tp>& __z)
1252     {
1253       __real__ _M_value = __z.real();
1254       __imag__ _M_value = __z.imag();
1255       return *this;
1256     }
1257     
1258   template<typename _Tp>
1259     inline complex<double>&
1260     complex<double>::operator+=(const complex<_Tp>& __z)
1261     {
1262       __real__ _M_value += __z.real();
1263       __imag__ _M_value += __z.imag();
1264       return *this;
1265     }
1266
1267   template<typename _Tp>
1268     inline complex<double>&
1269     complex<double>::operator-=(const complex<_Tp>& __z)
1270     {
1271       __real__ _M_value -= __z.real();
1272       __imag__ _M_value -= __z.imag();
1273       return *this;
1274     }
1275
1276   template<typename _Tp>
1277     inline complex<double>&
1278     complex<double>::operator*=(const complex<_Tp>& __z)
1279     {
1280       _ComplexT __t;
1281       __real__ __t = __z.real();
1282       __imag__ __t = __z.imag();
1283       _M_value *= __t;
1284       return *this;
1285     }
1286
1287   template<typename _Tp>
1288     inline complex<double>&
1289     complex<double>::operator/=(const complex<_Tp>& __z)
1290     {
1291       _ComplexT __t;
1292       __real__ __t = __z.real();
1293       __imag__ __t = __z.imag();
1294       _M_value /= __t;
1295       return *this;
1296     }
1297
1298   // 26.2.3  complex specializations
1299   // complex<long double> specialization
1300   template<>
1301     struct complex<long double>
1302     {
1303       typedef long double value_type;
1304       typedef __complex__ long double _ComplexT;
1305
1306       complex(_ComplexT __z) : _M_value(__z) { }
1307
1308       complex(long double = 0.0L, long double = 0.0L);
1309 #if _GLIBCXX_BUGGY_COMPLEX
1310       complex(const complex& __z) : _M_value(__z._M_value) { }
1311 #endif
1312       complex(const complex<float>&);
1313       complex(const complex<double>&);
1314
1315       long double& real();
1316       const long double& real() const;
1317       long double& imag();
1318       const long double& imag() const;
1319
1320       complex<long double>& operator= (long double);
1321       complex<long double>& operator+= (long double);
1322       complex<long double>& operator-= (long double);
1323       complex<long double>& operator*= (long double);
1324       complex<long double>& operator/= (long double);
1325
1326       // The compiler knows how to do this efficiently
1327       // complex& operator= (const complex&);
1328       template<typename _Tp>
1329         complex<long double>& operator=(const complex<_Tp>&);
1330       template<typename _Tp>
1331         complex<long double>& operator+=(const complex<_Tp>&);
1332       template<typename _Tp>
1333         complex<long double>& operator-=(const complex<_Tp>&);
1334       template<typename _Tp>
1335         complex<long double>& operator*=(const complex<_Tp>&);
1336       template<typename _Tp>
1337         complex<long double>& operator/=(const complex<_Tp>&);
1338
1339       const _ComplexT& __rep() const { return _M_value; }
1340
1341     private:
1342       _ComplexT _M_value;
1343     };
1344
1345   inline
1346   complex<long double>::complex(long double __r, long double __i)
1347   {
1348     __real__ _M_value = __r;
1349     __imag__ _M_value = __i;
1350   }
1351
1352   inline long double&
1353   complex<long double>::real()
1354   { return __real__ _M_value; }
1355
1356   inline const long double&
1357   complex<long double>::real() const
1358   { return __real__ _M_value; }
1359
1360   inline long double&
1361   complex<long double>::imag()
1362   { return __imag__ _M_value; }
1363
1364   inline const long double&
1365   complex<long double>::imag() const
1366   { return __imag__ _M_value; }
1367
1368   inline complex<long double>&   
1369   complex<long double>::operator=(long double __r)
1370   {
1371     __real__ _M_value = __r;
1372     __imag__ _M_value = 0.0L;
1373     return *this;
1374   }
1375
1376   inline complex<long double>&
1377   complex<long double>::operator+=(long double __r)
1378   {
1379     __real__ _M_value += __r;
1380     return *this;
1381   }
1382
1383   inline complex<long double>&
1384   complex<long double>::operator-=(long double __r)
1385   {
1386     __real__ _M_value -= __r;
1387     return *this;
1388   }
1389
1390   inline complex<long double>&
1391   complex<long double>::operator*=(long double __r)
1392   {
1393     _M_value *= __r;
1394     return *this;
1395   }
1396
1397   inline complex<long double>&
1398   complex<long double>::operator/=(long double __r)
1399   {
1400     _M_value /= __r;
1401     return *this;
1402   }
1403
1404   template<typename _Tp>
1405     inline complex<long double>&
1406     complex<long double>::operator=(const complex<_Tp>& __z)
1407     {
1408       __real__ _M_value = __z.real();
1409       __imag__ _M_value = __z.imag();
1410       return *this;
1411     }
1412
1413   template<typename _Tp>
1414     inline complex<long double>&
1415     complex<long double>::operator+=(const complex<_Tp>& __z)
1416     {
1417       __real__ _M_value += __z.real();
1418       __imag__ _M_value += __z.imag();
1419       return *this;
1420     }
1421
1422   template<typename _Tp>
1423     inline complex<long double>&
1424     complex<long double>::operator-=(const complex<_Tp>& __z)
1425     {
1426       __real__ _M_value -= __z.real();
1427       __imag__ _M_value -= __z.imag();
1428       return *this;
1429     }
1430     
1431   template<typename _Tp>
1432     inline complex<long double>&
1433     complex<long double>::operator*=(const complex<_Tp>& __z)
1434     {
1435       _ComplexT __t;
1436       __real__ __t = __z.real();
1437       __imag__ __t = __z.imag();
1438       _M_value *= __t;
1439       return *this;
1440     }
1441
1442   template<typename _Tp>
1443     inline complex<long double>&
1444     complex<long double>::operator/=(const complex<_Tp>& __z)
1445     {
1446       _ComplexT __t;
1447       __real__ __t = __z.real();
1448       __imag__ __t = __z.imag();
1449       _M_value /= __t;
1450       return *this;
1451     }
1452
1453   // These bits have to be at the end of this file, so that the
1454   // specializations have all been defined.
1455   // ??? No, they have to be there because of compiler limitation at
1456   // inlining.  It suffices that class specializations be defined.
1457   inline
1458   complex<float>::complex(const complex<double>& __z)
1459   : _M_value(__z.__rep()) { }
1460
1461   inline
1462   complex<float>::complex(const complex<long double>& __z)
1463   : _M_value(__z.__rep()) { }
1464
1465   inline
1466   complex<double>::complex(const complex<float>& __z) 
1467   : _M_value(__z.__rep()) { }
1468
1469   inline
1470   complex<double>::complex(const complex<long double>& __z)
1471     : _M_value(__z.__rep()) { }
1472
1473   inline
1474   complex<long double>::complex(const complex<float>& __z)
1475   : _M_value(__z.__rep()) { }
1476
1477   inline
1478   complex<long double>::complex(const complex<double>& __z)
1479   : _M_value(__z.__rep()) { }
1480 } // namespace std
1481
1482 #endif  /* _GLIBCXX_COMPLEX */