OSDN Git Service

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