libstdc++
|
00001 // The template and inlines for the -*- C++ -*- complex number classes. 00002 00003 // Copyright (C) 1997-2019 Free Software Foundation, Inc. 00004 // 00005 // This file is part of the GNU ISO C++ Library. This library is free 00006 // software; you can redistribute it and/or modify it under the 00007 // terms of the GNU General Public License as published by the 00008 // Free Software Foundation; either version 3, or (at your option) 00009 // any later version. 00010 00011 // This library is distributed in the hope that it will be useful, 00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 // GNU General Public License for more details. 00015 00016 // Under Section 7 of GPL version 3, you are granted additional 00017 // permissions described in the GCC Runtime Library Exception, version 00018 // 3.1, as published by the Free Software Foundation. 00019 00020 // You should have received a copy of the GNU General Public License and 00021 // a copy of the GCC Runtime Library Exception along with this program; 00022 // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see 00023 // <http://www.gnu.org/licenses/>. 00024 00025 /** @file include/complex 00026 * This is a Standard C++ Library header. 00027 */ 00028 00029 // 00030 // ISO C++ 14882: 26.2 Complex Numbers 00031 // Note: this is not a conforming implementation. 00032 // Initially implemented by Ulrich Drepper <drepper@cygnus.com> 00033 // Improved by Gabriel Dos Reis <dosreis@cmla.ens-cachan.fr> 00034 // 00035 00036 #ifndef _GLIBCXX_COMPLEX 00037 #define _GLIBCXX_COMPLEX 1 00038 00039 #pragma GCC system_header 00040 00041 #include <bits/c++config.h> 00042 #include <bits/cpp_type_traits.h> 00043 #include <ext/type_traits.h> 00044 #include <cmath> 00045 #include <sstream> 00046 00047 // Get rid of a macro possibly defined in <complex.h> 00048 #undef complex 00049 00050 namespace std _GLIBCXX_VISIBILITY(default) 00051 { 00052 _GLIBCXX_BEGIN_NAMESPACE_VERSION 00053 00054 /** 00055 * @defgroup complex_numbers Complex Numbers 00056 * @ingroup numerics 00057 * 00058 * Classes and functions for complex numbers. 00059 * @{ 00060 */ 00061 00062 // Forward declarations. 00063 template<typename _Tp> class complex; 00064 template<> class complex<float>; 00065 template<> class complex<double>; 00066 template<> class complex<long double>; 00067 00068 /// Return magnitude of @a z. 00069 template<typename _Tp> _Tp abs(const complex<_Tp>&); 00070 /// Return phase angle of @a z. 00071 template<typename _Tp> _Tp arg(const complex<_Tp>&); 00072 /// Return @a z magnitude squared. 00073 template<typename _Tp> _Tp _GLIBCXX20_CONSTEXPR norm(const complex<_Tp>&); 00074 00075 /// Return complex conjugate of @a z. 00076 template<typename _Tp> 00077 _GLIBCXX20_CONSTEXPR complex<_Tp> conj(const complex<_Tp>&); 00078 /// Return complex with magnitude @a rho and angle @a theta. 00079 template<typename _Tp> complex<_Tp> polar(const _Tp&, const _Tp& = 0); 00080 00081 // Transcendentals: 00082 /// Return complex cosine of @a z. 00083 template<typename _Tp> complex<_Tp> cos(const complex<_Tp>&); 00084 /// Return complex hyperbolic cosine of @a z. 00085 template<typename _Tp> complex<_Tp> cosh(const complex<_Tp>&); 00086 /// Return complex base e exponential of @a z. 00087 template<typename _Tp> complex<_Tp> exp(const complex<_Tp>&); 00088 /// Return complex natural logarithm of @a z. 00089 template<typename _Tp> complex<_Tp> log(const complex<_Tp>&); 00090 /// Return complex base 10 logarithm of @a z. 00091 template<typename _Tp> complex<_Tp> log10(const complex<_Tp>&); 00092 /// Return @a x to the @a y'th power. 00093 template<typename _Tp> complex<_Tp> pow(const complex<_Tp>&, int); 00094 /// Return @a x to the @a y'th power. 00095 template<typename _Tp> complex<_Tp> pow(const complex<_Tp>&, const _Tp&); 00096 /// Return @a x to the @a y'th power. 00097 template<typename _Tp> complex<_Tp> pow(const complex<_Tp>&, 00098 const complex<_Tp>&); 00099 /// Return @a x to the @a y'th power. 00100 template<typename _Tp> complex<_Tp> pow(const _Tp&, const complex<_Tp>&); 00101 /// Return complex sine of @a z. 00102 template<typename _Tp> complex<_Tp> sin(const complex<_Tp>&); 00103 /// Return complex hyperbolic sine of @a z. 00104 template<typename _Tp> complex<_Tp> sinh(const complex<_Tp>&); 00105 /// Return complex square root of @a z. 00106 template<typename _Tp> complex<_Tp> sqrt(const complex<_Tp>&); 00107 /// Return complex tangent of @a z. 00108 template<typename _Tp> complex<_Tp> tan(const complex<_Tp>&); 00109 /// Return complex hyperbolic tangent of @a z. 00110 template<typename _Tp> complex<_Tp> tanh(const complex<_Tp>&); 00111 00112 00113 // 26.2.2 Primary template class complex 00114 /** 00115 * Template to represent complex numbers. 00116 * 00117 * Specializations for float, double, and long double are part of the 00118 * library. Results with any other type are not guaranteed. 00119 * 00120 * @param Tp Type of real and imaginary values. 00121 */ 00122 template<typename _Tp> 00123 struct complex 00124 { 00125 /// Value typedef. 00126 typedef _Tp value_type; 00127 00128 /// Default constructor. First parameter is x, second parameter is y. 00129 /// Unspecified parameters default to 0. 00130 _GLIBCXX_CONSTEXPR complex(const _Tp& __r = _Tp(), const _Tp& __i = _Tp()) 00131 : _M_real(__r), _M_imag(__i) { } 00132 00133 // Let the compiler synthesize the copy constructor 00134 #if __cplusplus >= 201103L 00135 constexpr complex(const complex&) = default; 00136 #endif 00137 00138 /// Converting constructor. 00139 template<typename _Up> 00140 _GLIBCXX_CONSTEXPR complex(const complex<_Up>& __z) 00141 : _M_real(__z.real()), _M_imag(__z.imag()) { } 00142 00143 #if __cplusplus >= 201103L 00144 // _GLIBCXX_RESOLVE_LIB_DEFECTS 00145 // DR 387. std::complex over-encapsulated. 00146 _GLIBCXX_ABI_TAG_CXX11 00147 constexpr _Tp 00148 real() const { return _M_real; } 00149 00150 _GLIBCXX_ABI_TAG_CXX11 00151 constexpr _Tp 00152 imag() const { return _M_imag; } 00153 #else 00154 /// Return real part of complex number. 00155 _Tp& 00156 real() { return _M_real; } 00157 00158 /// Return real part of complex number. 00159 const _Tp& 00160 real() const { return _M_real; } 00161 00162 /// Return imaginary part of complex number. 00163 _Tp& 00164 imag() { return _M_imag; } 00165 00166 /// Return imaginary part of complex number. 00167 const _Tp& 00168 imag() const { return _M_imag; } 00169 #endif 00170 00171 // _GLIBCXX_RESOLVE_LIB_DEFECTS 00172 // DR 387. std::complex over-encapsulated. 00173 _GLIBCXX20_CONSTEXPR void 00174 real(_Tp __val) { _M_real = __val; } 00175 00176 _GLIBCXX20_CONSTEXPR void 00177 imag(_Tp __val) { _M_imag = __val; } 00178 00179 /// Assign a scalar to this complex number. 00180 _GLIBCXX20_CONSTEXPR complex<_Tp>& operator=(const _Tp&); 00181 00182 /// Add a scalar to this complex number. 00183 // 26.2.5/1 00184 _GLIBCXX20_CONSTEXPR complex<_Tp>& 00185 operator+=(const _Tp& __t) 00186 { 00187 _M_real += __t; 00188 return *this; 00189 } 00190 00191 /// Subtract a scalar from this complex number. 00192 // 26.2.5/3 00193 _GLIBCXX20_CONSTEXPR complex<_Tp>& 00194 operator-=(const _Tp& __t) 00195 { 00196 _M_real -= __t; 00197 return *this; 00198 } 00199 00200 /// Multiply this complex number by a scalar. 00201 _GLIBCXX20_CONSTEXPR complex<_Tp>& operator*=(const _Tp&); 00202 /// Divide this complex number by a scalar. 00203 _GLIBCXX20_CONSTEXPR complex<_Tp>& operator/=(const _Tp&); 00204 00205 // Let the compiler synthesize the copy assignment operator 00206 #if __cplusplus >= 201103L 00207 _GLIBCXX20_CONSTEXPR complex& operator=(const complex&) = default; 00208 #endif 00209 00210 /// Assign another complex number to this one. 00211 template<typename _Up> 00212 _GLIBCXX20_CONSTEXPR complex<_Tp>& operator=(const complex<_Up>&); 00213 /// Add another complex number to this one. 00214 template<typename _Up> 00215 _GLIBCXX20_CONSTEXPR complex<_Tp>& operator+=(const complex<_Up>&); 00216 /// Subtract another complex number from this one. 00217 template<typename _Up> 00218 _GLIBCXX20_CONSTEXPR complex<_Tp>& operator-=(const complex<_Up>&); 00219 /// Multiply this complex number by another. 00220 template<typename _Up> 00221 _GLIBCXX20_CONSTEXPR complex<_Tp>& operator*=(const complex<_Up>&); 00222 /// Divide this complex number by another. 00223 template<typename _Up> 00224 _GLIBCXX20_CONSTEXPR complex<_Tp>& operator/=(const complex<_Up>&); 00225 00226 _GLIBCXX_CONSTEXPR complex __rep() const 00227 { return *this; } 00228 00229 private: 00230 _Tp _M_real; 00231 _Tp _M_imag; 00232 }; 00233 00234 template<typename _Tp> 00235 _GLIBCXX20_CONSTEXPR complex<_Tp>& 00236 complex<_Tp>::operator=(const _Tp& __t) 00237 { 00238 _M_real = __t; 00239 _M_imag = _Tp(); 00240 return *this; 00241 } 00242 00243 // 26.2.5/5 00244 template<typename _Tp> 00245 _GLIBCXX20_CONSTEXPR complex<_Tp>& 00246 complex<_Tp>::operator*=(const _Tp& __t) 00247 { 00248 _M_real *= __t; 00249 _M_imag *= __t; 00250 return *this; 00251 } 00252 00253 // 26.2.5/7 00254 template<typename _Tp> 00255 _GLIBCXX20_CONSTEXPR complex<_Tp>& 00256 complex<_Tp>::operator/=(const _Tp& __t) 00257 { 00258 _M_real /= __t; 00259 _M_imag /= __t; 00260 return *this; 00261 } 00262 00263 template<typename _Tp> 00264 template<typename _Up> 00265 _GLIBCXX20_CONSTEXPR complex<_Tp>& 00266 complex<_Tp>::operator=(const complex<_Up>& __z) 00267 { 00268 _M_real = __z.real(); 00269 _M_imag = __z.imag(); 00270 return *this; 00271 } 00272 00273 // 26.2.5/9 00274 template<typename _Tp> 00275 template<typename _Up> 00276 _GLIBCXX20_CONSTEXPR complex<_Tp>& 00277 complex<_Tp>::operator+=(const complex<_Up>& __z) 00278 { 00279 _M_real += __z.real(); 00280 _M_imag += __z.imag(); 00281 return *this; 00282 } 00283 00284 // 26.2.5/11 00285 template<typename _Tp> 00286 template<typename _Up> 00287 _GLIBCXX20_CONSTEXPR complex<_Tp>& 00288 complex<_Tp>::operator-=(const complex<_Up>& __z) 00289 { 00290 _M_real -= __z.real(); 00291 _M_imag -= __z.imag(); 00292 return *this; 00293 } 00294 00295 // 26.2.5/13 00296 // XXX: This is a grammar school implementation. 00297 template<typename _Tp> 00298 template<typename _Up> 00299 _GLIBCXX20_CONSTEXPR complex<_Tp>& 00300 complex<_Tp>::operator*=(const complex<_Up>& __z) 00301 { 00302 const _Tp __r = _M_real * __z.real() - _M_imag * __z.imag(); 00303 _M_imag = _M_real * __z.imag() + _M_imag * __z.real(); 00304 _M_real = __r; 00305 return *this; 00306 } 00307 00308 // 26.2.5/15 00309 // XXX: This is a grammar school implementation. 00310 template<typename _Tp> 00311 template<typename _Up> 00312 _GLIBCXX20_CONSTEXPR complex<_Tp>& 00313 complex<_Tp>::operator/=(const complex<_Up>& __z) 00314 { 00315 const _Tp __r = _M_real * __z.real() + _M_imag * __z.imag(); 00316 const _Tp __n = std::norm(__z); 00317 _M_imag = (_M_imag * __z.real() - _M_real * __z.imag()) / __n; 00318 _M_real = __r / __n; 00319 return *this; 00320 } 00321 00322 // Operators: 00323 //@{ 00324 /// Return new complex value @a x plus @a y. 00325 template<typename _Tp> 00326 inline _GLIBCXX20_CONSTEXPR complex<_Tp> 00327 operator+(const complex<_Tp>& __x, const complex<_Tp>& __y) 00328 { 00329 complex<_Tp> __r = __x; 00330 __r += __y; 00331 return __r; 00332 } 00333 00334 template<typename _Tp> 00335 inline _GLIBCXX20_CONSTEXPR complex<_Tp> 00336 operator+(const complex<_Tp>& __x, const _Tp& __y) 00337 { 00338 complex<_Tp> __r = __x; 00339 __r += __y; 00340 return __r; 00341 } 00342 00343 template<typename _Tp> 00344 inline _GLIBCXX20_CONSTEXPR complex<_Tp> 00345 operator+(const _Tp& __x, const complex<_Tp>& __y) 00346 { 00347 complex<_Tp> __r = __y; 00348 __r += __x; 00349 return __r; 00350 } 00351 //@} 00352 00353 //@{ 00354 /// Return new complex value @a x minus @a y. 00355 template<typename _Tp> 00356 inline _GLIBCXX20_CONSTEXPR complex<_Tp> 00357 operator-(const complex<_Tp>& __x, const complex<_Tp>& __y) 00358 { 00359 complex<_Tp> __r = __x; 00360 __r -= __y; 00361 return __r; 00362 } 00363 00364 template<typename _Tp> 00365 inline _GLIBCXX20_CONSTEXPR complex<_Tp> 00366 operator-(const complex<_Tp>& __x, const _Tp& __y) 00367 { 00368 complex<_Tp> __r = __x; 00369 __r -= __y; 00370 return __r; 00371 } 00372 00373 template<typename _Tp> 00374 inline _GLIBCXX20_CONSTEXPR complex<_Tp> 00375 operator-(const _Tp& __x, const complex<_Tp>& __y) 00376 { 00377 complex<_Tp> __r = -__y; 00378 __r += __x; 00379 return __r; 00380 } 00381 //@} 00382 00383 //@{ 00384 /// Return new complex value @a x times @a y. 00385 template<typename _Tp> 00386 inline _GLIBCXX20_CONSTEXPR complex<_Tp> 00387 operator*(const complex<_Tp>& __x, const complex<_Tp>& __y) 00388 { 00389 complex<_Tp> __r = __x; 00390 __r *= __y; 00391 return __r; 00392 } 00393 00394 template<typename _Tp> 00395 inline _GLIBCXX20_CONSTEXPR complex<_Tp> 00396 operator*(const complex<_Tp>& __x, const _Tp& __y) 00397 { 00398 complex<_Tp> __r = __x; 00399 __r *= __y; 00400 return __r; 00401 } 00402 00403 template<typename _Tp> 00404 inline _GLIBCXX20_CONSTEXPR complex<_Tp> 00405 operator*(const _Tp& __x, const complex<_Tp>& __y) 00406 { 00407 complex<_Tp> __r = __y; 00408 __r *= __x; 00409 return __r; 00410 } 00411 //@} 00412 00413 //@{ 00414 /// Return new complex value @a x divided by @a y. 00415 template<typename _Tp> 00416 inline _GLIBCXX20_CONSTEXPR complex<_Tp> 00417 operator/(const complex<_Tp>& __x, const complex<_Tp>& __y) 00418 { 00419 complex<_Tp> __r = __x; 00420 __r /= __y; 00421 return __r; 00422 } 00423 00424 template<typename _Tp> 00425 inline _GLIBCXX20_CONSTEXPR complex<_Tp> 00426 operator/(const complex<_Tp>& __x, const _Tp& __y) 00427 { 00428 complex<_Tp> __r = __x; 00429 __r /= __y; 00430 return __r; 00431 } 00432 00433 template<typename _Tp> 00434 inline _GLIBCXX20_CONSTEXPR complex<_Tp> 00435 operator/(const _Tp& __x, const complex<_Tp>& __y) 00436 { 00437 complex<_Tp> __r = __x; 00438 __r /= __y; 00439 return __r; 00440 } 00441 //@} 00442 00443 /// Return @a x. 00444 template<typename _Tp> 00445 inline _GLIBCXX20_CONSTEXPR complex<_Tp> 00446 operator+(const complex<_Tp>& __x) 00447 { return __x; } 00448 00449 /// Return complex negation of @a x. 00450 template<typename _Tp> 00451 inline _GLIBCXX20_CONSTEXPR complex<_Tp> 00452 operator-(const complex<_Tp>& __x) 00453 { return complex<_Tp>(-__x.real(), -__x.imag()); } 00454 00455 //@{ 00456 /// Return true if @a x is equal to @a y. 00457 template<typename _Tp> 00458 inline _GLIBCXX_CONSTEXPR bool 00459 operator==(const complex<_Tp>& __x, const complex<_Tp>& __y) 00460 { return __x.real() == __y.real() && __x.imag() == __y.imag(); } 00461 00462 template<typename _Tp> 00463 inline _GLIBCXX_CONSTEXPR bool 00464 operator==(const complex<_Tp>& __x, const _Tp& __y) 00465 { return __x.real() == __y && __x.imag() == _Tp(); } 00466 00467 template<typename _Tp> 00468 inline _GLIBCXX_CONSTEXPR bool 00469 operator==(const _Tp& __x, const complex<_Tp>& __y) 00470 { return __x == __y.real() && _Tp() == __y.imag(); } 00471 //@} 00472 00473 //@{ 00474 /// Return false if @a x is equal to @a y. 00475 template<typename _Tp> 00476 inline _GLIBCXX_CONSTEXPR bool 00477 operator!=(const complex<_Tp>& __x, const complex<_Tp>& __y) 00478 { return __x.real() != __y.real() || __x.imag() != __y.imag(); } 00479 00480 template<typename _Tp> 00481 inline _GLIBCXX_CONSTEXPR bool 00482 operator!=(const complex<_Tp>& __x, const _Tp& __y) 00483 { return __x.real() != __y || __x.imag() != _Tp(); } 00484 00485 template<typename _Tp> 00486 inline _GLIBCXX_CONSTEXPR bool 00487 operator!=(const _Tp& __x, const complex<_Tp>& __y) 00488 { return __x != __y.real() || _Tp() != __y.imag(); } 00489 //@} 00490 00491 /// Extraction operator for complex values. 00492 template<typename _Tp, typename _CharT, class _Traits> 00493 basic_istream<_CharT, _Traits>& 00494 operator>>(basic_istream<_CharT, _Traits>& __is, complex<_Tp>& __x) 00495 { 00496 bool __fail = true; 00497 _CharT __ch; 00498 if (__is >> __ch) 00499 { 00500 if (_Traits::eq(__ch, __is.widen('('))) 00501 { 00502 _Tp __u; 00503 if (__is >> __u >> __ch) 00504 { 00505 const _CharT __rparen = __is.widen(')'); 00506 if (_Traits::eq(__ch, __rparen)) 00507 { 00508 __x = __u; 00509 __fail = false; 00510 } 00511 else if (_Traits::eq(__ch, __is.widen(','))) 00512 { 00513 _Tp __v; 00514 if (__is >> __v >> __ch) 00515 { 00516 if (_Traits::eq(__ch, __rparen)) 00517 { 00518 __x = complex<_Tp>(__u, __v); 00519 __fail = false; 00520 } 00521 else 00522 __is.putback(__ch); 00523 } 00524 } 00525 else 00526 __is.putback(__ch); 00527 } 00528 } 00529 else 00530 { 00531 __is.putback(__ch); 00532 _Tp __u; 00533 if (__is >> __u) 00534 { 00535 __x = __u; 00536 __fail = false; 00537 } 00538 } 00539 } 00540 if (__fail) 00541 __is.setstate(ios_base::failbit); 00542 return __is; 00543 } 00544 00545 /// Insertion operator for complex values. 00546 template<typename _Tp, typename _CharT, class _Traits> 00547 basic_ostream<_CharT, _Traits>& 00548 operator<<(basic_ostream<_CharT, _Traits>& __os, const complex<_Tp>& __x) 00549 { 00550 basic_ostringstream<_CharT, _Traits> __s; 00551 __s.flags(__os.flags()); 00552 __s.imbue(__os.getloc()); 00553 __s.precision(__os.precision()); 00554 __s << '(' << __x.real() << ',' << __x.imag() << ')'; 00555 return __os << __s.str(); 00556 } 00557 00558 // Values 00559 #if __cplusplus >= 201103L 00560 template<typename _Tp> 00561 constexpr _Tp 00562 real(const complex<_Tp>& __z) 00563 { return __z.real(); } 00564 00565 template<typename _Tp> 00566 constexpr _Tp 00567 imag(const complex<_Tp>& __z) 00568 { return __z.imag(); } 00569 #else 00570 template<typename _Tp> 00571 inline _Tp& 00572 real(complex<_Tp>& __z) 00573 { return __z.real(); } 00574 00575 template<typename _Tp> 00576 inline const _Tp& 00577 real(const complex<_Tp>& __z) 00578 { return __z.real(); } 00579 00580 template<typename _Tp> 00581 inline _Tp& 00582 imag(complex<_Tp>& __z) 00583 { return __z.imag(); } 00584 00585 template<typename _Tp> 00586 inline const _Tp& 00587 imag(const complex<_Tp>& __z) 00588 { return __z.imag(); } 00589 #endif 00590 00591 // 26.2.7/3 abs(__z): Returns the magnitude of __z. 00592 template<typename _Tp> 00593 inline _Tp 00594 __complex_abs(const complex<_Tp>& __z) 00595 { 00596 _Tp __x = __z.real(); 00597 _Tp __y = __z.imag(); 00598 const _Tp __s = std::max(abs(__x), abs(__y)); 00599 if (__s == _Tp()) // well ... 00600 return __s; 00601 __x /= __s; 00602 __y /= __s; 00603 return __s * sqrt(__x * __x + __y * __y); 00604 } 00605 00606 #if _GLIBCXX_USE_C99_COMPLEX 00607 inline float 00608 __complex_abs(__complex__ float __z) { return __builtin_cabsf(__z); } 00609 00610 inline double 00611 __complex_abs(__complex__ double __z) { return __builtin_cabs(__z); } 00612 00613 inline long double 00614 __complex_abs(const __complex__ long double& __z) 00615 { return __builtin_cabsl(__z); } 00616 00617 template<typename _Tp> 00618 inline _Tp 00619 abs(const complex<_Tp>& __z) { return __complex_abs(__z.__rep()); } 00620 #else 00621 template<typename _Tp> 00622 inline _Tp 00623 abs(const complex<_Tp>& __z) { return __complex_abs(__z); } 00624 #endif 00625 00626 00627 // 26.2.7/4: arg(__z): Returns the phase angle of __z. 00628 template<typename _Tp> 00629 inline _Tp 00630 __complex_arg(const complex<_Tp>& __z) 00631 { return atan2(__z.imag(), __z.real()); } 00632 00633 #if _GLIBCXX_USE_C99_COMPLEX 00634 inline float 00635 __complex_arg(__complex__ float __z) { return __builtin_cargf(__z); } 00636 00637 inline double 00638 __complex_arg(__complex__ double __z) { return __builtin_carg(__z); } 00639 00640 inline long double 00641 __complex_arg(const __complex__ long double& __z) 00642 { return __builtin_cargl(__z); } 00643 00644 template<typename _Tp> 00645 inline _Tp 00646 arg(const complex<_Tp>& __z) { return __complex_arg(__z.__rep()); } 00647 #else 00648 template<typename _Tp> 00649 inline _Tp 00650 arg(const complex<_Tp>& __z) { return __complex_arg(__z); } 00651 #endif 00652 00653 // 26.2.7/5: norm(__z) returns the squared magnitude of __z. 00654 // As defined, norm() is -not- a norm is the common mathematical 00655 // sense used in numerics. The helper class _Norm_helper<> tries to 00656 // distinguish between builtin floating point and the rest, so as 00657 // to deliver an answer as close as possible to the real value. 00658 template<bool> 00659 struct _Norm_helper 00660 { 00661 template<typename _Tp> 00662 static inline _GLIBCXX20_CONSTEXPR _Tp _S_do_it(const complex<_Tp>& __z) 00663 { 00664 const _Tp __x = __z.real(); 00665 const _Tp __y = __z.imag(); 00666 return __x * __x + __y * __y; 00667 } 00668 }; 00669 00670 template<> 00671 struct _Norm_helper<true> 00672 { 00673 template<typename _Tp> 00674 static inline _GLIBCXX20_CONSTEXPR _Tp _S_do_it(const complex<_Tp>& __z) 00675 { 00676 //_Tp __res = std::abs(__z); 00677 //return __res * __res; 00678 const _Tp __x = __z.real(); 00679 const _Tp __y = __z.imag(); 00680 return __x * __x + __y * __y; 00681 } 00682 }; 00683 00684 template<typename _Tp> 00685 inline _GLIBCXX20_CONSTEXPR _Tp 00686 norm(const complex<_Tp>& __z) 00687 { 00688 return _Norm_helper<__is_floating<_Tp>::__value 00689 && !_GLIBCXX_FAST_MATH>::_S_do_it(__z); 00690 } 00691 00692 template<typename _Tp> 00693 inline complex<_Tp> 00694 polar(const _Tp& __rho, const _Tp& __theta) 00695 { 00696 __glibcxx_assert( __rho >= 0 ); 00697 return complex<_Tp>(__rho * cos(__theta), __rho * sin(__theta)); 00698 } 00699 00700 template<typename _Tp> 00701 inline _GLIBCXX20_CONSTEXPR complex<_Tp> 00702 conj(const complex<_Tp>& __z) 00703 { return complex<_Tp>(__z.real(), -__z.imag()); } 00704 00705 // Transcendentals 00706 00707 // 26.2.8/1 cos(__z): Returns the cosine of __z. 00708 template<typename _Tp> 00709 inline complex<_Tp> 00710 __complex_cos(const complex<_Tp>& __z) 00711 { 00712 const _Tp __x = __z.real(); 00713 const _Tp __y = __z.imag(); 00714 return complex<_Tp>(cos(__x) * cosh(__y), -sin(__x) * sinh(__y)); 00715 } 00716 00717 #if _GLIBCXX_USE_C99_COMPLEX 00718 inline __complex__ float 00719 __complex_cos(__complex__ float __z) { return __builtin_ccosf(__z); } 00720 00721 inline __complex__ double 00722 __complex_cos(__complex__ double __z) { return __builtin_ccos(__z); } 00723 00724 inline __complex__ long double 00725 __complex_cos(const __complex__ long double& __z) 00726 { return __builtin_ccosl(__z); } 00727 00728 template<typename _Tp> 00729 inline complex<_Tp> 00730 cos(const complex<_Tp>& __z) { return __complex_cos(__z.__rep()); } 00731 #else 00732 template<typename _Tp> 00733 inline complex<_Tp> 00734 cos(const complex<_Tp>& __z) { return __complex_cos(__z); } 00735 #endif 00736 00737 // 26.2.8/2 cosh(__z): Returns the hyperbolic cosine of __z. 00738 template<typename _Tp> 00739 inline complex<_Tp> 00740 __complex_cosh(const complex<_Tp>& __z) 00741 { 00742 const _Tp __x = __z.real(); 00743 const _Tp __y = __z.imag(); 00744 return complex<_Tp>(cosh(__x) * cos(__y), sinh(__x) * sin(__y)); 00745 } 00746 00747 #if _GLIBCXX_USE_C99_COMPLEX 00748 inline __complex__ float 00749 __complex_cosh(__complex__ float __z) { return __builtin_ccoshf(__z); } 00750 00751 inline __complex__ double 00752 __complex_cosh(__complex__ double __z) { return __builtin_ccosh(__z); } 00753 00754 inline __complex__ long double 00755 __complex_cosh(const __complex__ long double& __z) 00756 { return __builtin_ccoshl(__z); } 00757 00758 template<typename _Tp> 00759 inline complex<_Tp> 00760 cosh(const complex<_Tp>& __z) { return __complex_cosh(__z.__rep()); } 00761 #else 00762 template<typename _Tp> 00763 inline complex<_Tp> 00764 cosh(const complex<_Tp>& __z) { return __complex_cosh(__z); } 00765 #endif 00766 00767 // 26.2.8/3 exp(__z): Returns the complex base e exponential of x 00768 template<typename _Tp> 00769 inline complex<_Tp> 00770 __complex_exp(const complex<_Tp>& __z) 00771 { return std::polar<_Tp>(exp(__z.real()), __z.imag()); } 00772 00773 #if _GLIBCXX_USE_C99_COMPLEX 00774 inline __complex__ float 00775 __complex_exp(__complex__ float __z) { return __builtin_cexpf(__z); } 00776 00777 inline __complex__ double 00778 __complex_exp(__complex__ double __z) { return __builtin_cexp(__z); } 00779 00780 inline __complex__ long double 00781 __complex_exp(const __complex__ long double& __z) 00782 { return __builtin_cexpl(__z); } 00783 00784 template<typename _Tp> 00785 inline complex<_Tp> 00786 exp(const complex<_Tp>& __z) { return __complex_exp(__z.__rep()); } 00787 #else 00788 template<typename _Tp> 00789 inline complex<_Tp> 00790 exp(const complex<_Tp>& __z) { return __complex_exp(__z); } 00791 #endif 00792 00793 // 26.2.8/5 log(__z): Returns the natural complex logarithm of __z. 00794 // The branch cut is along the negative axis. 00795 template<typename _Tp> 00796 inline complex<_Tp> 00797 __complex_log(const complex<_Tp>& __z) 00798 { return complex<_Tp>(log(std::abs(__z)), std::arg(__z)); } 00799 00800 #if _GLIBCXX_USE_C99_COMPLEX 00801 inline __complex__ float 00802 __complex_log(__complex__ float __z) { return __builtin_clogf(__z); } 00803 00804 inline __complex__ double 00805 __complex_log(__complex__ double __z) { return __builtin_clog(__z); } 00806 00807 inline __complex__ long double 00808 __complex_log(const __complex__ long double& __z) 00809 { return __builtin_clogl(__z); } 00810 00811 template<typename _Tp> 00812 inline complex<_Tp> 00813 log(const complex<_Tp>& __z) { return __complex_log(__z.__rep()); } 00814 #else 00815 template<typename _Tp> 00816 inline complex<_Tp> 00817 log(const complex<_Tp>& __z) { return __complex_log(__z); } 00818 #endif 00819 00820 template<typename _Tp> 00821 inline complex<_Tp> 00822 log10(const complex<_Tp>& __z) 00823 { return std::log(__z) / log(_Tp(10.0)); } 00824 00825 // 26.2.8/10 sin(__z): Returns the sine of __z. 00826 template<typename _Tp> 00827 inline complex<_Tp> 00828 __complex_sin(const complex<_Tp>& __z) 00829 { 00830 const _Tp __x = __z.real(); 00831 const _Tp __y = __z.imag(); 00832 return complex<_Tp>(sin(__x) * cosh(__y), cos(__x) * sinh(__y)); 00833 } 00834 00835 #if _GLIBCXX_USE_C99_COMPLEX 00836 inline __complex__ float 00837 __complex_sin(__complex__ float __z) { return __builtin_csinf(__z); } 00838 00839 inline __complex__ double 00840 __complex_sin(__complex__ double __z) { return __builtin_csin(__z); } 00841 00842 inline __complex__ long double 00843 __complex_sin(const __complex__ long double& __z) 00844 { return __builtin_csinl(__z); } 00845 00846 template<typename _Tp> 00847 inline complex<_Tp> 00848 sin(const complex<_Tp>& __z) { return __complex_sin(__z.__rep()); } 00849 #else 00850 template<typename _Tp> 00851 inline complex<_Tp> 00852 sin(const complex<_Tp>& __z) { return __complex_sin(__z); } 00853 #endif 00854 00855 // 26.2.8/11 sinh(__z): Returns the hyperbolic sine of __z. 00856 template<typename _Tp> 00857 inline complex<_Tp> 00858 __complex_sinh(const complex<_Tp>& __z) 00859 { 00860 const _Tp __x = __z.real(); 00861 const _Tp __y = __z.imag(); 00862 return complex<_Tp>(sinh(__x) * cos(__y), cosh(__x) * sin(__y)); 00863 } 00864 00865 #if _GLIBCXX_USE_C99_COMPLEX 00866 inline __complex__ float 00867 __complex_sinh(__complex__ float __z) { return __builtin_csinhf(__z); } 00868 00869 inline __complex__ double 00870 __complex_sinh(__complex__ double __z) { return __builtin_csinh(__z); } 00871 00872 inline __complex__ long double 00873 __complex_sinh(const __complex__ long double& __z) 00874 { return __builtin_csinhl(__z); } 00875 00876 template<typename _Tp> 00877 inline complex<_Tp> 00878 sinh(const complex<_Tp>& __z) { return __complex_sinh(__z.__rep()); } 00879 #else 00880 template<typename _Tp> 00881 inline complex<_Tp> 00882 sinh(const complex<_Tp>& __z) { return __complex_sinh(__z); } 00883 #endif 00884 00885 // 26.2.8/13 sqrt(__z): Returns the complex square root of __z. 00886 // The branch cut is on the negative axis. 00887 template<typename _Tp> 00888 complex<_Tp> 00889 __complex_sqrt(const complex<_Tp>& __z) 00890 { 00891 _Tp __x = __z.real(); 00892 _Tp __y = __z.imag(); 00893 00894 if (__x == _Tp()) 00895 { 00896 _Tp __t = sqrt(abs(__y) / 2); 00897 return complex<_Tp>(__t, __y < _Tp() ? -__t : __t); 00898 } 00899 else 00900 { 00901 _Tp __t = sqrt(2 * (std::abs(__z) + abs(__x))); 00902 _Tp __u = __t / 2; 00903 return __x > _Tp() 00904 ? complex<_Tp>(__u, __y / __t) 00905 : complex<_Tp>(abs(__y) / __t, __y < _Tp() ? -__u : __u); 00906 } 00907 } 00908 00909 #if _GLIBCXX_USE_C99_COMPLEX 00910 inline __complex__ float 00911 __complex_sqrt(__complex__ float __z) { return __builtin_csqrtf(__z); } 00912 00913 inline __complex__ double 00914 __complex_sqrt(__complex__ double __z) { return __builtin_csqrt(__z); } 00915 00916 inline __complex__ long double 00917 __complex_sqrt(const __complex__ long double& __z) 00918 { return __builtin_csqrtl(__z); } 00919 00920 template<typename _Tp> 00921 inline complex<_Tp> 00922 sqrt(const complex<_Tp>& __z) { return __complex_sqrt(__z.__rep()); } 00923 #else 00924 template<typename _Tp> 00925 inline complex<_Tp> 00926 sqrt(const complex<_Tp>& __z) { return __complex_sqrt(__z); } 00927 #endif 00928 00929 // 26.2.8/14 tan(__z): Return the complex tangent of __z. 00930 00931 template<typename _Tp> 00932 inline complex<_Tp> 00933 __complex_tan(const complex<_Tp>& __z) 00934 { return std::sin(__z) / std::cos(__z); } 00935 00936 #if _GLIBCXX_USE_C99_COMPLEX 00937 inline __complex__ float 00938 __complex_tan(__complex__ float __z) { return __builtin_ctanf(__z); } 00939 00940 inline __complex__ double 00941 __complex_tan(__complex__ double __z) { return __builtin_ctan(__z); } 00942 00943 inline __complex__ long double 00944 __complex_tan(const __complex__ long double& __z) 00945 { return __builtin_ctanl(__z); } 00946 00947 template<typename _Tp> 00948 inline complex<_Tp> 00949 tan(const complex<_Tp>& __z) { return __complex_tan(__z.__rep()); } 00950 #else 00951 template<typename _Tp> 00952 inline complex<_Tp> 00953 tan(const complex<_Tp>& __z) { return __complex_tan(__z); } 00954 #endif 00955 00956 00957 // 26.2.8/15 tanh(__z): Returns the hyperbolic tangent of __z. 00958 00959 template<typename _Tp> 00960 inline complex<_Tp> 00961 __complex_tanh(const complex<_Tp>& __z) 00962 { return std::sinh(__z) / std::cosh(__z); } 00963 00964 #if _GLIBCXX_USE_C99_COMPLEX 00965 inline __complex__ float 00966 __complex_tanh(__complex__ float __z) { return __builtin_ctanhf(__z); } 00967 00968 inline __complex__ double 00969 __complex_tanh(__complex__ double __z) { return __builtin_ctanh(__z); } 00970 00971 inline __complex__ long double 00972 __complex_tanh(const __complex__ long double& __z) 00973 { return __builtin_ctanhl(__z); } 00974 00975 template<typename _Tp> 00976 inline complex<_Tp> 00977 tanh(const complex<_Tp>& __z) { return __complex_tanh(__z.__rep()); } 00978 #else 00979 template<typename _Tp> 00980 inline complex<_Tp> 00981 tanh(const complex<_Tp>& __z) { return __complex_tanh(__z); } 00982 #endif 00983 00984 00985 // 26.2.8/9 pow(__x, __y): Returns the complex power base of __x 00986 // raised to the __y-th power. The branch 00987 // cut is on the negative axis. 00988 template<typename _Tp> 00989 complex<_Tp> 00990 __complex_pow_unsigned(complex<_Tp> __x, unsigned __n) 00991 { 00992 complex<_Tp> __y = __n % 2 ? __x : complex<_Tp>(1); 00993 00994 while (__n >>= 1) 00995 { 00996 __x *= __x; 00997 if (__n % 2) 00998 __y *= __x; 00999 } 01000 01001 return __y; 01002 } 01003 01004 // In C++11 mode we used to implement the resolution of 01005 // DR 844. complex pow return type is ambiguous. 01006 // thus the following overload was disabled in that mode. However, doing 01007 // that causes all sorts of issues, see, for example: 01008 // http://gcc.gnu.org/ml/libstdc++/2013-01/msg00058.html 01009 // and also PR57974. 01010 template<typename _Tp> 01011 inline complex<_Tp> 01012 pow(const complex<_Tp>& __z, int __n) 01013 { 01014 return __n < 0 01015 ? complex<_Tp>(1) / std::__complex_pow_unsigned(__z, -(unsigned)__n) 01016 : std::__complex_pow_unsigned(__z, __n); 01017 } 01018 01019 template<typename _Tp> 01020 complex<_Tp> 01021 pow(const complex<_Tp>& __x, const _Tp& __y) 01022 { 01023 #if ! _GLIBCXX_USE_C99_COMPLEX 01024 if (__x == _Tp()) 01025 return _Tp(); 01026 #endif 01027 if (__x.imag() == _Tp() && __x.real() > _Tp()) 01028 return pow(__x.real(), __y); 01029 01030 complex<_Tp> __t = std::log(__x); 01031 return std::polar<_Tp>(exp(__y * __t.real()), __y * __t.imag()); 01032 } 01033 01034 template<typename _Tp> 01035 inline complex<_Tp> 01036 __complex_pow(const complex<_Tp>& __x, const complex<_Tp>& __y) 01037 { return __x == _Tp() ? _Tp() : std::exp(__y * std::log(__x)); } 01038 01039 #if _GLIBCXX_USE_C99_COMPLEX 01040 inline __complex__ float 01041 __complex_pow(__complex__ float __x, __complex__ float __y) 01042 { return __builtin_cpowf(__x, __y); } 01043 01044 inline __complex__ double 01045 __complex_pow(__complex__ double __x, __complex__ double __y) 01046 { return __builtin_cpow(__x, __y); } 01047 01048 inline __complex__ long double 01049 __complex_pow(const __complex__ long double& __x, 01050 const __complex__ long double& __y) 01051 { return __builtin_cpowl(__x, __y); } 01052 01053 template<typename _Tp> 01054 inline complex<_Tp> 01055 pow(const complex<_Tp>& __x, const complex<_Tp>& __y) 01056 { return __complex_pow(__x.__rep(), __y.__rep()); } 01057 #else 01058 template<typename _Tp> 01059 inline complex<_Tp> 01060 pow(const complex<_Tp>& __x, const complex<_Tp>& __y) 01061 { return __complex_pow(__x, __y); } 01062 #endif 01063 01064 template<typename _Tp> 01065 inline complex<_Tp> 01066 pow(const _Tp& __x, const complex<_Tp>& __y) 01067 { 01068 return __x > _Tp() ? std::polar<_Tp>(pow(__x, __y.real()), 01069 __y.imag() * log(__x)) 01070 : std::pow(complex<_Tp>(__x), __y); 01071 } 01072 01073 /// 26.2.3 complex specializations 01074 /// complex<float> specialization 01075 template<> 01076 struct complex<float> 01077 { 01078 typedef float value_type; 01079 typedef __complex__ float _ComplexT; 01080 01081 _GLIBCXX_CONSTEXPR complex(_ComplexT __z) : _M_value(__z) { } 01082 01083 _GLIBCXX_CONSTEXPR complex(float __r = 0.0f, float __i = 0.0f) 01084 #if __cplusplus >= 201103L 01085 : _M_value{ __r, __i } { } 01086 #else 01087 { 01088 __real__ _M_value = __r; 01089 __imag__ _M_value = __i; 01090 } 01091 #endif 01092 01093 explicit _GLIBCXX_CONSTEXPR complex(const complex<double>&); 01094 explicit _GLIBCXX_CONSTEXPR complex(const complex<long double>&); 01095 01096 #if __cplusplus >= 201103L 01097 // _GLIBCXX_RESOLVE_LIB_DEFECTS 01098 // DR 387. std::complex over-encapsulated. 01099 __attribute ((__abi_tag__ ("cxx11"))) 01100 constexpr float 01101 real() const { return __real__ _M_value; } 01102 01103 __attribute ((__abi_tag__ ("cxx11"))) 01104 constexpr float 01105 imag() const { return __imag__ _M_value; } 01106 #else 01107 float& 01108 real() { return __real__ _M_value; } 01109 01110 const float& 01111 real() const { return __real__ _M_value; } 01112 01113 float& 01114 imag() { return __imag__ _M_value; } 01115 01116 const float& 01117 imag() const { return __imag__ _M_value; } 01118 #endif 01119 01120 // _GLIBCXX_RESOLVE_LIB_DEFECTS 01121 // DR 387. std::complex over-encapsulated. 01122 _GLIBCXX20_CONSTEXPR void 01123 real(float __val) { __real__ _M_value = __val; } 01124 01125 _GLIBCXX20_CONSTEXPR void 01126 imag(float __val) { __imag__ _M_value = __val; } 01127 01128 _GLIBCXX20_CONSTEXPR complex& 01129 operator=(float __f) 01130 { 01131 _M_value = __f; 01132 return *this; 01133 } 01134 01135 _GLIBCXX20_CONSTEXPR complex& 01136 operator+=(float __f) 01137 { 01138 _M_value += __f; 01139 return *this; 01140 } 01141 01142 _GLIBCXX20_CONSTEXPR complex& 01143 operator-=(float __f) 01144 { 01145 _M_value -= __f; 01146 return *this; 01147 } 01148 01149 _GLIBCXX20_CONSTEXPR complex& 01150 operator*=(float __f) 01151 { 01152 _M_value *= __f; 01153 return *this; 01154 } 01155 01156 _GLIBCXX20_CONSTEXPR complex& 01157 operator/=(float __f) 01158 { 01159 _M_value /= __f; 01160 return *this; 01161 } 01162 01163 // Let the compiler synthesize the copy and assignment 01164 // operator. It always does a pretty good job. 01165 #if __cplusplus >= 201103L 01166 _GLIBCXX14_CONSTEXPR complex& operator=(const complex&) = default; 01167 #endif 01168 01169 template<typename _Tp> 01170 _GLIBCXX20_CONSTEXPR complex& 01171 operator=(const complex<_Tp>& __z) 01172 { 01173 __real__ _M_value = __z.real(); 01174 __imag__ _M_value = __z.imag(); 01175 return *this; 01176 } 01177 01178 template<typename _Tp> 01179 _GLIBCXX20_CONSTEXPR complex& 01180 operator+=(const complex<_Tp>& __z) 01181 { 01182 _M_value += __z.__rep(); 01183 return *this; 01184 } 01185 01186 template<class _Tp> 01187 _GLIBCXX20_CONSTEXPR complex& 01188 operator-=(const complex<_Tp>& __z) 01189 { 01190 _M_value -= __z.__rep(); 01191 return *this; 01192 } 01193 01194 template<class _Tp> 01195 _GLIBCXX20_CONSTEXPR complex& 01196 operator*=(const complex<_Tp>& __z) 01197 { 01198 const _ComplexT __t = __z.__rep(); 01199 _M_value *= __t; 01200 return *this; 01201 } 01202 01203 template<class _Tp> 01204 _GLIBCXX20_CONSTEXPR complex& 01205 operator/=(const complex<_Tp>& __z) 01206 { 01207 const _ComplexT __t = __z.__rep(); 01208 _M_value /= __t; 01209 return *this; 01210 } 01211 01212 _GLIBCXX_CONSTEXPR _ComplexT __rep() const { return _M_value; } 01213 01214 private: 01215 _ComplexT _M_value; 01216 }; 01217 01218 /// 26.2.3 complex specializations 01219 /// complex<double> specialization 01220 template<> 01221 struct complex<double> 01222 { 01223 typedef double value_type; 01224 typedef __complex__ double _ComplexT; 01225 01226 _GLIBCXX_CONSTEXPR complex(_ComplexT __z) : _M_value(__z) { } 01227 01228 _GLIBCXX_CONSTEXPR complex(double __r = 0.0, double __i = 0.0) 01229 #if __cplusplus >= 201103L 01230 : _M_value{ __r, __i } { } 01231 #else 01232 { 01233 __real__ _M_value = __r; 01234 __imag__ _M_value = __i; 01235 } 01236 #endif 01237 01238 _GLIBCXX_CONSTEXPR complex(const complex<float>& __z) 01239 : _M_value(__z.__rep()) { } 01240 01241 explicit _GLIBCXX_CONSTEXPR complex(const complex<long double>&); 01242 01243 #if __cplusplus >= 201103L 01244 // _GLIBCXX_RESOLVE_LIB_DEFECTS 01245 // DR 387. std::complex over-encapsulated. 01246 __attribute ((__abi_tag__ ("cxx11"))) 01247 constexpr double 01248 real() const { return __real__ _M_value; } 01249 01250 __attribute ((__abi_tag__ ("cxx11"))) 01251 constexpr double 01252 imag() const { return __imag__ _M_value; } 01253 #else 01254 double& 01255 real() { return __real__ _M_value; } 01256 01257 const double& 01258 real() const { return __real__ _M_value; } 01259 01260 double& 01261 imag() { return __imag__ _M_value; } 01262 01263 const double& 01264 imag() const { return __imag__ _M_value; } 01265 #endif 01266 01267 // _GLIBCXX_RESOLVE_LIB_DEFECTS 01268 // DR 387. std::complex over-encapsulated. 01269 _GLIBCXX20_CONSTEXPR void 01270 real(double __val) { __real__ _M_value = __val; } 01271 01272 _GLIBCXX20_CONSTEXPR void 01273 imag(double __val) { __imag__ _M_value = __val; } 01274 01275 _GLIBCXX20_CONSTEXPR complex& 01276 operator=(double __d) 01277 { 01278 _M_value = __d; 01279 return *this; 01280 } 01281 01282 _GLIBCXX20_CONSTEXPR complex& 01283 operator+=(double __d) 01284 { 01285 _M_value += __d; 01286 return *this; 01287 } 01288 01289 _GLIBCXX20_CONSTEXPR complex& 01290 operator-=(double __d) 01291 { 01292 _M_value -= __d; 01293 return *this; 01294 } 01295 01296 _GLIBCXX20_CONSTEXPR complex& 01297 operator*=(double __d) 01298 { 01299 _M_value *= __d; 01300 return *this; 01301 } 01302 01303 _GLIBCXX20_CONSTEXPR complex& 01304 operator/=(double __d) 01305 { 01306 _M_value /= __d; 01307 return *this; 01308 } 01309 01310 // The compiler will synthesize this, efficiently. 01311 #if __cplusplus >= 201103L 01312 _GLIBCXX14_CONSTEXPR complex& operator=(const complex&) = default; 01313 #endif 01314 01315 template<typename _Tp> 01316 _GLIBCXX20_CONSTEXPR complex& 01317 operator=(const complex<_Tp>& __z) 01318 { 01319 _M_value = __z.__rep(); 01320 return *this; 01321 } 01322 01323 template<typename _Tp> 01324 _GLIBCXX20_CONSTEXPR complex& 01325 operator+=(const complex<_Tp>& __z) 01326 { 01327 _M_value += __z.__rep(); 01328 return *this; 01329 } 01330 01331 template<typename _Tp> 01332 _GLIBCXX20_CONSTEXPR complex& 01333 operator-=(const complex<_Tp>& __z) 01334 { 01335 _M_value -= __z.__rep(); 01336 return *this; 01337 } 01338 01339 template<typename _Tp> 01340 _GLIBCXX20_CONSTEXPR complex& 01341 operator*=(const complex<_Tp>& __z) 01342 { 01343 const _ComplexT __t = __z.__rep(); 01344 _M_value *= __t; 01345 return *this; 01346 } 01347 01348 template<typename _Tp> 01349 _GLIBCXX20_CONSTEXPR complex& 01350 operator/=(const complex<_Tp>& __z) 01351 { 01352 const _ComplexT __t = __z.__rep(); 01353 _M_value /= __t; 01354 return *this; 01355 } 01356 01357 _GLIBCXX_CONSTEXPR _ComplexT __rep() const { return _M_value; } 01358 01359 private: 01360 _ComplexT _M_value; 01361 }; 01362 01363 /// 26.2.3 complex specializations 01364 /// complex<long double> specialization 01365 template<> 01366 struct complex<long double> 01367 { 01368 typedef long double value_type; 01369 typedef __complex__ long double _ComplexT; 01370 01371 _GLIBCXX_CONSTEXPR complex(_ComplexT __z) : _M_value(__z) { } 01372 01373 _GLIBCXX_CONSTEXPR complex(long double __r = 0.0L, 01374 long double __i = 0.0L) 01375 #if __cplusplus >= 201103L 01376 : _M_value{ __r, __i } { } 01377 #else 01378 { 01379 __real__ _M_value = __r; 01380 __imag__ _M_value = __i; 01381 } 01382 #endif 01383 01384 _GLIBCXX_CONSTEXPR complex(const complex<float>& __z) 01385 : _M_value(__z.__rep()) { } 01386 01387 _GLIBCXX_CONSTEXPR complex(const complex<double>& __z) 01388 : _M_value(__z.__rep()) { } 01389 01390 #if __cplusplus >= 201103L 01391 // _GLIBCXX_RESOLVE_LIB_DEFECTS 01392 // DR 387. std::complex over-encapsulated. 01393 __attribute ((__abi_tag__ ("cxx11"))) 01394 constexpr long double 01395 real() const { return __real__ _M_value; } 01396 01397 __attribute ((__abi_tag__ ("cxx11"))) 01398 constexpr long double 01399 imag() const { return __imag__ _M_value; } 01400 #else 01401 long double& 01402 real() { return __real__ _M_value; } 01403 01404 const long double& 01405 real() const { return __real__ _M_value; } 01406 01407 long double& 01408 imag() { return __imag__ _M_value; } 01409 01410 const long double& 01411 imag() const { return __imag__ _M_value; } 01412 #endif 01413 01414 // _GLIBCXX_RESOLVE_LIB_DEFECTS 01415 // DR 387. std::complex over-encapsulated. 01416 _GLIBCXX20_CONSTEXPR void 01417 real(long double __val) { __real__ _M_value = __val; } 01418 01419 _GLIBCXX20_CONSTEXPR void 01420 imag(long double __val) { __imag__ _M_value = __val; } 01421 01422 _GLIBCXX20_CONSTEXPR complex& 01423 operator=(long double __r) 01424 { 01425 _M_value = __r; 01426 return *this; 01427 } 01428 01429 _GLIBCXX20_CONSTEXPR complex& 01430 operator+=(long double __r) 01431 { 01432 _M_value += __r; 01433 return *this; 01434 } 01435 01436 _GLIBCXX20_CONSTEXPR complex& 01437 operator-=(long double __r) 01438 { 01439 _M_value -= __r; 01440 return *this; 01441 } 01442 01443 _GLIBCXX20_CONSTEXPR complex& 01444 operator*=(long double __r) 01445 { 01446 _M_value *= __r; 01447 return *this; 01448 } 01449 01450 _GLIBCXX20_CONSTEXPR complex& 01451 operator/=(long double __r) 01452 { 01453 _M_value /= __r; 01454 return *this; 01455 } 01456 01457 // The compiler knows how to do this efficiently 01458 #if __cplusplus >= 201103L 01459 _GLIBCXX14_CONSTEXPR complex& operator=(const complex&) = default; 01460 #endif 01461 01462 template<typename _Tp> 01463 _GLIBCXX20_CONSTEXPR complex& 01464 operator=(const complex<_Tp>& __z) 01465 { 01466 _M_value = __z.__rep(); 01467 return *this; 01468 } 01469 01470 template<typename _Tp> 01471 _GLIBCXX20_CONSTEXPR complex& 01472 operator+=(const complex<_Tp>& __z) 01473 { 01474 _M_value += __z.__rep(); 01475 return *this; 01476 } 01477 01478 template<typename _Tp> 01479 _GLIBCXX20_CONSTEXPR complex& 01480 operator-=(const complex<_Tp>& __z) 01481 { 01482 _M_value -= __z.__rep(); 01483 return *this; 01484 } 01485 01486 template<typename _Tp> 01487 _GLIBCXX20_CONSTEXPR complex& 01488 operator*=(const complex<_Tp>& __z) 01489 { 01490 const _ComplexT __t = __z.__rep(); 01491 _M_value *= __t; 01492 return *this; 01493 } 01494 01495 template<typename _Tp> 01496 _GLIBCXX20_CONSTEXPR complex& 01497 operator/=(const complex<_Tp>& __z) 01498 { 01499 const _ComplexT __t = __z.__rep(); 01500 _M_value /= __t; 01501 return *this; 01502 } 01503 01504 _GLIBCXX_CONSTEXPR _ComplexT __rep() const { return _M_value; } 01505 01506 private: 01507 _ComplexT _M_value; 01508 }; 01509 01510 // These bits have to be at the end of this file, so that the 01511 // specializations have all been defined. 01512 inline _GLIBCXX_CONSTEXPR 01513 complex<float>::complex(const complex<double>& __z) 01514 : _M_value(__z.__rep()) { } 01515 01516 inline _GLIBCXX_CONSTEXPR 01517 complex<float>::complex(const complex<long double>& __z) 01518 : _M_value(__z.__rep()) { } 01519 01520 inline _GLIBCXX_CONSTEXPR 01521 complex<double>::complex(const complex<long double>& __z) 01522 : _M_value(__z.__rep()) { } 01523 01524 // Inhibit implicit instantiations for required instantiations, 01525 // which are defined via explicit instantiations elsewhere. 01526 // NB: This syntax is a GNU extension. 01527 #if _GLIBCXX_EXTERN_TEMPLATE 01528 extern template istream& operator>>(istream&, complex<float>&); 01529 extern template ostream& operator<<(ostream&, const complex<float>&); 01530 extern template istream& operator>>(istream&, complex<double>&); 01531 extern template ostream& operator<<(ostream&, const complex<double>&); 01532 extern template istream& operator>>(istream&, complex<long double>&); 01533 extern template ostream& operator<<(ostream&, const complex<long double>&); 01534 01535 #ifdef _GLIBCXX_USE_WCHAR_T 01536 extern template wistream& operator>>(wistream&, complex<float>&); 01537 extern template wostream& operator<<(wostream&, const complex<float>&); 01538 extern template wistream& operator>>(wistream&, complex<double>&); 01539 extern template wostream& operator<<(wostream&, const complex<double>&); 01540 extern template wistream& operator>>(wistream&, complex<long double>&); 01541 extern template wostream& operator<<(wostream&, const complex<long double>&); 01542 #endif 01543 #endif 01544 01545 // @} group complex_numbers 01546 01547 _GLIBCXX_END_NAMESPACE_VERSION 01548 } // namespace 01549 01550 namespace __gnu_cxx _GLIBCXX_VISIBILITY(default) 01551 { 01552 _GLIBCXX_BEGIN_NAMESPACE_VERSION 01553 01554 // See ext/type_traits.h for the primary template. 01555 template<typename _Tp, typename _Up> 01556 struct __promote_2<std::complex<_Tp>, _Up> 01557 { 01558 public: 01559 typedef std::complex<typename __promote_2<_Tp, _Up>::__type> __type; 01560 }; 01561 01562 template<typename _Tp, typename _Up> 01563 struct __promote_2<_Tp, std::complex<_Up> > 01564 { 01565 public: 01566 typedef std::complex<typename __promote_2<_Tp, _Up>::__type> __type; 01567 }; 01568 01569 template<typename _Tp, typename _Up> 01570 struct __promote_2<std::complex<_Tp>, std::complex<_Up> > 01571 { 01572 public: 01573 typedef std::complex<typename __promote_2<_Tp, _Up>::__type> __type; 01574 }; 01575 01576 _GLIBCXX_END_NAMESPACE_VERSION 01577 } // namespace 01578 01579 #if __cplusplus >= 201103L 01580 01581 namespace std _GLIBCXX_VISIBILITY(default) 01582 { 01583 _GLIBCXX_BEGIN_NAMESPACE_VERSION 01584 01585 // Forward declarations. 01586 template<typename _Tp> std::complex<_Tp> acos(const std::complex<_Tp>&); 01587 template<typename _Tp> std::complex<_Tp> asin(const std::complex<_Tp>&); 01588 template<typename _Tp> std::complex<_Tp> atan(const std::complex<_Tp>&); 01589 01590 template<typename _Tp> std::complex<_Tp> acosh(const std::complex<_Tp>&); 01591 template<typename _Tp> std::complex<_Tp> asinh(const std::complex<_Tp>&); 01592 template<typename _Tp> std::complex<_Tp> atanh(const std::complex<_Tp>&); 01593 // DR 595. 01594 template<typename _Tp> _Tp fabs(const std::complex<_Tp>&); 01595 01596 template<typename _Tp> 01597 inline std::complex<_Tp> 01598 __complex_acos(const std::complex<_Tp>& __z) 01599 { 01600 const std::complex<_Tp> __t = std::asin(__z); 01601 const _Tp __pi_2 = 1.5707963267948966192313216916397514L; 01602 return std::complex<_Tp>(__pi_2 - __t.real(), -__t.imag()); 01603 } 01604 01605 #if _GLIBCXX_USE_C99_COMPLEX_TR1 01606 inline __complex__ float 01607 __complex_acos(__complex__ float __z) 01608 { return __builtin_cacosf(__z); } 01609 01610 inline __complex__ double 01611 __complex_acos(__complex__ double __z) 01612 { return __builtin_cacos(__z); } 01613 01614 inline __complex__ long double 01615 __complex_acos(const __complex__ long double& __z) 01616 { return __builtin_cacosl(__z); } 01617 01618 template<typename _Tp> 01619 inline std::complex<_Tp> 01620 acos(const std::complex<_Tp>& __z) 01621 { return __complex_acos(__z.__rep()); } 01622 #else 01623 /// acos(__z) [8.1.2]. 01624 // Effects: Behaves the same as C99 function cacos, defined 01625 // in subclause 7.3.5.1. 01626 template<typename _Tp> 01627 inline std::complex<_Tp> 01628 acos(const std::complex<_Tp>& __z) 01629 { return __complex_acos(__z); } 01630 #endif 01631 01632 template<typename _Tp> 01633 inline std::complex<_Tp> 01634 __complex_asin(const std::complex<_Tp>& __z) 01635 { 01636 std::complex<_Tp> __t(-__z.imag(), __z.real()); 01637 __t = std::asinh(__t); 01638 return std::complex<_Tp>(__t.imag(), -__t.real()); 01639 } 01640 01641 #if _GLIBCXX_USE_C99_COMPLEX_TR1 01642 inline __complex__ float 01643 __complex_asin(__complex__ float __z) 01644 { return __builtin_casinf(__z); } 01645 01646 inline __complex__ double 01647 __complex_asin(__complex__ double __z) 01648 { return __builtin_casin(__z); } 01649 01650 inline __complex__ long double 01651 __complex_asin(const __complex__ long double& __z) 01652 { return __builtin_casinl(__z); } 01653 01654 template<typename _Tp> 01655 inline std::complex<_Tp> 01656 asin(const std::complex<_Tp>& __z) 01657 { return __complex_asin(__z.__rep()); } 01658 #else 01659 /// asin(__z) [8.1.3]. 01660 // Effects: Behaves the same as C99 function casin, defined 01661 // in subclause 7.3.5.2. 01662 template<typename _Tp> 01663 inline std::complex<_Tp> 01664 asin(const std::complex<_Tp>& __z) 01665 { return __complex_asin(__z); } 01666 #endif 01667 01668 template<typename _Tp> 01669 std::complex<_Tp> 01670 __complex_atan(const std::complex<_Tp>& __z) 01671 { 01672 const _Tp __r2 = __z.real() * __z.real(); 01673 const _Tp __x = _Tp(1.0) - __r2 - __z.imag() * __z.imag(); 01674 01675 _Tp __num = __z.imag() + _Tp(1.0); 01676 _Tp __den = __z.imag() - _Tp(1.0); 01677 01678 __num = __r2 + __num * __num; 01679 __den = __r2 + __den * __den; 01680 01681 return std::complex<_Tp>(_Tp(0.5) * atan2(_Tp(2.0) * __z.real(), __x), 01682 _Tp(0.25) * log(__num / __den)); 01683 } 01684 01685 #if _GLIBCXX_USE_C99_COMPLEX_TR1 01686 inline __complex__ float 01687 __complex_atan(__complex__ float __z) 01688 { return __builtin_catanf(__z); } 01689 01690 inline __complex__ double 01691 __complex_atan(__complex__ double __z) 01692 { return __builtin_catan(__z); } 01693 01694 inline __complex__ long double 01695 __complex_atan(const __complex__ long double& __z) 01696 { return __builtin_catanl(__z); } 01697 01698 template<typename _Tp> 01699 inline std::complex<_Tp> 01700 atan(const std::complex<_Tp>& __z) 01701 { return __complex_atan(__z.__rep()); } 01702 #else 01703 /// atan(__z) [8.1.4]. 01704 // Effects: Behaves the same as C99 function catan, defined 01705 // in subclause 7.3.5.3. 01706 template<typename _Tp> 01707 inline std::complex<_Tp> 01708 atan(const std::complex<_Tp>& __z) 01709 { return __complex_atan(__z); } 01710 #endif 01711 01712 template<typename _Tp> 01713 std::complex<_Tp> 01714 __complex_acosh(const std::complex<_Tp>& __z) 01715 { 01716 // Kahan's formula. 01717 return _Tp(2.0) * std::log(std::sqrt(_Tp(0.5) * (__z + _Tp(1.0))) 01718 + std::sqrt(_Tp(0.5) * (__z - _Tp(1.0)))); 01719 } 01720 01721 #if _GLIBCXX_USE_C99_COMPLEX_TR1 01722 inline __complex__ float 01723 __complex_acosh(__complex__ float __z) 01724 { return __builtin_cacoshf(__z); } 01725 01726 inline __complex__ double 01727 __complex_acosh(__complex__ double __z) 01728 { return __builtin_cacosh(__z); } 01729 01730 inline __complex__ long double 01731 __complex_acosh(const __complex__ long double& __z) 01732 { return __builtin_cacoshl(__z); } 01733 01734 template<typename _Tp> 01735 inline std::complex<_Tp> 01736 acosh(const std::complex<_Tp>& __z) 01737 { return __complex_acosh(__z.__rep()); } 01738 #else 01739 /// acosh(__z) [8.1.5]. 01740 // Effects: Behaves the same as C99 function cacosh, defined 01741 // in subclause 7.3.6.1. 01742 template<typename _Tp> 01743 inline std::complex<_Tp> 01744 acosh(const std::complex<_Tp>& __z) 01745 { return __complex_acosh(__z); } 01746 #endif 01747 01748 template<typename _Tp> 01749 std::complex<_Tp> 01750 __complex_asinh(const std::complex<_Tp>& __z) 01751 { 01752 std::complex<_Tp> __t((__z.real() - __z.imag()) 01753 * (__z.real() + __z.imag()) + _Tp(1.0), 01754 _Tp(2.0) * __z.real() * __z.imag()); 01755 __t = std::sqrt(__t); 01756 01757 return std::log(__t + __z); 01758 } 01759 01760 #if _GLIBCXX_USE_C99_COMPLEX_TR1 01761 inline __complex__ float 01762 __complex_asinh(__complex__ float __z) 01763 { return __builtin_casinhf(__z); } 01764 01765 inline __complex__ double 01766 __complex_asinh(__complex__ double __z) 01767 { return __builtin_casinh(__z); } 01768 01769 inline __complex__ long double 01770 __complex_asinh(const __complex__ long double& __z) 01771 { return __builtin_casinhl(__z); } 01772 01773 template<typename _Tp> 01774 inline std::complex<_Tp> 01775 asinh(const std::complex<_Tp>& __z) 01776 { return __complex_asinh(__z.__rep()); } 01777 #else 01778 /// asinh(__z) [8.1.6]. 01779 // Effects: Behaves the same as C99 function casin, defined 01780 // in subclause 7.3.6.2. 01781 template<typename _Tp> 01782 inline std::complex<_Tp> 01783 asinh(const std::complex<_Tp>& __z) 01784 { return __complex_asinh(__z); } 01785 #endif 01786 01787 template<typename _Tp> 01788 std::complex<_Tp> 01789 __complex_atanh(const std::complex<_Tp>& __z) 01790 { 01791 const _Tp __i2 = __z.imag() * __z.imag(); 01792 const _Tp __x = _Tp(1.0) - __i2 - __z.real() * __z.real(); 01793 01794 _Tp __num = _Tp(1.0) + __z.real(); 01795 _Tp __den = _Tp(1.0) - __z.real(); 01796 01797 __num = __i2 + __num * __num; 01798 __den = __i2 + __den * __den; 01799 01800 return std::complex<_Tp>(_Tp(0.25) * (log(__num) - log(__den)), 01801 _Tp(0.5) * atan2(_Tp(2.0) * __z.imag(), __x)); 01802 } 01803 01804 #if _GLIBCXX_USE_C99_COMPLEX_TR1 01805 inline __complex__ float 01806 __complex_atanh(__complex__ float __z) 01807 { return __builtin_catanhf(__z); } 01808 01809 inline __complex__ double 01810 __complex_atanh(__complex__ double __z) 01811 { return __builtin_catanh(__z); } 01812 01813 inline __complex__ long double 01814 __complex_atanh(const __complex__ long double& __z) 01815 { return __builtin_catanhl(__z); } 01816 01817 template<typename _Tp> 01818 inline std::complex<_Tp> 01819 atanh(const std::complex<_Tp>& __z) 01820 { return __complex_atanh(__z.__rep()); } 01821 #else 01822 /// atanh(__z) [8.1.7]. 01823 // Effects: Behaves the same as C99 function catanh, defined 01824 // in subclause 7.3.6.3. 01825 template<typename _Tp> 01826 inline std::complex<_Tp> 01827 atanh(const std::complex<_Tp>& __z) 01828 { return __complex_atanh(__z); } 01829 #endif 01830 01831 template<typename _Tp> 01832 inline _Tp 01833 /// fabs(__z) [8.1.8]. 01834 // Effects: Behaves the same as C99 function cabs, defined 01835 // in subclause 7.3.8.1. 01836 fabs(const std::complex<_Tp>& __z) 01837 { return std::abs(__z); } 01838 01839 /// Additional overloads [8.1.9]. 01840 template<typename _Tp> 01841 inline typename __gnu_cxx::__promote<_Tp>::__type 01842 arg(_Tp __x) 01843 { 01844 typedef typename __gnu_cxx::__promote<_Tp>::__type __type; 01845 #if (_GLIBCXX11_USE_C99_MATH && !_GLIBCXX_USE_C99_FP_MACROS_DYNAMIC) 01846 return std::signbit(__x) ? __type(3.1415926535897932384626433832795029L) 01847 : __type(); 01848 #else 01849 return std::arg(std::complex<__type>(__x)); 01850 #endif 01851 } 01852 01853 template<typename _Tp> 01854 _GLIBCXX_CONSTEXPR inline typename __gnu_cxx::__promote<_Tp>::__type 01855 imag(_Tp) 01856 { return _Tp(); } 01857 01858 template<typename _Tp> 01859 _GLIBCXX20_CONSTEXPR inline typename __gnu_cxx::__promote<_Tp>::__type 01860 norm(_Tp __x) 01861 { 01862 typedef typename __gnu_cxx::__promote<_Tp>::__type __type; 01863 return __type(__x) * __type(__x); 01864 } 01865 01866 template<typename _Tp> 01867 _GLIBCXX_CONSTEXPR inline typename __gnu_cxx::__promote<_Tp>::__type 01868 real(_Tp __x) 01869 { return __x; } 01870 01871 template<typename _Tp, typename _Up> 01872 inline std::complex<typename __gnu_cxx::__promote_2<_Tp, _Up>::__type> 01873 pow(const std::complex<_Tp>& __x, const _Up& __y) 01874 { 01875 typedef typename __gnu_cxx::__promote_2<_Tp, _Up>::__type __type; 01876 return std::pow(std::complex<__type>(__x), __type(__y)); 01877 } 01878 01879 template<typename _Tp, typename _Up> 01880 inline std::complex<typename __gnu_cxx::__promote_2<_Tp, _Up>::__type> 01881 pow(const _Tp& __x, const std::complex<_Up>& __y) 01882 { 01883 typedef typename __gnu_cxx::__promote_2<_Tp, _Up>::__type __type; 01884 return std::pow(__type(__x), std::complex<__type>(__y)); 01885 } 01886 01887 template<typename _Tp, typename _Up> 01888 inline std::complex<typename __gnu_cxx::__promote_2<_Tp, _Up>::__type> 01889 pow(const std::complex<_Tp>& __x, const std::complex<_Up>& __y) 01890 { 01891 typedef typename __gnu_cxx::__promote_2<_Tp, _Up>::__type __type; 01892 return std::pow(std::complex<__type>(__x), 01893 std::complex<__type>(__y)); 01894 } 01895 01896 // Forward declarations. 01897 // DR 781. 01898 template<typename _Tp> 01899 std::complex<_Tp> proj(const std::complex<_Tp>&); 01900 01901 template<typename _Tp> 01902 std::complex<_Tp> 01903 __complex_proj(const std::complex<_Tp>& __z) 01904 { 01905 const _Tp __den = (__z.real() * __z.real() 01906 + __z.imag() * __z.imag() + _Tp(1.0)); 01907 01908 return std::complex<_Tp>((_Tp(2.0) * __z.real()) / __den, 01909 (_Tp(2.0) * __z.imag()) / __den); 01910 } 01911 01912 #if _GLIBCXX_USE_C99_COMPLEX 01913 inline __complex__ float 01914 __complex_proj(__complex__ float __z) 01915 { return __builtin_cprojf(__z); } 01916 01917 inline __complex__ double 01918 __complex_proj(__complex__ double __z) 01919 { return __builtin_cproj(__z); } 01920 01921 inline __complex__ long double 01922 __complex_proj(const __complex__ long double& __z) 01923 { return __builtin_cprojl(__z); } 01924 01925 template<typename _Tp> 01926 inline std::complex<_Tp> 01927 proj(const std::complex<_Tp>& __z) 01928 { return __complex_proj(__z.__rep()); } 01929 #else 01930 template<typename _Tp> 01931 inline std::complex<_Tp> 01932 proj(const std::complex<_Tp>& __z) 01933 { return __complex_proj(__z); } 01934 #endif 01935 01936 template<typename _Tp> 01937 inline std::complex<typename __gnu_cxx::__promote<_Tp>::__type> 01938 proj(_Tp __x) 01939 { 01940 typedef typename __gnu_cxx::__promote<_Tp>::__type __type; 01941 return std::proj(std::complex<__type>(__x)); 01942 } 01943 01944 template<typename _Tp> 01945 inline _GLIBCXX20_CONSTEXPR 01946 std::complex<typename __gnu_cxx::__promote<_Tp>::__type> 01947 conj(_Tp __x) 01948 { 01949 typedef typename __gnu_cxx::__promote<_Tp>::__type __type; 01950 return std::complex<__type>(__x, -__type()); 01951 } 01952 01953 #if __cplusplus > 201103L 01954 01955 inline namespace literals { 01956 inline namespace complex_literals { 01957 #pragma GCC diagnostic push 01958 #pragma GCC diagnostic ignored "-Wliteral-suffix" 01959 #define __cpp_lib_complex_udls 201309 01960 01961 constexpr std::complex<float> 01962 operator""if(long double __num) 01963 { return std::complex<float>{0.0F, static_cast<float>(__num)}; } 01964 01965 constexpr std::complex<float> 01966 operator""if(unsigned long long __num) 01967 { return std::complex<float>{0.0F, static_cast<float>(__num)}; } 01968 01969 constexpr std::complex<double> 01970 operator""i(long double __num) 01971 { return std::complex<double>{0.0, static_cast<double>(__num)}; } 01972 01973 constexpr std::complex<double> 01974 operator""i(unsigned long long __num) 01975 { return std::complex<double>{0.0, static_cast<double>(__num)}; } 01976 01977 constexpr std::complex<long double> 01978 operator""il(long double __num) 01979 { return std::complex<long double>{0.0L, __num}; } 01980 01981 constexpr std::complex<long double> 01982 operator""il(unsigned long long __num) 01983 { return std::complex<long double>{0.0L, static_cast<long double>(__num)}; } 01984 01985 #pragma GCC diagnostic pop 01986 } // inline namespace complex_literals 01987 } // inline namespace literals 01988 01989 #endif // C++14 01990 01991 _GLIBCXX_END_NAMESPACE_VERSION 01992 } // namespace 01993 01994 #endif // C++11 01995 01996 #endif /* _GLIBCXX_COMPLEX */