36 #ifndef _GLIBCXX_COMPLEX
37 #define _GLIBCXX_COMPLEX 1
39 #pragma GCC system_header
50 #if __cplusplus > 201703L
51 # define __cpp_lib_constexpr_complex 201711L
54 namespace std _GLIBCXX_VISIBILITY(default)
56 _GLIBCXX_BEGIN_NAMESPACE_VERSION
68 template<>
class complex<float>;
69 template<>
class complex<double>;
70 template<>
class complex<long double>;
80 template<
typename _Tp>
126 template<
typename _Tp>
134 _GLIBCXX_CONSTEXPR
complex(
const _Tp& __r = _Tp(),
const _Tp& __i = _Tp())
135 : _M_real(__r), _M_imag(__i) { }
138 #if __cplusplus >= 201103L
143 template<
typename _Up>
145 : _M_real(__z.real()), _M_imag(__z.imag()) { }
147 #if __cplusplus >= 201103L
150 _GLIBCXX_ABI_TAG_CXX11
152 real()
const {
return _M_real; }
154 _GLIBCXX_ABI_TAG_CXX11
156 imag()
const {
return _M_imag; }
160 real() {
return _M_real; }
164 real()
const {
return _M_real; }
168 imag() {
return _M_imag; }
172 imag()
const {
return _M_imag; }
177 _GLIBCXX20_CONSTEXPR
void
178 real(_Tp __val) { _M_real = __val; }
180 _GLIBCXX20_CONSTEXPR
void
181 imag(_Tp __val) { _M_imag = __val; }
184 _GLIBCXX20_CONSTEXPR complex<_Tp>&
operator=(
const _Tp&);
188 _GLIBCXX20_CONSTEXPR complex<_Tp>&
210 #if __cplusplus >= 201103L
215 template<
typename _Up>
218 template<
typename _Up>
221 template<
typename _Up>
224 template<
typename _Up>
227 template<
typename _Up>
230 _GLIBCXX_CONSTEXPR
complex __rep()
const
238 template<
typename _Tp>
239 _GLIBCXX20_CONSTEXPR complex<_Tp>&
248 template<
typename _Tp>
258 template<
typename _Tp>
267 template<
typename _Tp>
268 template<
typename _Up>
272 _M_real = __z.real();
273 _M_imag = __z.imag();
278 template<
typename _Tp>
279 template<
typename _Up>
283 _M_real += __z.real();
284 _M_imag += __z.imag();
289 template<
typename _Tp>
290 template<
typename _Up>
294 _M_real -= __z.real();
295 _M_imag -= __z.imag();
301 template<
typename _Tp>
302 template<
typename _Up>
306 const _Tp __r = _M_real * __z.real() - _M_imag * __z.imag();
307 _M_imag = _M_real * __z.imag() + _M_imag * __z.real();
314 template<
typename _Tp>
315 template<
typename _Up>
319 const _Tp __r = _M_real * __z.real() + _M_imag * __z.imag();
321 _M_imag = (_M_imag * __z.real() - _M_real * __z.imag()) / __n;
329 template<
typename _Tp>
338 template<
typename _Tp>
339 inline _GLIBCXX20_CONSTEXPR complex<_Tp>
347 template<
typename _Tp>
348 inline _GLIBCXX20_CONSTEXPR complex<_Tp>
359 template<
typename _Tp>
360 inline _GLIBCXX20_CONSTEXPR complex<_Tp>
368 template<
typename _Tp>
369 inline _GLIBCXX20_CONSTEXPR complex<_Tp>
377 template<
typename _Tp>
378 inline _GLIBCXX20_CONSTEXPR complex<_Tp>
389 template<
typename _Tp>
390 inline _GLIBCXX20_CONSTEXPR complex<_Tp>
398 template<
typename _Tp>
399 inline _GLIBCXX20_CONSTEXPR complex<_Tp>
407 template<
typename _Tp>
408 inline _GLIBCXX20_CONSTEXPR complex<_Tp>
419 template<
typename _Tp>
420 inline _GLIBCXX20_CONSTEXPR complex<_Tp>
428 template<
typename _Tp>
429 inline _GLIBCXX20_CONSTEXPR complex<_Tp>
437 template<
typename _Tp>
438 inline _GLIBCXX20_CONSTEXPR complex<_Tp>
448 template<
typename _Tp>
449 inline _GLIBCXX20_CONSTEXPR complex<_Tp>
454 template<
typename _Tp>
455 inline _GLIBCXX20_CONSTEXPR complex<_Tp>
461 template<
typename _Tp>
462 inline _GLIBCXX_CONSTEXPR
bool
464 {
return __x.real() == __y.real() && __x.imag() == __y.imag(); }
466 template<
typename _Tp>
467 inline _GLIBCXX_CONSTEXPR
bool
469 {
return __x.real() == __y && __x.imag() == _Tp(); }
471 #if !(__cpp_impl_three_way_comparison >= 201907L)
472 template<
typename _Tp>
473 inline _GLIBCXX_CONSTEXPR
bool
475 {
return __x == __y.real() && _Tp() == __y.imag(); }
480 template<
typename _Tp>
481 inline _GLIBCXX_CONSTEXPR
bool
483 {
return __x.real() != __y.real() || __x.imag() != __y.imag(); }
485 template<
typename _Tp>
486 inline _GLIBCXX_CONSTEXPR
bool
488 {
return __x.real() != __y || __x.imag() != _Tp(); }
490 template<
typename _Tp>
491 inline _GLIBCXX_CONSTEXPR
bool
493 {
return __x != __y.real() || _Tp() != __y.imag(); }
498 template<
typename _Tp,
typename _CharT,
class _Traits>
499 basic_istream<_CharT, _Traits>&
506 if (_Traits::eq(__ch, __is.
widen(
'(')))
509 if (__is >> __u >> __ch)
511 const _CharT __rparen = __is.
widen(
')');
512 if (_Traits::eq(__ch, __rparen))
517 else if (_Traits::eq(__ch, __is.
widen(
',')))
520 if (__is >> __v >> __ch)
522 if (_Traits::eq(__ch, __rparen))
552 template<
typename _Tp,
typename _CharT,
class _Traits>
553 basic_ostream<_CharT, _Traits>&
554 operator<<(basic_ostream<_CharT, _Traits>& __os,
const complex<_Tp>& __x)
557 __s.
flags(__os.flags());
558 __s.
imbue(__os.getloc());
560 __s <<
'(' << __x.real() <<
',' << __x.imag() <<
')';
561 return __os << __s.
str();
565 #if __cplusplus >= 201103L
566 template<
typename _Tp>
568 real(
const complex<_Tp>& __z)
569 {
return __z.real(); }
571 template<
typename _Tp>
573 imag(
const complex<_Tp>& __z)
574 {
return __z.imag(); }
576 template<
typename _Tp>
578 real(complex<_Tp>& __z)
579 {
return __z.real(); }
581 template<
typename _Tp>
583 real(
const complex<_Tp>& __z)
584 {
return __z.real(); }
586 template<
typename _Tp>
588 imag(complex<_Tp>& __z)
589 {
return __z.imag(); }
591 template<
typename _Tp>
593 imag(
const complex<_Tp>& __z)
594 {
return __z.imag(); }
598 template<
typename _Tp>
600 __complex_abs(
const complex<_Tp>& __z)
602 _Tp __x = __z.real();
603 _Tp __y = __z.imag();
609 return __s *
sqrt(__x * __x + __y * __y);
612 #if _GLIBCXX_USE_C99_COMPLEX
614 __complex_abs(__complex__
float __z) {
return __builtin_cabsf(__z); }
617 __complex_abs(__complex__
double __z) {
return __builtin_cabs(__z); }
620 __complex_abs(
const __complex__
long double& __z)
621 {
return __builtin_cabsl(__z); }
623 template<
typename _Tp>
625 abs(
const complex<_Tp>& __z) {
return __complex_abs(__z.__rep()); }
627 template<
typename _Tp>
634 template<
typename _Tp>
636 __complex_arg(
const complex<_Tp>& __z)
637 {
return atan2(__z.imag(), __z.real()); }
639 #if _GLIBCXX_USE_C99_COMPLEX
641 __complex_arg(__complex__
float __z) {
return __builtin_cargf(__z); }
644 __complex_arg(__complex__
double __z) {
return __builtin_carg(__z); }
647 __complex_arg(
const __complex__
long double& __z)
648 {
return __builtin_cargl(__z); }
650 template<
typename _Tp>
652 arg(
const complex<_Tp>& __z) {
return __complex_arg(__z.__rep()); }
654 template<
typename _Tp>
667 template<
typename _Tp>
668 static inline _GLIBCXX20_CONSTEXPR _Tp _S_do_it(
const complex<_Tp>& __z)
670 const _Tp __x = __z.real();
671 const _Tp __y = __z.imag();
672 return __x * __x + __y * __y;
677 struct _Norm_helper<true>
679 template<
typename _Tp>
680 static inline _GLIBCXX20_CONSTEXPR _Tp _S_do_it(
const complex<_Tp>& __z)
684 const _Tp __x = __z.real();
685 const _Tp __y = __z.imag();
686 return __x * __x + __y * __y;
690 template<
typename _Tp>
691 inline _GLIBCXX20_CONSTEXPR _Tp
694 return _Norm_helper<__is_floating<_Tp>::__value
695 && !_GLIBCXX_FAST_MATH>::_S_do_it(__z);
698 template<
typename _Tp>
700 polar(
const _Tp& __rho,
const _Tp& __theta)
702 __glibcxx_assert( __rho >= 0 );
706 template<
typename _Tp>
707 inline _GLIBCXX20_CONSTEXPR complex<_Tp>
714 template<
typename _Tp>
716 __complex_cos(
const complex<_Tp>& __z)
718 const _Tp __x = __z.real();
719 const _Tp __y = __z.imag();
723 #if _GLIBCXX_USE_C99_COMPLEX
724 inline __complex__
float
725 __complex_cos(__complex__
float __z) {
return __builtin_ccosf(__z); }
727 inline __complex__
double
728 __complex_cos(__complex__
double __z) {
return __builtin_ccos(__z); }
730 inline __complex__
long double
731 __complex_cos(
const __complex__
long double& __z)
732 {
return __builtin_ccosl(__z); }
734 template<
typename _Tp>
736 cos(
const complex<_Tp>& __z) {
return __complex_cos(__z.__rep()); }
738 template<
typename _Tp>
744 template<
typename _Tp>
746 __complex_cosh(
const complex<_Tp>& __z)
748 const _Tp __x = __z.real();
749 const _Tp __y = __z.imag();
753 #if _GLIBCXX_USE_C99_COMPLEX
754 inline __complex__
float
755 __complex_cosh(__complex__
float __z) {
return __builtin_ccoshf(__z); }
757 inline __complex__
double
758 __complex_cosh(__complex__
double __z) {
return __builtin_ccosh(__z); }
760 inline __complex__
long double
761 __complex_cosh(
const __complex__
long double& __z)
762 {
return __builtin_ccoshl(__z); }
764 template<
typename _Tp>
766 cosh(
const complex<_Tp>& __z) {
return __complex_cosh(__z.__rep()); }
768 template<
typename _Tp>
774 template<
typename _Tp>
776 __complex_exp(
const complex<_Tp>& __z)
777 {
return std::polar<_Tp>(
exp(__z.real()), __z.imag()); }
779 #if _GLIBCXX_USE_C99_COMPLEX
780 inline __complex__
float
781 __complex_exp(__complex__
float __z) {
return __builtin_cexpf(__z); }
783 inline __complex__
double
784 __complex_exp(__complex__
double __z) {
return __builtin_cexp(__z); }
786 inline __complex__
long double
787 __complex_exp(
const __complex__
long double& __z)
788 {
return __builtin_cexpl(__z); }
790 template<
typename _Tp>
792 exp(
const complex<_Tp>& __z) {
return __complex_exp(__z.__rep()); }
794 template<
typename _Tp>
801 template<
typename _Tp>
803 __complex_log(
const complex<_Tp>& __z)
806 #if _GLIBCXX_USE_C99_COMPLEX
807 inline __complex__
float
808 __complex_log(__complex__
float __z) {
return __builtin_clogf(__z); }
810 inline __complex__
double
811 __complex_log(__complex__
double __z) {
return __builtin_clog(__z); }
813 inline __complex__
long double
814 __complex_log(
const __complex__
long double& __z)
815 {
return __builtin_clogl(__z); }
817 template<
typename _Tp>
819 log(
const complex<_Tp>& __z) {
return __complex_log(__z.__rep()); }
821 template<
typename _Tp>
826 template<
typename _Tp>
832 template<
typename _Tp>
834 __complex_sin(
const complex<_Tp>& __z)
836 const _Tp __x = __z.real();
837 const _Tp __y = __z.imag();
841 #if _GLIBCXX_USE_C99_COMPLEX
842 inline __complex__
float
843 __complex_sin(__complex__
float __z) {
return __builtin_csinf(__z); }
845 inline __complex__
double
846 __complex_sin(__complex__
double __z) {
return __builtin_csin(__z); }
848 inline __complex__
long double
849 __complex_sin(
const __complex__
long double& __z)
850 {
return __builtin_csinl(__z); }
852 template<
typename _Tp>
854 sin(
const complex<_Tp>& __z) {
return __complex_sin(__z.__rep()); }
856 template<
typename _Tp>
862 template<
typename _Tp>
864 __complex_sinh(
const complex<_Tp>& __z)
866 const _Tp __x = __z.real();
867 const _Tp __y = __z.imag();
871 #if _GLIBCXX_USE_C99_COMPLEX
872 inline __complex__
float
873 __complex_sinh(__complex__
float __z) {
return __builtin_csinhf(__z); }
875 inline __complex__
double
876 __complex_sinh(__complex__
double __z) {
return __builtin_csinh(__z); }
878 inline __complex__
long double
879 __complex_sinh(
const __complex__
long double& __z)
880 {
return __builtin_csinhl(__z); }
882 template<
typename _Tp>
884 sinh(
const complex<_Tp>& __z) {
return __complex_sinh(__z.__rep()); }
886 template<
typename _Tp>
893 template<
typename _Tp>
895 __complex_sqrt(
const complex<_Tp>& __z)
897 _Tp __x = __z.real();
898 _Tp __y = __z.imag();
903 return complex<_Tp>(__t, __y < _Tp() ? -__t : __t);
910 ? complex<_Tp>(__u, __y / __t)
911 : complex<_Tp>(
abs(__y) / __t, __y < _Tp() ? -__u : __u);
915 #if _GLIBCXX_USE_C99_COMPLEX
916 inline __complex__
float
917 __complex_sqrt(__complex__
float __z) {
return __builtin_csqrtf(__z); }
919 inline __complex__
double
920 __complex_sqrt(__complex__
double __z) {
return __builtin_csqrt(__z); }
922 inline __complex__
long double
923 __complex_sqrt(
const __complex__
long double& __z)
924 {
return __builtin_csqrtl(__z); }
926 template<
typename _Tp>
928 sqrt(
const complex<_Tp>& __z) {
return __complex_sqrt(__z.__rep()); }
930 template<
typename _Tp>
937 template<
typename _Tp>
939 __complex_tan(
const complex<_Tp>& __z)
942 #if _GLIBCXX_USE_C99_COMPLEX
943 inline __complex__
float
944 __complex_tan(__complex__
float __z) {
return __builtin_ctanf(__z); }
946 inline __complex__
double
947 __complex_tan(__complex__
double __z) {
return __builtin_ctan(__z); }
949 inline __complex__
long double
950 __complex_tan(
const __complex__
long double& __z)
951 {
return __builtin_ctanl(__z); }
953 template<
typename _Tp>
955 tan(
const complex<_Tp>& __z) {
return __complex_tan(__z.__rep()); }
957 template<
typename _Tp>
965 template<
typename _Tp>
967 __complex_tanh(
const complex<_Tp>& __z)
970 #if _GLIBCXX_USE_C99_COMPLEX
971 inline __complex__
float
972 __complex_tanh(__complex__
float __z) {
return __builtin_ctanhf(__z); }
974 inline __complex__
double
975 __complex_tanh(__complex__
double __z) {
return __builtin_ctanh(__z); }
977 inline __complex__
long double
978 __complex_tanh(
const __complex__
long double& __z)
979 {
return __builtin_ctanhl(__z); }
981 template<
typename _Tp>
983 tanh(
const complex<_Tp>& __z) {
return __complex_tanh(__z.__rep()); }
985 template<
typename _Tp>
994 template<
typename _Tp>
996 __complex_pow_unsigned(complex<_Tp> __x,
unsigned __n)
998 complex<_Tp> __y = __n % 2 ? __x : complex<_Tp>(1);
1016 template<
typename _Tp>
1021 ?
complex<_Tp>(1) / std::__complex_pow_unsigned(__z, -(
unsigned)__n)
1022 : std::__complex_pow_unsigned(__z, __n);
1025 template<
typename _Tp>
1029 #if ! _GLIBCXX_USE_C99_COMPLEX
1033 if (__x.imag() == _Tp() && __x.real() > _Tp())
1034 return pow(__x.real(), __y);
1037 return std::polar<_Tp>(
exp(__y * __t.real()), __y * __t.imag());
1040 template<
typename _Tp>
1042 __complex_pow(
const complex<_Tp>& __x,
const complex<_Tp>& __y)
1043 {
return __x == _Tp() ? _Tp() : std::
exp(__y * std::
log(__x)); }
1045 #if _GLIBCXX_USE_C99_COMPLEX
1046 inline __complex__
float
1047 __complex_pow(__complex__
float __x, __complex__
float __y)
1048 {
return __builtin_cpowf(__x, __y); }
1050 inline __complex__
double
1051 __complex_pow(__complex__
double __x, __complex__
double __y)
1052 {
return __builtin_cpow(__x, __y); }
1054 inline __complex__
long double
1055 __complex_pow(
const __complex__
long double& __x,
1056 const __complex__
long double& __y)
1057 {
return __builtin_cpowl(__x, __y); }
1059 template<
typename _Tp>
1061 pow(
const complex<_Tp>& __x,
const complex<_Tp>& __y)
1062 {
return __complex_pow(__x.__rep(), __y.__rep()); }
1064 template<
typename _Tp>
1067 {
return __complex_pow(__x, __y); }
1070 template<
typename _Tp>
1074 return __x > _Tp() ? std::polar<_Tp>(
pow(__x, __y.real()),
1075 __y.imag() *
log(__x))
1085 typedef __complex__
float _ComplexT;
1087 _GLIBCXX_CONSTEXPR
complex(_ComplexT __z) : _M_value(__z) { }
1089 _GLIBCXX_CONSTEXPR
complex(
float __r = 0.0f,
float __i = 0.0f)
1090 #if __cplusplus >= 201103L
1091 : _M_value{ __r, __i } { }
1094 __real__ _M_value = __r;
1095 __imag__ _M_value = __i;
1102 #if __cplusplus >= 201103L
1105 __attribute ((__abi_tag__ (
"cxx11")))
1107 real()
const {
return __real__ _M_value; }
1109 __attribute ((__abi_tag__ (
"cxx11")))
1111 imag()
const {
return __imag__ _M_value; }
1114 real() {
return __real__ _M_value; }
1117 real()
const {
return __real__ _M_value; }
1120 imag() {
return __imag__ _M_value; }
1123 imag()
const {
return __imag__ _M_value; }
1128 _GLIBCXX20_CONSTEXPR
void
1129 real(
float __val) { __real__ _M_value = __val; }
1131 _GLIBCXX20_CONSTEXPR
void
1132 imag(
float __val) { __imag__ _M_value = __val; }
1134 _GLIBCXX20_CONSTEXPR complex&
1141 _GLIBCXX20_CONSTEXPR complex&
1148 _GLIBCXX20_CONSTEXPR complex&
1155 _GLIBCXX20_CONSTEXPR complex&
1162 _GLIBCXX20_CONSTEXPR complex&
1171 #if __cplusplus >= 201103L
1172 _GLIBCXX14_CONSTEXPR complex&
operator=(
const complex&) =
default;
1175 template<
typename _Tp>
1176 _GLIBCXX20_CONSTEXPR complex&
1179 __real__ _M_value = __z.real();
1180 __imag__ _M_value = __z.imag();
1184 template<
typename _Tp>
1185 _GLIBCXX20_CONSTEXPR complex&
1188 _M_value += __z.__rep();
1193 _GLIBCXX20_CONSTEXPR complex&
1196 _M_value -= __z.__rep();
1201 _GLIBCXX20_CONSTEXPR complex&
1204 const _ComplexT __t = __z.__rep();
1210 _GLIBCXX20_CONSTEXPR complex&
1213 const _ComplexT __t = __z.__rep();
1218 _GLIBCXX_CONSTEXPR _ComplexT __rep()
const {
return _M_value; }
1230 typedef __complex__
double _ComplexT;
1232 _GLIBCXX_CONSTEXPR
complex(_ComplexT __z) : _M_value(__z) { }
1234 _GLIBCXX_CONSTEXPR
complex(
double __r = 0.0,
double __i = 0.0)
1235 #if __cplusplus >= 201103L
1236 : _M_value{ __r, __i } { }
1239 __real__ _M_value = __r;
1240 __imag__ _M_value = __i;
1245 : _M_value(__z.__rep()) { }
1249 #if __cplusplus >= 201103L
1252 __attribute ((__abi_tag__ (
"cxx11")))
1254 real()
const {
return __real__ _M_value; }
1256 __attribute ((__abi_tag__ (
"cxx11")))
1258 imag()
const {
return __imag__ _M_value; }
1261 real() {
return __real__ _M_value; }
1264 real()
const {
return __real__ _M_value; }
1267 imag() {
return __imag__ _M_value; }
1270 imag()
const {
return __imag__ _M_value; }
1275 _GLIBCXX20_CONSTEXPR
void
1276 real(
double __val) { __real__ _M_value = __val; }
1278 _GLIBCXX20_CONSTEXPR
void
1279 imag(
double __val) { __imag__ _M_value = __val; }
1281 _GLIBCXX20_CONSTEXPR complex&
1288 _GLIBCXX20_CONSTEXPR complex&
1295 _GLIBCXX20_CONSTEXPR complex&
1302 _GLIBCXX20_CONSTEXPR complex&
1309 _GLIBCXX20_CONSTEXPR complex&
1317 #if __cplusplus >= 201103L
1318 _GLIBCXX14_CONSTEXPR complex&
operator=(
const complex&) =
default;
1321 template<
typename _Tp>
1322 _GLIBCXX20_CONSTEXPR complex&
1325 _M_value = __z.__rep();
1329 template<
typename _Tp>
1330 _GLIBCXX20_CONSTEXPR complex&
1333 _M_value += __z.__rep();
1337 template<
typename _Tp>
1338 _GLIBCXX20_CONSTEXPR complex&
1341 _M_value -= __z.__rep();
1345 template<
typename _Tp>
1346 _GLIBCXX20_CONSTEXPR complex&
1349 const _ComplexT __t = __z.__rep();
1354 template<
typename _Tp>
1355 _GLIBCXX20_CONSTEXPR complex&
1358 const _ComplexT __t = __z.__rep();
1363 _GLIBCXX_CONSTEXPR _ComplexT __rep()
const {
return _M_value; }
1375 typedef __complex__
long double _ComplexT;
1377 _GLIBCXX_CONSTEXPR
complex(_ComplexT __z) : _M_value(__z) { }
1379 _GLIBCXX_CONSTEXPR
complex(
long double __r = 0.0L,
1380 long double __i = 0.0L)
1381 #if __cplusplus >= 201103L
1382 : _M_value{ __r, __i } { }
1385 __real__ _M_value = __r;
1386 __imag__ _M_value = __i;
1391 : _M_value(__z.__rep()) { }
1394 : _M_value(__z.__rep()) { }
1396 #if __cplusplus >= 201103L
1399 __attribute ((__abi_tag__ (
"cxx11")))
1400 constexpr
long double
1401 real()
const {
return __real__ _M_value; }
1403 __attribute ((__abi_tag__ (
"cxx11")))
1404 constexpr
long double
1405 imag()
const {
return __imag__ _M_value; }
1408 real() {
return __real__ _M_value; }
1411 real()
const {
return __real__ _M_value; }
1414 imag() {
return __imag__ _M_value; }
1417 imag()
const {
return __imag__ _M_value; }
1422 _GLIBCXX20_CONSTEXPR
void
1423 real(
long double __val) { __real__ _M_value = __val; }
1425 _GLIBCXX20_CONSTEXPR
void
1426 imag(
long double __val) { __imag__ _M_value = __val; }
1428 _GLIBCXX20_CONSTEXPR complex&
1435 _GLIBCXX20_CONSTEXPR complex&
1442 _GLIBCXX20_CONSTEXPR complex&
1449 _GLIBCXX20_CONSTEXPR complex&
1456 _GLIBCXX20_CONSTEXPR complex&
1464 #if __cplusplus >= 201103L
1465 _GLIBCXX14_CONSTEXPR complex&
operator=(
const complex&) =
default;
1468 template<
typename _Tp>
1469 _GLIBCXX20_CONSTEXPR complex&
1472 _M_value = __z.__rep();
1476 template<
typename _Tp>
1477 _GLIBCXX20_CONSTEXPR complex&
1480 _M_value += __z.__rep();
1484 template<
typename _Tp>
1485 _GLIBCXX20_CONSTEXPR complex&
1488 _M_value -= __z.__rep();
1492 template<
typename _Tp>
1493 _GLIBCXX20_CONSTEXPR complex&
1496 const _ComplexT __t = __z.__rep();
1501 template<
typename _Tp>
1502 _GLIBCXX20_CONSTEXPR complex&
1505 const _ComplexT __t = __z.__rep();
1510 _GLIBCXX_CONSTEXPR _ComplexT __rep()
const {
return _M_value; }
1518 inline _GLIBCXX_CONSTEXPR
1520 : _M_value(__z.__rep()) { }
1522 inline _GLIBCXX_CONSTEXPR
1524 : _M_value(__z.__rep()) { }
1526 inline _GLIBCXX_CONSTEXPR
1528 : _M_value(__z.__rep()) { }
1533 #if _GLIBCXX_EXTERN_TEMPLATE
1535 extern template ostream& operator<<(ostream&, const complex<float>&);
1537 extern template ostream& operator<<(ostream&, const complex<double>&);
1539 extern template ostream& operator<<(ostream&, const complex<long double>&);
1541 #ifdef _GLIBCXX_USE_WCHAR_T
1543 extern template wostream& operator<<(wostream&, const complex<float>&);
1545 extern template wostream& operator<<(wostream&, const complex<double>&);
1547 extern template wostream& operator<<(wostream&, const complex<long double>&);
1553 _GLIBCXX_END_NAMESPACE_VERSION
1556 namespace __gnu_cxx _GLIBCXX_VISIBILITY(
default)
1558 _GLIBCXX_BEGIN_NAMESPACE_VERSION
1561 template<
typename _Tp,
typename _Up>
1562 struct __promote_2<std::complex<_Tp>, _Up>
1568 template<
typename _Tp,
typename _Up>
1569 struct __promote_2<_Tp, std::complex<_Up> >
1575 template<
typename _Tp,
typename _Up>
1576 struct __promote_2<std::complex<_Tp>,
std::complex<_Up> >
1582 _GLIBCXX_END_NAMESPACE_VERSION
1585 #if __cplusplus >= 201103L
1587 namespace std _GLIBCXX_VISIBILITY(default)
1589 _GLIBCXX_BEGIN_NAMESPACE_VERSION
1602 template<
typename _Tp>
1607 const _Tp __pi_2 = 1.5707963267948966192313216916397514L;
1611 #if _GLIBCXX_USE_C99_COMPLEX_TR1
1612 inline __complex__
float
1613 __complex_acos(__complex__
float __z)
1614 {
return __builtin_cacosf(__z); }
1616 inline __complex__
double
1617 __complex_acos(__complex__
double __z)
1618 {
return __builtin_cacos(__z); }
1620 inline __complex__
long double
1621 __complex_acos(
const __complex__
long double& __z)
1622 {
return __builtin_cacosl(__z); }
1624 template<
typename _Tp>
1627 {
return __complex_acos(__z.__rep()); }
1632 template<
typename _Tp>
1635 {
return __complex_acos(__z); }
1638 template<
typename _Tp>
1647 #if _GLIBCXX_USE_C99_COMPLEX_TR1
1648 inline __complex__
float
1649 __complex_asin(__complex__
float __z)
1650 {
return __builtin_casinf(__z); }
1652 inline __complex__
double
1653 __complex_asin(__complex__
double __z)
1654 {
return __builtin_casin(__z); }
1656 inline __complex__
long double
1657 __complex_asin(
const __complex__
long double& __z)
1658 {
return __builtin_casinl(__z); }
1660 template<
typename _Tp>
1663 {
return __complex_asin(__z.__rep()); }
1668 template<
typename _Tp>
1671 {
return __complex_asin(__z); }
1674 template<
typename _Tp>
1678 const _Tp __r2 = __z.real() * __z.real();
1679 const _Tp __x = _Tp(1.0) - __r2 - __z.imag() * __z.imag();
1681 _Tp __num = __z.imag() + _Tp(1.0);
1682 _Tp __den = __z.imag() - _Tp(1.0);
1684 __num = __r2 + __num * __num;
1685 __den = __r2 + __den * __den;
1688 _Tp(0.25) *
log(__num / __den));
1691 #if _GLIBCXX_USE_C99_COMPLEX_TR1
1692 inline __complex__
float
1693 __complex_atan(__complex__
float __z)
1694 {
return __builtin_catanf(__z); }
1696 inline __complex__
double
1697 __complex_atan(__complex__
double __z)
1698 {
return __builtin_catan(__z); }
1700 inline __complex__
long double
1701 __complex_atan(
const __complex__
long double& __z)
1702 {
return __builtin_catanl(__z); }
1704 template<
typename _Tp>
1707 {
return __complex_atan(__z.__rep()); }
1712 template<
typename _Tp>
1715 {
return __complex_atan(__z); }
1718 template<
typename _Tp>
1724 +
std::sqrt(_Tp(0.5) * (__z - _Tp(1.0))));
1727 #if _GLIBCXX_USE_C99_COMPLEX_TR1
1728 inline __complex__
float
1729 __complex_acosh(__complex__
float __z)
1730 {
return __builtin_cacoshf(__z); }
1732 inline __complex__
double
1733 __complex_acosh(__complex__
double __z)
1734 {
return __builtin_cacosh(__z); }
1736 inline __complex__
long double
1737 __complex_acosh(
const __complex__
long double& __z)
1738 {
return __builtin_cacoshl(__z); }
1740 template<
typename _Tp>
1743 {
return __complex_acosh(__z.__rep()); }
1748 template<
typename _Tp>
1751 {
return __complex_acosh(__z); }
1754 template<
typename _Tp>
1759 * (__z.real() + __z.imag()) + _Tp(1.0),
1760 _Tp(2.0) * __z.real() * __z.imag());
1766 #if _GLIBCXX_USE_C99_COMPLEX_TR1
1767 inline __complex__
float
1768 __complex_asinh(__complex__
float __z)
1769 {
return __builtin_casinhf(__z); }
1771 inline __complex__
double
1772 __complex_asinh(__complex__
double __z)
1773 {
return __builtin_casinh(__z); }
1775 inline __complex__
long double
1776 __complex_asinh(
const __complex__
long double& __z)
1777 {
return __builtin_casinhl(__z); }
1779 template<
typename _Tp>
1782 {
return __complex_asinh(__z.__rep()); }
1787 template<
typename _Tp>
1790 {
return __complex_asinh(__z); }
1793 template<
typename _Tp>
1797 const _Tp __i2 = __z.imag() * __z.imag();
1798 const _Tp __x = _Tp(1.0) - __i2 - __z.real() * __z.real();
1800 _Tp __num = _Tp(1.0) + __z.real();
1801 _Tp __den = _Tp(1.0) - __z.real();
1803 __num = __i2 + __num * __num;
1804 __den = __i2 + __den * __den;
1807 _Tp(0.5) * atan2(_Tp(2.0) * __z.imag(), __x));
1810 #if _GLIBCXX_USE_C99_COMPLEX_TR1
1811 inline __complex__
float
1812 __complex_atanh(__complex__
float __z)
1813 {
return __builtin_catanhf(__z); }
1815 inline __complex__
double
1816 __complex_atanh(__complex__
double __z)
1817 {
return __builtin_catanh(__z); }
1819 inline __complex__
long double
1820 __complex_atanh(
const __complex__
long double& __z)
1821 {
return __builtin_catanhl(__z); }
1823 template<
typename _Tp>
1826 {
return __complex_atanh(__z.__rep()); }
1831 template<
typename _Tp>
1834 {
return __complex_atanh(__z); }
1837 template<
typename _Tp>
1846 template<
typename _Tp>
1847 inline typename __gnu_cxx::__promote<_Tp>::__type
1850 typedef typename __gnu_cxx::__promote<_Tp>::__type __type;
1851 #if (_GLIBCXX11_USE_C99_MATH && !_GLIBCXX_USE_C99_FP_MACROS_DYNAMIC)
1852 return std::signbit(__x) ? __type(3.1415926535897932384626433832795029L)
1859 template<
typename _Tp>
1860 _GLIBCXX_CONSTEXPR
inline typename __gnu_cxx::__promote<_Tp>::__type
1864 template<
typename _Tp>
1865 _GLIBCXX20_CONSTEXPR
inline typename __gnu_cxx::__promote<_Tp>::__type
1868 typedef typename __gnu_cxx::__promote<_Tp>::__type __type;
1869 return __type(__x) * __type(__x);
1872 template<
typename _Tp>
1873 _GLIBCXX_CONSTEXPR
inline typename __gnu_cxx::__promote<_Tp>::__type
1877 template<
typename _Tp,
typename _Up>
1881 typedef typename __gnu_cxx::__promote_2<_Tp, _Up>::__type __type;
1885 template<
typename _Tp,
typename _Up>
1889 typedef typename __gnu_cxx::__promote_2<_Tp, _Up>::__type __type;
1893 template<
typename _Tp,
typename _Up>
1897 typedef typename __gnu_cxx::__promote_2<_Tp, _Up>::__type __type;
1904 template<
typename _Tp>
1908 template<
typename _Tp>
1913 #if _GLIBCXX_USE_C99_COMPLEX
1914 inline complex<float>
1915 __complex_proj(
const complex<float>& __z)
1916 {
return __builtin_cprojf(__z.__rep()); }
1918 inline complex<double>
1919 __complex_proj(
const complex<double>& __z)
1920 {
return __builtin_cproj(__z.__rep()); }
1922 inline complex<long double>
1923 __complex_proj(
const complex<long double>& __z)
1924 {
return __builtin_cprojl(__z.__rep()); }
1925 #elif defined _GLIBCXX_USE_C99_MATH_TR1
1926 inline complex<float>
1927 __complex_proj(
const complex<float>& __z)
1929 if (__builtin_isinf(__z.real()) || __builtin_isinf(__z.imag()))
1930 return complex<float>(__builtin_inff(),
1931 __builtin_copysignf(0.0f, __z.imag()));
1935 inline complex<double>
1936 __complex_proj(
const complex<double>& __z)
1938 if (__builtin_isinf(__z.real()) || __builtin_isinf(__z.imag()))
1939 return complex<double>(__builtin_inf(),
1940 __builtin_copysign(0.0, __z.imag()));
1944 inline complex<long double>
1945 __complex_proj(
const complex<long double>& __z)
1947 if (__builtin_isinf(__z.real()) || __builtin_isinf(__z.imag()))
1948 return complex<long double>(__builtin_infl(),
1949 __builtin_copysignl(0.0l, __z.imag()));
1954 template<
typename _Tp>
1957 {
return __complex_proj(__z); }
1960 template<
typename _Tp>
1964 typedef typename __gnu_cxx::__promote<_Tp>::__type __type;
1968 template<
typename _Tp>
1969 inline _GLIBCXX20_CONSTEXPR
1973 typedef typename __gnu_cxx::__promote<_Tp>::__type __type;
1977 #if __cplusplus > 201103L
1979 inline namespace literals {
1980 inline namespace complex_literals {
1981 #pragma GCC diagnostic push
1982 #pragma GCC diagnostic ignored "-Wliteral-suffix"
1983 #define __cpp_lib_complex_udls 201309
1986 operator""if(
long double __num)
1990 operator""if(
unsigned long long __num)
1994 operator""i(
long double __num)
1998 operator""i(
unsigned long long __num)
2002 operator""il(
long double __num)
2006 operator""il(
unsigned long long __num)
2009 #pragma GCC diagnostic pop
2015 _GLIBCXX_END_NAMESPACE_VERSION
constexpr complex< _Tp > operator-(const complex< _Tp > &__x, const complex< _Tp > &__y)
Return new complex value x minus y.
complex< _Tp > polar(const _Tp &, const _Tp &=0)
Return complex with magnitude rho and angle theta.
constexpr complex(const complex< _Up > &__z)
Converting constructor.
Controlling output for std::string.
std::complex< _Tp > asinh(const std::complex< _Tp > &)
asinh(__z) [8.1.6].
std::complex< _Tp > acos(const std::complex< _Tp > &)
acos(__z) [8.1.2].
_Tp abs(const complex< _Tp > &)
Return magnitude of z.
26.2.3 complex specializations complex<double> specialization
complex< _Tp > sqrt(const complex< _Tp > &)
Return complex square root of z.
constexpr complex< _Tp > & operator*=(const _Tp &)
Multiply this complex number by a scalar.
streamsize precision() const
Flags access.
complex< _Tp > cos(const complex< _Tp > &)
Return complex cosine of z.
constexpr complex< _Tp > & operator/=(const _Tp &)
Divide this complex number by a scalar.
std::complex< _Tp > asin(const std::complex< _Tp > &)
asin(__z) [8.1.3].
complex< _Tp > exp(const complex< _Tp > &)
Return complex base e exponential of z.
complex< _Tp > tan(const complex< _Tp > &)
Return complex tangent of z.
basic_istream< wchar_t > wistream
Base class for wchar_t input streams.
static const iostate failbit
Indicates that an input operation failed to read the expected characters, or that an output operation...
locale imbue(const locale &__loc)
Moves to a new locale.
_Tp constexpr norm(const complex< _Tp > &)
Return z magnitude squared.
__istream_type & putback(char_type __c)
Unextracting a single character.
basic_ostream< char > ostream
Base class for char output streams.
_Tp arg(const complex< _Tp > &)
Return phase angle of z.
fmtflags flags() const
Access to format flags.
Template class basic_istream.
constexpr complex< _Tp > conj(const complex< _Tp > &)
Return complex conjugate of z.
std::basic_istream< _CharT, _Traits > & operator>>(std::basic_istream< _CharT, _Traits > &__is, bitset< _Nb > &__x)
Global I/O operators for bitsets.
constexpr complex< _Tp > & operator+=(const _Tp &__t)
Add a scalar to this complex number.
complex< _Tp > cosh(const complex< _Tp > &)
Return complex hyperbolic cosine of z.
char_type widen(char __c) const
Widens characters.
26.2.3 complex specializations complex<long double> specialization
constexpr const _Tp & max(const _Tp &, const _Tp &)
This does what you think it does.
complex< _Tp > log10(const complex< _Tp > &)
Return complex base 10 logarithm of z.
std::complex< _Tp > atan(const std::complex< _Tp > &)
atan(__z) [8.1.4].
complex< _Tp > sin(const complex< _Tp > &)
Return complex sine of z.
complex< _Tp > pow(const complex< _Tp > &, int)
Return x to the y'th power.
complex< _Tp > log(const complex< _Tp > &)
Return complex natural logarithm of z.
complex< _Tp > tanh(const complex< _Tp > &)
Return complex hyperbolic tangent of z.
_Tp fabs(const std::complex< _Tp > &)
fabs(__z) [8.1.8].
complex< _Tp > sinh(const complex< _Tp > &)
Return complex hyperbolic sine of z.
std::complex< _Tp > acosh(const std::complex< _Tp > &)
acosh(__z) [8.1.5].
basic_istream< char > istream
Base class for char input streams.
constexpr complex< _Tp > operator+(const complex< _Tp > &__x, const complex< _Tp > &__y)
Return new complex value x plus y.
26.2.3 complex specializations complex<float> specialization
constexpr complex< _Tp > operator/(const complex< _Tp > &__x, const complex< _Tp > &__y)
Return new complex value x divided by y.
constexpr complex< _Tp > & operator-=(const _Tp &__t)
Subtract a scalar from this complex number.
basic_ostream< wchar_t > wostream
Base class for wchar_t output streams.
constexpr complex< _Tp > operator*(const complex< _Tp > &__x, const complex< _Tp > &__y)
Return new complex value x times y.
__string_type str() const
Copying out the string buffer.
void setstate(iostate __state)
Sets additional flags in the error state.
constexpr complex(const _Tp &__r=_Tp(), const _Tp &__i=_Tp())
Default constructor. First parameter is x, second parameter is y. Unspecified parameters default to 0...
std::complex< _Tp > atanh(const std::complex< _Tp > &)
atanh(__z) [8.1.7].
_Tp value_type
Value typedef.
constexpr complex< _Tp > & operator=(const _Tp &)
Assign a scalar to this complex number.