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
54namespace std _GLIBCXX_VISIBILITY(default)
56_GLIBCXX_BEGIN_NAMESPACE_VERSION
67 template<
typename _Tp>
class complex;
68 template<>
class complex<float>;
69 template<>
class complex<double>;
70 template<>
class complex<long double>;
73 template<
typename _Tp> _Tp
abs(
const complex<_Tp>&);
75 template<
typename _Tp> _Tp
arg(
const complex<_Tp>&);
77 template<
typename _Tp> _Tp _GLIBCXX20_CONSTEXPR
norm(
const complex<_Tp>&);
80 template<
typename _Tp>
81 _GLIBCXX20_CONSTEXPR complex<_Tp>
conj(
const complex<_Tp>&);
83 template<
typename _Tp> complex<_Tp>
polar(
const _Tp&,
const _Tp& = 0);
87 template<
typename _Tp> complex<_Tp>
cos(
const complex<_Tp>&);
89 template<
typename _Tp> complex<_Tp>
cosh(
const complex<_Tp>&);
91 template<
typename _Tp> complex<_Tp>
exp(
const complex<_Tp>&);
93 template<
typename _Tp> complex<_Tp>
log(
const complex<_Tp>&);
95 template<
typename _Tp> complex<_Tp>
log10(
const complex<_Tp>&);
97 template<
typename _Tp> complex<_Tp>
pow(
const complex<_Tp>&,
int);
99 template<
typename _Tp> complex<_Tp>
pow(
const complex<_Tp>&,
const _Tp&);
101 template<
typename _Tp> complex<_Tp>
pow(
const complex<_Tp>&,
102 const complex<_Tp>&);
104 template<
typename _Tp> complex<_Tp>
pow(
const _Tp&,
const complex<_Tp>&);
106 template<
typename _Tp> complex<_Tp>
sin(
const complex<_Tp>&);
108 template<
typename _Tp> complex<_Tp>
sinh(
const complex<_Tp>&);
110 template<
typename _Tp> complex<_Tp>
sqrt(
const complex<_Tp>&);
112 template<
typename _Tp> complex<_Tp>
tan(
const complex<_Tp>&);
114 template<
typename _Tp> complex<_Tp>
tanh(
const complex<_Tp>&);
126 template<
typename _Tp>
135 _GLIBCXX_CONSTEXPR
complex(
const _Tp& __r = _Tp(),
const _Tp& __i = _Tp())
136 : _M_real(__r), _M_imag(__i) { }
139#if __cplusplus >= 201103L
144 template<
typename _Up>
145#if __cplusplus > 202002L
146 explicit(!
requires(_Up __u) { _Tp{__u}; })
149 : _M_real(_Tp(__z.real())), _M_imag(_Tp(__z.imag())) { }
151#if __cplusplus >= 201103L
154 _GLIBCXX_ABI_TAG_CXX11
156 real()
const {
return _M_real; }
158 _GLIBCXX_ABI_TAG_CXX11
160 imag()
const {
return _M_imag; }
164 real() {
return _M_real; }
168 real()
const {
return _M_real; }
172 imag() {
return _M_imag; }
176 imag()
const {
return _M_imag; }
181 _GLIBCXX20_CONSTEXPR
void
182 real(_Tp __val) { _M_real = __val; }
184 _GLIBCXX20_CONSTEXPR
void
185 imag(_Tp __val) { _M_imag = __val; }
188 _GLIBCXX20_CONSTEXPR complex<_Tp>&
operator=(
const _Tp&);
192 _GLIBCXX20_CONSTEXPR complex<_Tp>&
214#if __cplusplus >= 201103L
219 template<
typename _Up>
222 template<
typename _Up>
225 template<
typename _Up>
228 template<
typename _Up>
231 template<
typename _Up>
234 _GLIBCXX_CONSTEXPR
complex __rep()
const
242 template<
typename _Tp>
243 _GLIBCXX20_CONSTEXPR complex<_Tp>&
252 template<
typename _Tp>
262 template<
typename _Tp>
271 template<
typename _Tp>
272 template<
typename _Up>
276 _M_real = __z.real();
277 _M_imag = __z.imag();
282 template<
typename _Tp>
283 template<
typename _Up>
287 _M_real += __z.real();
288 _M_imag += __z.imag();
293 template<
typename _Tp>
294 template<
typename _Up>
298 _M_real -= __z.real();
299 _M_imag -= __z.imag();
305 template<
typename _Tp>
306 template<
typename _Up>
310 const _Tp __r = _M_real * __z.real() - _M_imag * __z.imag();
311 _M_imag = _M_real * __z.imag() + _M_imag * __z.real();
318 template<
typename _Tp>
319 template<
typename _Up>
323 const _Tp __r = _M_real * __z.real() + _M_imag * __z.imag();
325 _M_imag = (_M_imag * __z.real() - _M_real * __z.imag()) / __n;
333 template<
typename _Tp>
342 template<
typename _Tp>
343 inline _GLIBCXX20_CONSTEXPR complex<_Tp>
351 template<
typename _Tp>
352 inline _GLIBCXX20_CONSTEXPR complex<_Tp>
363 template<
typename _Tp>
364 inline _GLIBCXX20_CONSTEXPR complex<_Tp>
372 template<
typename _Tp>
373 inline _GLIBCXX20_CONSTEXPR complex<_Tp>
381 template<
typename _Tp>
382 inline _GLIBCXX20_CONSTEXPR complex<_Tp>
393 template<
typename _Tp>
394 inline _GLIBCXX20_CONSTEXPR complex<_Tp>
402 template<
typename _Tp>
403 inline _GLIBCXX20_CONSTEXPR complex<_Tp>
411 template<
typename _Tp>
412 inline _GLIBCXX20_CONSTEXPR complex<_Tp>
423 template<
typename _Tp>
424 inline _GLIBCXX20_CONSTEXPR complex<_Tp>
432 template<
typename _Tp>
433 inline _GLIBCXX20_CONSTEXPR complex<_Tp>
441 template<
typename _Tp>
442 inline _GLIBCXX20_CONSTEXPR complex<_Tp>
452 template<
typename _Tp>
453 inline _GLIBCXX20_CONSTEXPR complex<_Tp>
458 template<
typename _Tp>
459 inline _GLIBCXX20_CONSTEXPR complex<_Tp>
465 template<
typename _Tp>
466 inline _GLIBCXX_CONSTEXPR
bool
468 {
return __x.real() == __y.real() && __x.imag() == __y.imag(); }
470 template<
typename _Tp>
471 inline _GLIBCXX_CONSTEXPR
bool
473 {
return __x.real() == __y && __x.imag() == _Tp(); }
475#if !(__cpp_impl_three_way_comparison >= 201907L)
476 template<
typename _Tp>
477 inline _GLIBCXX_CONSTEXPR
bool
478 operator==(
const _Tp& __x,
const complex<_Tp>& __y)
479 {
return __x == __y.real() && _Tp() == __y.imag(); }
484 template<
typename _Tp>
485 inline _GLIBCXX_CONSTEXPR
bool
486 operator!=(
const complex<_Tp>& __x,
const complex<_Tp>& __y)
487 {
return __x.real() != __y.real() || __x.imag() != __y.imag(); }
489 template<
typename _Tp>
490 inline _GLIBCXX_CONSTEXPR
bool
491 operator!=(
const complex<_Tp>& __x,
const _Tp& __y)
492 {
return __x.real() != __y || __x.imag() != _Tp(); }
494 template<
typename _Tp>
495 inline _GLIBCXX_CONSTEXPR
bool
496 operator!=(
const _Tp& __x,
const complex<_Tp>& __y)
497 {
return __x != __y.real() || _Tp() != __y.imag(); }
502 template<
typename _Tp,
typename _CharT,
class _Traits>
503 basic_istream<_CharT, _Traits>&
510 if (_Traits::eq(__ch, __is.
widen(
'(')))
513 if (__is >> __u >> __ch)
515 const _CharT __rparen = __is.
widen(
')');
516 if (_Traits::eq(__ch, __rparen))
521 else if (_Traits::eq(__ch, __is.
widen(
',')))
524 if (__is >> __v >> __ch)
526 if (_Traits::eq(__ch, __rparen))
556 template<
typename _Tp,
typename _CharT,
class _Traits>
557 basic_ostream<_CharT, _Traits>&
558 operator<<(basic_ostream<_CharT, _Traits>& __os,
const complex<_Tp>& __x)
560 basic_ostringstream<_CharT, _Traits> __s;
561 __s.
flags(__os.flags());
562 __s.imbue(__os.getloc());
563 __s.precision(__os.precision());
564 __s <<
'(' << __x.real() <<
',' << __x.imag() <<
')';
565 return __os << __s.str();
569#if __cplusplus >= 201103L
570 template<
typename _Tp>
572 real(
const complex<_Tp>& __z)
573 {
return __z.real(); }
575 template<
typename _Tp>
577 imag(
const complex<_Tp>& __z)
578 {
return __z.imag(); }
580 template<
typename _Tp>
582 real(complex<_Tp>& __z)
583 {
return __z.real(); }
585 template<
typename _Tp>
587 real(
const complex<_Tp>& __z)
588 {
return __z.real(); }
590 template<
typename _Tp>
592 imag(complex<_Tp>& __z)
593 {
return __z.imag(); }
595 template<
typename _Tp>
597 imag(
const complex<_Tp>& __z)
598 {
return __z.imag(); }
601#if _GLIBCXX_USE_C99_COMPLEX
602#if defined(__STDCPP_FLOAT16_T__) && defined(_GLIBCXX_FLOAT_IS_IEEE_BINARY32)
604 __complex_abs(__complex__ _Float16 __z)
605 {
return _Float16(__builtin_cabsf(__z)); }
608 __complex_arg(__complex__ _Float16 __z)
609 {
return _Float16(__builtin_cargf(__z)); }
611 inline __complex__ _Float16
612 __complex_cos(__complex__ _Float16 __z)
613 {
return static_cast<__complex__ _Float16
>(__builtin_ccosf(__z)); }
615 inline __complex__ _Float16
616 __complex_cosh(__complex__ _Float16 __z)
617 {
return static_cast<__complex__ _Float16
>(__builtin_ccoshf(__z)); }
619 inline __complex__ _Float16
620 __complex_exp(__complex__ _Float16 __z)
621 {
return static_cast<__complex__ _Float16
>(__builtin_cexpf(__z)); }
623 inline __complex__ _Float16
624 __complex_log(__complex__ _Float16 __z)
625 {
return static_cast<__complex__ _Float16
>(__builtin_clogf(__z)); }
627 inline __complex__ _Float16
628 __complex_sin(__complex__ _Float16 __z)
629 {
return static_cast<__complex__ _Float16
>(__builtin_csinf(__z)); }
631 inline __complex__ _Float16
632 __complex_sinh(__complex__ _Float16 __z)
633 {
return static_cast<__complex__ _Float16
>(__builtin_csinhf(__z)); }
635 inline __complex__ _Float16
636 __complex_sqrt(__complex__ _Float16 __z)
637 {
return static_cast<__complex__ _Float16
>(__builtin_csqrtf(__z)); }
639 inline __complex__ _Float16
640 __complex_tan(__complex__ _Float16 __z)
641 {
return static_cast<__complex__ _Float16
>(__builtin_ctanf(__z)); }
643 inline __complex__ _Float16
644 __complex_tanh(__complex__ _Float16 __z)
645 {
return static_cast<__complex__ _Float16
>(__builtin_ctanhf(__z)); }
647 inline __complex__ _Float16
648 __complex_pow(__complex__ _Float16 __x, __complex__ _Float16 __y)
649 {
return static_cast<__complex__ _Float16
>(__builtin_cpowf(__x, __y)); }
652#if defined(__STDCPP_FLOAT32_T__) && defined(_GLIBCXX_FLOAT_IS_IEEE_BINARY32)
654 __complex_abs(__complex__ _Float32 __z) {
return __builtin_cabsf(__z); }
657 __complex_arg(__complex__ _Float32 __z) {
return __builtin_cargf(__z); }
659 inline __complex__ _Float32
660 __complex_cos(__complex__ _Float32 __z) {
return __builtin_ccosf(__z); }
662 inline __complex__ _Float32
663 __complex_cosh(__complex__ _Float32 __z) {
return __builtin_ccoshf(__z); }
665 inline __complex__ _Float32
666 __complex_exp(__complex__ _Float32 __z) {
return __builtin_cexpf(__z); }
668 inline __complex__ _Float32
669 __complex_log(__complex__ _Float32 __z) {
return __builtin_clogf(__z); }
671 inline __complex__ _Float32
672 __complex_sin(__complex__ _Float32 __z) {
return __builtin_csinf(__z); }
674 inline __complex__ _Float32
675 __complex_sinh(__complex__ _Float32 __z) {
return __builtin_csinhf(__z); }
677 inline __complex__ _Float32
678 __complex_sqrt(__complex__ _Float32 __z) {
return __builtin_csqrtf(__z); }
680 inline __complex__ _Float32
681 __complex_tan(__complex__ _Float32 __z) {
return __builtin_ctanf(__z); }
683 inline __complex__ _Float32
684 __complex_tanh(__complex__ _Float32 __z) {
return __builtin_ctanhf(__z); }
686 inline __complex__ _Float32
687 __complex_pow(__complex__ _Float32 __x, __complex__ _Float32 __y)
688 {
return __builtin_cpowf(__x, __y); }
691#if defined(__STDCPP_FLOAT64_T__) && defined(_GLIBCXX_DOUBLE_IS_IEEE_BINARY64)
693 __complex_abs(__complex__ _Float64 __z) {
return __builtin_cabs(__z); }
696 __complex_arg(__complex__ _Float64 __z) {
return __builtin_carg(__z); }
698 inline __complex__ _Float64
699 __complex_cos(__complex__ _Float64 __z) {
return __builtin_ccos(__z); }
701 inline __complex__ _Float64
702 __complex_cosh(__complex__ _Float64 __z) {
return __builtin_ccosh(__z); }
704 inline __complex__ _Float64
705 __complex_exp(__complex__ _Float64 __z) {
return __builtin_cexp(__z); }
707 inline __complex__ _Float64
708 __complex_log(__complex__ _Float64 __z) {
return __builtin_clog(__z); }
710 inline __complex__ _Float64
711 __complex_sin(__complex__ _Float64 __z) {
return __builtin_csin(__z); }
713 inline __complex__ _Float64
714 __complex_sinh(__complex__ _Float64 __z) {
return __builtin_csinh(__z); }
716 inline __complex__ _Float64
717 __complex_sqrt(__complex__ _Float64 __z) {
return __builtin_csqrt(__z); }
719 inline __complex__ _Float64
720 __complex_tan(__complex__ _Float64 __z) {
return __builtin_ctan(__z); }
722 inline __complex__ _Float64
723 __complex_tanh(__complex__ _Float64 __z) {
return __builtin_ctanh(__z); }
725 inline __complex__ _Float64
726 __complex_pow(__complex__ _Float64 __x, __complex__ _Float64 __y)
727 {
return __builtin_cpow(__x, __y); }
730#if defined(__STDCPP_FLOAT128_T__) && defined(_GLIBCXX_LDOUBLE_IS_IEEE_BINARY128)
732 __complex_abs(__complex__ _Float128 __z) {
return __builtin_cabsl(__z); }
735 __complex_arg(__complex__ _Float128 __z) {
return __builtin_cargl(__z); }
737 inline __complex__ _Float128
738 __complex_cos(__complex__ _Float128 __z) {
return __builtin_ccosl(__z); }
740 inline __complex__ _Float128
741 __complex_cosh(__complex__ _Float128 __z) {
return __builtin_ccoshl(__z); }
743 inline __complex__ _Float128
744 __complex_exp(__complex__ _Float128 __z) {
return __builtin_cexpl(__z); }
746 inline __complex__ _Float128
747 __complex_log(__complex__ _Float128 __z) {
return __builtin_clogl(__z); }
749 inline __complex__ _Float128
750 __complex_sin(__complex__ _Float128 __z) {
return __builtin_csinl(__z); }
752 inline __complex__ _Float128
753 __complex_sinh(__complex__ _Float128 __z) {
return __builtin_csinhl(__z); }
755 inline __complex__ _Float128
756 __complex_sqrt(__complex__ _Float128 __z) {
return __builtin_csqrtl(__z); }
758 inline __complex__ _Float128
759 __complex_tan(__complex__ _Float128 __z) {
return __builtin_ctanl(__z); }
761 inline __complex__ _Float128
762 __complex_tanh(__complex__ _Float128 __z) {
return __builtin_ctanhl(__z); }
764 inline __complex__ _Float128
765 __complex_pow(__complex__ _Float128 __x, __complex__ _Float128 __y)
766 {
return __builtin_cpowl(__x, __y); }
767#elif defined(__STDCPP_FLOAT128_T__) && defined(_GLIBCXX_HAVE_FLOAT128_MATH)
769 __complex_abs(__complex__ _Float128 __z) {
return __builtin_cabsf128(__z); }
772 __complex_arg(__complex__ _Float128 __z) {
return __builtin_cargf128(__z); }
774 inline __complex__ _Float128
775 __complex_cos(__complex__ _Float128 __z) {
return __builtin_ccosf128(__z); }
777 inline __complex__ _Float128
778 __complex_cosh(__complex__ _Float128 __z) {
return __builtin_ccoshf128(__z); }
780 inline __complex__ _Float128
781 __complex_exp(__complex__ _Float128 __z) {
return __builtin_cexpf128(__z); }
783 inline __complex__ _Float128
784 __complex_log(__complex__ _Float128 __z) {
return __builtin_clogf128(__z); }
786 inline __complex__ _Float128
787 __complex_sin(__complex__ _Float128 __z) {
return __builtin_csinf128(__z); }
789 inline __complex__ _Float128
790 __complex_sinh(__complex__ _Float128 __z) {
return __builtin_csinhf128(__z); }
792 inline __complex__ _Float128
793 __complex_sqrt(__complex__ _Float128 __z) {
return __builtin_csqrtf128(__z); }
795 inline __complex__ _Float128
796 __complex_tan(__complex__ _Float128 __z) {
return __builtin_ctanf128(__z); }
798 inline __complex__ _Float128
799 __complex_tanh(__complex__ _Float128 __z) {
return __builtin_ctanhf128(__z); }
801 inline __complex__ _Float128
802 __complex_pow(__complex__ _Float128 __x, __complex__ _Float128 __y)
803 {
return __builtin_cpowf128(__x, __y); }
806#if defined(__STDCPP_BFLOAT16_T__) && defined(_GLIBCXX_FLOAT_IS_IEEE_BINARY32)
807 inline __gnu_cxx::__bfloat16_t
808 __complex_abs(__complex__
decltype(0.0bf16) __z)
809 {
return __gnu_cxx::__bfloat16_t(__builtin_cabsf(__z)); }
811 inline __gnu_cxx::__bfloat16_t
812 __complex_arg(__complex__
decltype(0.0bf16) __z)
813 {
return __gnu_cxx::__bfloat16_t(__builtin_cargf(__z)); }
815 inline __complex__
decltype(0.0bf16)
816 __complex_cos(__complex__
decltype(0.0bf16) __z)
817 {
return static_cast<__complex__ decltype(0.0bf16)
>(__builtin_ccosf(__z)); }
819 inline __complex__
decltype(0.0bf16)
820 __complex_cosh(__complex__
decltype(0.0bf16) __z)
821 {
return static_cast<__complex__ decltype(0.0bf16)
>(__builtin_ccoshf(__z)); }
823 inline __complex__
decltype(0.0bf16)
824 __complex_exp(__complex__
decltype(0.0bf16) __z)
825 {
return static_cast<__complex__ decltype(0.0bf16)
>(__builtin_cexpf(__z)); }
827 inline __complex__
decltype(0.0bf16)
828 __complex_log(__complex__
decltype(0.0bf16) __z)
829 {
return static_cast<__complex__ decltype(0.0bf16)
>(__builtin_clogf(__z)); }
831 inline __complex__
decltype(0.0bf16)
832 __complex_sin(__complex__
decltype(0.0bf16) __z)
833 {
return static_cast<__complex__ decltype(0.0bf16)
>(__builtin_csinf(__z)); }
835 inline __complex__
decltype(0.0bf16)
836 __complex_sinh(__complex__
decltype(0.0bf16) __z)
837 {
return static_cast<__complex__ decltype(0.0bf16)
>(__builtin_csinhf(__z)); }
839 inline __complex__
decltype(0.0bf16)
840 __complex_sqrt(__complex__
decltype(0.0bf16) __z)
841 {
return static_cast<__complex__ decltype(0.0bf16)
>(__builtin_csqrtf(__z)); }
843 inline __complex__
decltype(0.0bf16)
844 __complex_tan(__complex__
decltype(0.0bf16) __z)
845 {
return static_cast<__complex__ decltype(0.0bf16)
>(__builtin_ctanf(__z)); }
847 inline __complex__
decltype(0.0bf16)
848 __complex_tanh(__complex__
decltype(0.0bf16) __z)
849 {
return static_cast<__complex__ decltype(0.0bf16)
>(__builtin_ctanhf(__z)); }
851 inline __complex__
decltype(0.0bf16)
852 __complex_pow(__complex__
decltype(0.0bf16) __x,
853 __complex__
decltype(0.0bf16) __y)
854 {
return static_cast<__complex__ decltype(0.0bf16)
>(__builtin_cpowf(__x,
860 template<
typename _Tp>
862 __complex_abs(
const complex<_Tp>& __z)
864 _Tp __x = __z.real();
865 _Tp __y = __z.imag();
871 return __s *
sqrt(__x * __x + __y * __y);
874#if _GLIBCXX_USE_C99_COMPLEX
876 __complex_abs(__complex__
float __z) {
return __builtin_cabsf(__z); }
879 __complex_abs(__complex__
double __z) {
return __builtin_cabs(__z); }
882 __complex_abs(
const __complex__
long double& __z)
883 {
return __builtin_cabsl(__z); }
885 template<
typename _Tp>
887 abs(
const complex<_Tp>& __z) {
return __complex_abs(__z.__rep()); }
889 template<
typename _Tp>
896 template<
typename _Tp>
898 __complex_arg(
const complex<_Tp>& __z)
899 {
return atan2(__z.imag(), __z.real()); }
901#if _GLIBCXX_USE_C99_COMPLEX
903 __complex_arg(__complex__
float __z) {
return __builtin_cargf(__z); }
906 __complex_arg(__complex__
double __z) {
return __builtin_carg(__z); }
909 __complex_arg(
const __complex__
long double& __z)
910 {
return __builtin_cargl(__z); }
912 template<
typename _Tp>
914 arg(
const complex<_Tp>& __z) {
return __complex_arg(__z.__rep()); }
916 template<
typename _Tp>
929 template<
typename _Tp>
930 static inline _GLIBCXX20_CONSTEXPR _Tp _S_do_it(
const complex<_Tp>& __z)
932 const _Tp __x = __z.real();
933 const _Tp __y = __z.imag();
934 return __x * __x + __y * __y;
939 struct _Norm_helper<true>
941 template<
typename _Tp>
942 static inline _GLIBCXX20_CONSTEXPR _Tp _S_do_it(
const complex<_Tp>& __z)
946 const _Tp __x = __z.real();
947 const _Tp __y = __z.imag();
948 return __x * __x + __y * __y;
952 template<
typename _Tp>
953 inline _GLIBCXX20_CONSTEXPR _Tp
956 return _Norm_helper<__is_floating<_Tp>::__value
957 && !_GLIBCXX_FAST_MATH>::_S_do_it(__z);
960 template<
typename _Tp>
962 polar(
const _Tp& __rho,
const _Tp& __theta)
964 __glibcxx_assert( __rho >= 0 );
968 template<
typename _Tp>
969 inline _GLIBCXX20_CONSTEXPR complex<_Tp>
976 template<
typename _Tp>
978 __complex_cos(
const complex<_Tp>& __z)
980 const _Tp __x = __z.real();
981 const _Tp __y = __z.imag();
982 return complex<_Tp>(cos(__x) * cosh(__y), -sin(__x) * sinh(__y));
985#if _GLIBCXX_USE_C99_COMPLEX
986 inline __complex__
float
987 __complex_cos(__complex__
float __z) {
return __builtin_ccosf(__z); }
989 inline __complex__
double
990 __complex_cos(__complex__
double __z) {
return __builtin_ccos(__z); }
992 inline __complex__
long double
993 __complex_cos(
const __complex__
long double& __z)
994 {
return __builtin_ccosl(__z); }
996 template<
typename _Tp>
998 cos(
const complex<_Tp>& __z) {
return __complex_cos(__z.__rep()); }
1000 template<
typename _Tp>
1006 template<
typename _Tp>
1008 __complex_cosh(
const complex<_Tp>& __z)
1010 const _Tp __x = __z.real();
1011 const _Tp __y = __z.imag();
1012 return complex<_Tp>(cosh(__x) * cos(__y), sinh(__x) * sin(__y));
1015#if _GLIBCXX_USE_C99_COMPLEX
1016 inline __complex__
float
1017 __complex_cosh(__complex__
float __z) {
return __builtin_ccoshf(__z); }
1019 inline __complex__
double
1020 __complex_cosh(__complex__
double __z) {
return __builtin_ccosh(__z); }
1022 inline __complex__
long double
1023 __complex_cosh(
const __complex__
long double& __z)
1024 {
return __builtin_ccoshl(__z); }
1026 template<
typename _Tp>
1028 cosh(
const complex<_Tp>& __z) {
return __complex_cosh(__z.__rep()); }
1030 template<
typename _Tp>
1036 template<
typename _Tp>
1038 __complex_exp(
const complex<_Tp>& __z)
1039 {
return std::polar<_Tp>(exp(__z.real()), __z.imag()); }
1041#if _GLIBCXX_USE_C99_COMPLEX
1042 inline __complex__
float
1043 __complex_exp(__complex__
float __z) {
return __builtin_cexpf(__z); }
1045 inline __complex__
double
1046 __complex_exp(__complex__
double __z) {
return __builtin_cexp(__z); }
1048 inline __complex__
long double
1049 __complex_exp(
const __complex__
long double& __z)
1050 {
return __builtin_cexpl(__z); }
1052 template<
typename _Tp>
1054 exp(
const complex<_Tp>& __z) {
return __complex_exp(__z.__rep()); }
1056 template<
typename _Tp>
1063 template<
typename _Tp>
1065 __complex_log(
const complex<_Tp>& __z)
1068#if _GLIBCXX_USE_C99_COMPLEX
1069 inline __complex__
float
1070 __complex_log(__complex__
float __z) {
return __builtin_clogf(__z); }
1072 inline __complex__
double
1073 __complex_log(__complex__
double __z) {
return __builtin_clog(__z); }
1075 inline __complex__
long double
1076 __complex_log(
const __complex__
long double& __z)
1077 {
return __builtin_clogl(__z); }
1079 template<
typename _Tp>
1081 log(
const complex<_Tp>& __z) {
return __complex_log(__z.__rep()); }
1083 template<
typename _Tp>
1088 template<
typename _Tp>
1094 template<
typename _Tp>
1096 __complex_sin(
const complex<_Tp>& __z)
1098 const _Tp __x = __z.real();
1099 const _Tp __y = __z.imag();
1100 return complex<_Tp>(sin(__x) * cosh(__y), cos(__x) * sinh(__y));
1103#if _GLIBCXX_USE_C99_COMPLEX
1104 inline __complex__
float
1105 __complex_sin(__complex__
float __z) {
return __builtin_csinf(__z); }
1107 inline __complex__
double
1108 __complex_sin(__complex__
double __z) {
return __builtin_csin(__z); }
1110 inline __complex__
long double
1111 __complex_sin(
const __complex__
long double& __z)
1112 {
return __builtin_csinl(__z); }
1114 template<
typename _Tp>
1116 sin(
const complex<_Tp>& __z) {
return __complex_sin(__z.__rep()); }
1118 template<
typename _Tp>
1124 template<
typename _Tp>
1126 __complex_sinh(
const complex<_Tp>& __z)
1128 const _Tp __x = __z.real();
1129 const _Tp __y = __z.imag();
1130 return complex<_Tp>(sinh(__x) * cos(__y), cosh(__x) * sin(__y));
1133#if _GLIBCXX_USE_C99_COMPLEX
1134 inline __complex__
float
1135 __complex_sinh(__complex__
float __z) {
return __builtin_csinhf(__z); }
1137 inline __complex__
double
1138 __complex_sinh(__complex__
double __z) {
return __builtin_csinh(__z); }
1140 inline __complex__
long double
1141 __complex_sinh(
const __complex__
long double& __z)
1142 {
return __builtin_csinhl(__z); }
1144 template<
typename _Tp>
1146 sinh(
const complex<_Tp>& __z) {
return __complex_sinh(__z.__rep()); }
1148 template<
typename _Tp>
1155 template<
typename _Tp>
1157 __complex_sqrt(
const complex<_Tp>& __z)
1159 _Tp __x = __z.real();
1160 _Tp __y = __z.imag();
1164 _Tp __t = sqrt(abs(__y) / 2);
1165 return complex<_Tp>(__t, __y < _Tp() ? -__t : __t);
1172 ? complex<_Tp>(__u, __y / __t)
1173 : complex<_Tp>(
abs(__y) / __t, __y < _Tp() ? -__u : __u);
1177#if _GLIBCXX_USE_C99_COMPLEX
1178 inline __complex__
float
1179 __complex_sqrt(__complex__
float __z) {
return __builtin_csqrtf(__z); }
1181 inline __complex__
double
1182 __complex_sqrt(__complex__
double __z) {
return __builtin_csqrt(__z); }
1184 inline __complex__
long double
1185 __complex_sqrt(
const __complex__
long double& __z)
1186 {
return __builtin_csqrtl(__z); }
1188 template<
typename _Tp>
1190 sqrt(
const complex<_Tp>& __z) {
return __complex_sqrt(__z.__rep()); }
1192 template<
typename _Tp>
1199 template<
typename _Tp>
1201 __complex_tan(
const complex<_Tp>& __z)
1204#if _GLIBCXX_USE_C99_COMPLEX
1205 inline __complex__
float
1206 __complex_tan(__complex__
float __z) {
return __builtin_ctanf(__z); }
1208 inline __complex__
double
1209 __complex_tan(__complex__
double __z) {
return __builtin_ctan(__z); }
1211 inline __complex__
long double
1212 __complex_tan(
const __complex__
long double& __z)
1213 {
return __builtin_ctanl(__z); }
1215 template<
typename _Tp>
1217 tan(
const complex<_Tp>& __z) {
return __complex_tan(__z.__rep()); }
1219 template<
typename _Tp>
1227 template<
typename _Tp>
1229 __complex_tanh(
const complex<_Tp>& __z)
1232#if _GLIBCXX_USE_C99_COMPLEX
1233 inline __complex__
float
1234 __complex_tanh(__complex__
float __z) {
return __builtin_ctanhf(__z); }
1236 inline __complex__
double
1237 __complex_tanh(__complex__
double __z) {
return __builtin_ctanh(__z); }
1239 inline __complex__
long double
1240 __complex_tanh(
const __complex__
long double& __z)
1241 {
return __builtin_ctanhl(__z); }
1243 template<
typename _Tp>
1245 tanh(
const complex<_Tp>& __z) {
return __complex_tanh(__z.__rep()); }
1247 template<
typename _Tp>
1256 template<
typename _Tp>
1258 __complex_pow_unsigned(complex<_Tp> __x,
unsigned __n)
1260 complex<_Tp> __y = __n % 2 ? __x : complex<_Tp>(1);
1278 template<
typename _Tp>
1283 ?
complex<_Tp>(1) / std::__complex_pow_unsigned(__z, -(
unsigned)__n)
1284 : std::__complex_pow_unsigned(__z, __n);
1287 template<
typename _Tp>
1291#if ! _GLIBCXX_USE_C99_COMPLEX
1295 if (__x.imag() == _Tp() && __x.real() > _Tp())
1296 return pow(__x.real(), __y);
1299 return std::polar<_Tp>(
exp(__y * __t.real()), __y * __t.imag());
1302 template<
typename _Tp>
1304 __complex_pow(
const complex<_Tp>& __x,
const complex<_Tp>& __y)
1305 {
return __x == _Tp() ? _Tp() :
std::exp(__y *
std::log(__x)); }
1307#if _GLIBCXX_USE_C99_COMPLEX
1308 inline __complex__
float
1309 __complex_pow(__complex__
float __x, __complex__
float __y)
1310 {
return __builtin_cpowf(__x, __y); }
1312 inline __complex__
double
1313 __complex_pow(__complex__
double __x, __complex__
double __y)
1314 {
return __builtin_cpow(__x, __y); }
1316 inline __complex__
long double
1317 __complex_pow(
const __complex__
long double& __x,
1318 const __complex__
long double& __y)
1319 {
return __builtin_cpowl(__x, __y); }
1321 template<
typename _Tp>
1323 pow(
const complex<_Tp>& __x,
const complex<_Tp>& __y)
1324 {
return __complex_pow(__x.__rep(), __y.__rep()); }
1326 template<
typename _Tp>
1329 {
return __complex_pow(__x, __y); }
1332 template<
typename _Tp>
1336 return __x > _Tp() ? std::polar<_Tp>(
pow(__x, __y.real()),
1337 __y.imag() *
log(__x))
1348 typedef __complex__
float _ComplexT;
1350 _GLIBCXX_CONSTEXPR
complex(_ComplexT __z) : _M_value(__z) { }
1352 _GLIBCXX_CONSTEXPR
complex(
float __r = 0.0f,
float __i = 0.0f)
1353#if __cplusplus >= 201103L
1354 : _M_value{ __r, __i } { }
1357 __real__ _M_value = __r;
1358 __imag__ _M_value = __i;
1362#if __cplusplus >= 201103L
1366#if __cplusplus > 202002L
1367 template<
typename _Up>
1368 explicit(!
requires(_Up __u) { value_type{__u}; })
1376#if __cplusplus >= 201103L
1379 __attribute ((__abi_tag__ (
"cxx11")))
1381 real()
const {
return __real__ _M_value; }
1383 __attribute ((__abi_tag__ (
"cxx11")))
1385 imag()
const {
return __imag__ _M_value; }
1388 real() {
return __real__ _M_value; }
1391 real()
const {
return __real__ _M_value; }
1394 imag() {
return __imag__ _M_value; }
1397 imag()
const {
return __imag__ _M_value; }
1402 _GLIBCXX20_CONSTEXPR
void
1403 real(
float __val) { __real__ _M_value = __val; }
1405 _GLIBCXX20_CONSTEXPR
void
1406 imag(
float __val) { __imag__ _M_value = __val; }
1445#if __cplusplus >= 201103L
1449 template<
typename _Tp>
1453 __real__ _M_value = __z.real();
1454 __imag__ _M_value = __z.imag();
1458 template<
typename _Tp>
1462 _M_value += __z.__rep();
1470 _M_value -= __z.__rep();
1478 const _ComplexT __t = __z.__rep();
1487 const _ComplexT __t = __z.__rep();
1492 _GLIBCXX_CONSTEXPR _ComplexT __rep()
const {
return _M_value; }
1505 typedef __complex__
double _ComplexT;
1507 _GLIBCXX_CONSTEXPR
complex(_ComplexT __z) : _M_value(__z) { }
1509 _GLIBCXX_CONSTEXPR
complex(
double __r = 0.0,
double __i = 0.0)
1510#if __cplusplus >= 201103L
1511 : _M_value{ __r, __i } { }
1514 __real__ _M_value = __r;
1515 __imag__ _M_value = __i;
1519#if __cplusplus >= 201103L
1523#if __cplusplus > 202002L
1524 template<
typename _Up>
1525 explicit(!
requires(_Up __u) { value_type{__u}; })
1530 : _M_value(__z.__rep()) { }
1535#if __cplusplus >= 201103L
1538 __attribute ((__abi_tag__ (
"cxx11")))
1540 real()
const {
return __real__ _M_value; }
1542 __attribute ((__abi_tag__ (
"cxx11")))
1544 imag()
const {
return __imag__ _M_value; }
1547 real() {
return __real__ _M_value; }
1550 real()
const {
return __real__ _M_value; }
1553 imag() {
return __imag__ _M_value; }
1556 imag()
const {
return __imag__ _M_value; }
1561 _GLIBCXX20_CONSTEXPR
void
1562 real(
double __val) { __real__ _M_value = __val; }
1564 _GLIBCXX20_CONSTEXPR
void
1565 imag(
double __val) { __imag__ _M_value = __val; }
1603#if __cplusplus >= 201103L
1607 template<
typename _Tp>
1611 _M_value = __z.__rep();
1615 template<
typename _Tp>
1619 _M_value += __z.__rep();
1623 template<
typename _Tp>
1627 _M_value -= __z.__rep();
1631 template<
typename _Tp>
1635 const _ComplexT __t = __z.__rep();
1640 template<
typename _Tp>
1644 const _ComplexT __t = __z.__rep();
1649 _GLIBCXX_CONSTEXPR _ComplexT __rep()
const {
return _M_value; }
1662 typedef __complex__
long double _ComplexT;
1664 _GLIBCXX_CONSTEXPR
complex(_ComplexT __z) : _M_value(__z) { }
1666 _GLIBCXX_CONSTEXPR
complex(
long double __r = 0.0L,
1667 long double __i = 0.0L)
1668#if __cplusplus >= 201103L
1669 : _M_value{ __r, __i } { }
1672 __real__ _M_value = __r;
1673 __imag__ _M_value = __i;
1677#if __cplusplus >= 201103L
1681#if __cplusplus > 202002L
1682 template<
typename _Up>
1683 explicit(!
requires(_Up __u) { value_type{__u}; })
1688 : _M_value(__z.__rep()) { }
1691 : _M_value(__z.__rep()) { }
1694#if __cplusplus >= 201103L
1697 __attribute ((__abi_tag__ (
"cxx11")))
1698 constexpr long double
1699 real()
const {
return __real__ _M_value; }
1701 __attribute ((__abi_tag__ (
"cxx11")))
1702 constexpr long double
1703 imag()
const {
return __imag__ _M_value; }
1706 real() {
return __real__ _M_value; }
1709 real()
const {
return __real__ _M_value; }
1712 imag() {
return __imag__ _M_value; }
1715 imag()
const {
return __imag__ _M_value; }
1720 _GLIBCXX20_CONSTEXPR
void
1721 real(
long double __val) { __real__ _M_value = __val; }
1723 _GLIBCXX20_CONSTEXPR
void
1724 imag(
long double __val) { __imag__ _M_value = __val; }
1762#if __cplusplus >= 201103L
1766 template<
typename _Tp>
1770 _M_value = __z.__rep();
1774 template<
typename _Tp>
1778 _M_value += __z.__rep();
1782 template<
typename _Tp>
1786 _M_value -= __z.__rep();
1790 template<
typename _Tp>
1794 const _ComplexT __t = __z.__rep();
1799 template<
typename _Tp>
1803 const _ComplexT __t = __z.__rep();
1808 _GLIBCXX_CONSTEXPR _ComplexT __rep()
const {
return _M_value; }
1814#if __cplusplus > 202002L
1815 template<
typename _Tp>
1816 struct __complex_type
1819#ifdef __STDCPP_FLOAT16_T__
1821 struct __complex_type<_Float16>
1822 {
typedef __complex__ _Float16 type; };
1825#ifdef __STDCPP_FLOAT32_T__
1827 struct __complex_type<_Float32>
1828 {
typedef __complex__ _Float32 type; };
1831#ifdef __STDCPP_FLOAT64_T__
1833 struct __complex_type<_Float64>
1834 {
typedef __complex__ _Float64 type; };
1837#ifdef __STDCPP_FLOAT128_T__
1839 struct __complex_type<_Float128>
1840 {
typedef __complex__ _Float128 type; };
1843#ifdef __STDCPP_BFLOAT16_T__
1845 struct __complex_type<
__gnu_cxx::__bfloat16_t>
1846 {
typedef __complex__
decltype(0.0bf16) type; };
1849 template<
typename _Tp>
1850 requires requires {
typename __complex_type<_Tp>::type; }
1855 typedef typename std::__complex_type<_Tp>::type _ComplexT;
1857 constexpr complex(_ComplexT __z) : _M_value(__z) { }
1859 constexpr complex(_Tp __r = _Tp(), _Tp __i = _Tp())
1860 : _M_value{ __r, __i } { }
1862 template<
typename _Up>
1863 explicit(!
requires(_Up __u) {
value_type{__u}; })
1864 constexpr complex(
const complex<_Up>& __z)
1868 real()
const {
return __real__ _M_value; }
1871 imag()
const {
return __imag__ _M_value; }
1874 real(_Tp __val) { __real__ _M_value = __val; }
1877 imag(_Tp __val) { __imag__ _M_value = __val; }
1916 constexpr complex(
const complex&) =
default;
1919 template<
typename _Up>
1923 __real__ _M_value = __z.real();
1924 __imag__ _M_value = __z.imag();
1928 template<
typename _Up>
1932 _M_value += __z.__rep();
1940 _M_value -= __z.__rep();
1948 const _ComplexT __t = __z.__rep();
1957 const _ComplexT __t = __z.__rep();
1962 constexpr _ComplexT __rep()
const {
return _M_value; }
1969#if __cplusplus <= 202002L
1972 inline _GLIBCXX_CONSTEXPR
1974 : _M_value(__z.__rep()) { }
1976 inline _GLIBCXX_CONSTEXPR
1978 : _M_value(__z.__rep()) { }
1980 inline _GLIBCXX_CONSTEXPR
1982 : _M_value(__z.__rep()) { }
1988#if _GLIBCXX_EXTERN_TEMPLATE
1996#ifdef _GLIBCXX_USE_WCHAR_T
2008_GLIBCXX_END_NAMESPACE_VERSION
2011#if __cplusplus >= 201103L
2013namespace std _GLIBCXX_VISIBILITY(
default)
2015_GLIBCXX_BEGIN_NAMESPACE_VERSION
2028 template<
typename _Tp>
2033 const _Tp __pi_2 = 1.5707963267948966192313216916397514L;
2037#if _GLIBCXX_USE_C99_COMPLEX_TR1
2038#if defined(__STDCPP_FLOAT16_T__) && defined(_GLIBCXX_FLOAT_IS_IEEE_BINARY32)
2039 inline __complex__ _Float16
2040 __complex_acos(__complex__ _Float16 __z)
2041 {
return static_cast<__complex__ _Float16
>(__builtin_cacosf(__z)); }
2043 inline __complex__ _Float16
2044 __complex_asin(__complex__ _Float16 __z)
2045 {
return static_cast<__complex__ _Float16
>(__builtin_casinf(__z)); }
2047 inline __complex__ _Float16
2048 __complex_atan(__complex__ _Float16 __z)
2049 {
return static_cast<__complex__ _Float16
>(__builtin_catanf(__z)); }
2051 inline __complex__ _Float16
2052 __complex_acosh(__complex__ _Float16 __z)
2053 {
return static_cast<__complex__ _Float16
>(__builtin_cacoshf(__z)); }
2055 inline __complex__ _Float16
2056 __complex_asinh(__complex__ _Float16 __z)
2057 {
return static_cast<__complex__ _Float16
>(__builtin_casinhf(__z)); }
2059 inline __complex__ _Float16
2060 __complex_atanh(__complex__ _Float16 __z)
2061 {
return static_cast<__complex__ _Float16
>(__builtin_catanhf(__z)); }
2064#if defined(__STDCPP_FLOAT32_T__) && defined(_GLIBCXX_FLOAT_IS_IEEE_BINARY32)
2065 inline __complex__ _Float32
2066 __complex_acos(__complex__ _Float32 __z)
2067 {
return __builtin_cacosf(__z); }
2069 inline __complex__ _Float32
2070 __complex_asin(__complex__ _Float32 __z)
2071 {
return __builtin_casinf(__z); }
2073 inline __complex__ _Float32
2074 __complex_atan(__complex__ _Float32 __z)
2075 {
return __builtin_catanf(__z); }
2077 inline __complex__ _Float32
2078 __complex_acosh(__complex__ _Float32 __z)
2079 {
return __builtin_cacoshf(__z); }
2081 inline __complex__ _Float32
2082 __complex_asinh(__complex__ _Float32 __z)
2083 {
return __builtin_casinhf(__z); }
2085 inline __complex__ _Float32
2086 __complex_atanh(__complex__ _Float32 __z)
2087 {
return __builtin_catanhf(__z); }
2090#if defined(__STDCPP_FLOAT64_T__) && defined(_GLIBCXX_DOUBLE_IS_IEEE_BINARY64)
2091 inline __complex__ _Float64
2092 __complex_acos(__complex__ _Float64 __z)
2093 {
return __builtin_cacos(__z); }
2095 inline __complex__ _Float64
2096 __complex_asin(__complex__ _Float64 __z)
2097 {
return __builtin_casin(__z); }
2099 inline __complex__ _Float64
2100 __complex_atan(__complex__ _Float64 __z)
2101 {
return __builtin_catan(__z); }
2103 inline __complex__ _Float64
2104 __complex_acosh(__complex__ _Float64 __z)
2105 {
return __builtin_cacosh(__z); }
2107 inline __complex__ _Float64
2108 __complex_asinh(__complex__ _Float64 __z)
2109 {
return __builtin_casinh(__z); }
2111 inline __complex__ _Float64
2112 __complex_atanh(__complex__ _Float64 __z)
2113 {
return __builtin_catanh(__z); }
2116#if defined(__STDCPP_FLOAT128_T__) && defined(_GLIBCXX_LDOUBLE_IS_IEEE_BINARY128)
2117 inline __complex__ _Float128
2118 __complex_acos(__complex__ _Float128 __z)
2119 {
return __builtin_cacosl(__z); }
2121 inline __complex__ _Float128
2122 __complex_asin(__complex__ _Float128 __z)
2123 {
return __builtin_casinl(__z); }
2125 inline __complex__ _Float128
2126 __complex_atan(__complex__ _Float128 __z)
2127 {
return __builtin_catanl(__z); }
2129 inline __complex__ _Float128
2130 __complex_acosh(__complex__ _Float128 __z)
2131 {
return __builtin_cacoshl(__z); }
2133 inline __complex__ _Float128
2134 __complex_asinh(__complex__ _Float128 __z)
2135 {
return __builtin_casinhl(__z); }
2137 inline __complex__ _Float128
2138 __complex_atanh(__complex__ _Float128 __z)
2139 {
return __builtin_catanhl(__z); }
2140#elif defined(__STDCPP_FLOAT128_T__) && defined(_GLIBCXX_HAVE_FLOAT128_MATH)
2141 inline __complex__ _Float128
2142 __complex_acos(__complex__ _Float128 __z)
2143 {
return __builtin_cacosf128(__z); }
2145 inline __complex__ _Float128
2146 __complex_asin(__complex__ _Float128 __z)
2147 {
return __builtin_casinf128(__z); }
2149 inline __complex__ _Float128
2150 __complex_atan(__complex__ _Float128 __z)
2151 {
return __builtin_catanf128(__z); }
2153 inline __complex__ _Float128
2154 __complex_acosh(__complex__ _Float128 __z)
2155 {
return __builtin_cacoshf128(__z); }
2157 inline __complex__ _Float128
2158 __complex_asinh(__complex__ _Float128 __z)
2159 {
return __builtin_casinhf128(__z); }
2161 inline __complex__ _Float128
2162 __complex_atanh(__complex__ _Float128 __z)
2163 {
return __builtin_catanhf128(__z); }
2166#if defined(__STDCPP_BFLOAT16_T__) && defined(_GLIBCXX_FLOAT_IS_IEEE_BINARY32)
2167 inline __complex__
decltype(0.0bf16)
2168 __complex_acos(__complex__
decltype(0.0bf16) __z)
2169 {
return static_cast<__complex__ decltype(0.0bf16)
>(__builtin_cacosf(__z)); }
2171 inline __complex__
decltype(0.0bf16)
2172 __complex_asin(__complex__
decltype(0.0bf16) __z)
2173 {
return static_cast<__complex__ decltype(0.0bf16)
>(__builtin_casinf(__z)); }
2175 inline __complex__
decltype(0.0bf16)
2176 __complex_atan(__complex__
decltype(0.0bf16) __z)
2177 {
return static_cast<__complex__ decltype(0.0bf16)
>(__builtin_catanf(__z)); }
2179 inline __complex__
decltype(0.0bf16)
2180 __complex_acosh(__complex__
decltype(0.0bf16) __z)
2181 {
return static_cast<__complex__ decltype(0.0bf16)
>(__builtin_cacoshf(__z)); }
2183 inline __complex__
decltype(0.0bf16)
2184 __complex_asinh(__complex__
decltype(0.0bf16) __z)
2185 {
return static_cast<__complex__ decltype(0.0bf16)
>(__builtin_casinhf(__z)); }
2187 inline __complex__
decltype(0.0bf16)
2188 __complex_atanh(__complex__
decltype(0.0bf16) __z)
2189 {
return static_cast<__complex__ decltype(0.0bf16)
>(__builtin_catanhf(__z)); }
2193#if _GLIBCXX_USE_C99_COMPLEX_TR1
2194 inline __complex__
float
2195 __complex_acos(__complex__
float __z)
2196 {
return __builtin_cacosf(__z); }
2198 inline __complex__
double
2199 __complex_acos(__complex__
double __z)
2200 {
return __builtin_cacos(__z); }
2202 inline __complex__
long double
2203 __complex_acos(
const __complex__
long double& __z)
2204 {
return __builtin_cacosl(__z); }
2206 template<
typename _Tp>
2209 {
return __complex_acos(__z.__rep()); }
2214 template<
typename _Tp>
2217 {
return __complex_acos(__z); }
2220 template<
typename _Tp>
2225 __t = std::asinh(__t);
2229#if _GLIBCXX_USE_C99_COMPLEX_TR1
2230 inline __complex__
float
2231 __complex_asin(__complex__
float __z)
2232 {
return __builtin_casinf(__z); }
2234 inline __complex__
double
2235 __complex_asin(__complex__
double __z)
2236 {
return __builtin_casin(__z); }
2238 inline __complex__
long double
2239 __complex_asin(
const __complex__
long double& __z)
2240 {
return __builtin_casinl(__z); }
2242 template<
typename _Tp>
2245 {
return __complex_asin(__z.__rep()); }
2250 template<
typename _Tp>
2253 {
return __complex_asin(__z); }
2256 template<
typename _Tp>
2260 const _Tp __r2 = __z.real() * __z.real();
2261 const _Tp __x = _Tp(1.0) - __r2 - __z.imag() * __z.imag();
2263 _Tp __num = __z.imag() + _Tp(1.0);
2264 _Tp __den = __z.imag() - _Tp(1.0);
2266 __num = __r2 + __num * __num;
2267 __den = __r2 + __den * __den;
2270 _Tp(0.25) *
log(__num / __den));
2273#if _GLIBCXX_USE_C99_COMPLEX_TR1
2274 inline __complex__
float
2275 __complex_atan(__complex__
float __z)
2276 {
return __builtin_catanf(__z); }
2278 inline __complex__
double
2279 __complex_atan(__complex__
double __z)
2280 {
return __builtin_catan(__z); }
2282 inline __complex__
long double
2283 __complex_atan(
const __complex__
long double& __z)
2284 {
return __builtin_catanl(__z); }
2286 template<
typename _Tp>
2289 {
return __complex_atan(__z.__rep()); }
2294 template<
typename _Tp>
2297 {
return __complex_atan(__z); }
2300 template<
typename _Tp>
2306 +
std::sqrt(_Tp(0.5) * (__z - _Tp(1.0))));
2309#if _GLIBCXX_USE_C99_COMPLEX_TR1
2310 inline __complex__
float
2311 __complex_acosh(__complex__
float __z)
2312 {
return __builtin_cacoshf(__z); }
2314 inline __complex__
double
2315 __complex_acosh(__complex__
double __z)
2316 {
return __builtin_cacosh(__z); }
2318 inline __complex__
long double
2319 __complex_acosh(
const __complex__
long double& __z)
2320 {
return __builtin_cacoshl(__z); }
2322 template<
typename _Tp>
2325 {
return __complex_acosh(__z.__rep()); }
2330 template<
typename _Tp>
2333 {
return __complex_acosh(__z); }
2336 template<
typename _Tp>
2341 * (__z.real() + __z.imag()) + _Tp(1.0),
2342 _Tp(2.0) * __z.real() * __z.imag());
2348#if _GLIBCXX_USE_C99_COMPLEX_TR1
2349 inline __complex__
float
2350 __complex_asinh(__complex__
float __z)
2351 {
return __builtin_casinhf(__z); }
2353 inline __complex__
double
2354 __complex_asinh(__complex__
double __z)
2355 {
return __builtin_casinh(__z); }
2357 inline __complex__
long double
2358 __complex_asinh(
const __complex__
long double& __z)
2359 {
return __builtin_casinhl(__z); }
2361 template<
typename _Tp>
2364 {
return __complex_asinh(__z.__rep()); }
2369 template<
typename _Tp>
2372 {
return __complex_asinh(__z); }
2375 template<
typename _Tp>
2379 const _Tp __i2 = __z.imag() * __z.imag();
2380 const _Tp __x = _Tp(1.0) - __i2 - __z.real() * __z.real();
2382 _Tp __num = _Tp(1.0) + __z.real();
2383 _Tp __den = _Tp(1.0) - __z.real();
2385 __num = __i2 + __num * __num;
2386 __den = __i2 + __den * __den;
2389 _Tp(0.5) * atan2(_Tp(2.0) * __z.imag(), __x));
2392#if _GLIBCXX_USE_C99_COMPLEX_TR1
2393 inline __complex__
float
2394 __complex_atanh(__complex__
float __z)
2395 {
return __builtin_catanhf(__z); }
2397 inline __complex__
double
2398 __complex_atanh(__complex__
double __z)
2399 {
return __builtin_catanh(__z); }
2401 inline __complex__
long double
2402 __complex_atanh(
const __complex__
long double& __z)
2403 {
return __builtin_catanhl(__z); }
2405 template<
typename _Tp>
2408 {
return __complex_atanh(__z.__rep()); }
2413 template<
typename _Tp>
2416 {
return __complex_atanh(__z); }
2419 template<
typename _Tp>
2428 template<
typename _Tp>
2429 inline typename __gnu_cxx::__promote<_Tp>::__type
2432 typedef typename __gnu_cxx::__promote<_Tp>::__type __type;
2433#if (_GLIBCXX11_USE_C99_MATH && !_GLIBCXX_USE_C99_FP_MACROS_DYNAMIC)
2434 return std::signbit(__x) ? __type(3.1415926535897932384626433832795029L)
2441 template<
typename _Tp>
2442 _GLIBCXX_CONSTEXPR
inline typename __gnu_cxx::__promote<_Tp>::__type
2446 template<
typename _Tp>
2447 _GLIBCXX20_CONSTEXPR
inline typename __gnu_cxx::__promote<_Tp>::__type
2450 typedef typename __gnu_cxx::__promote<_Tp>::__type __type;
2451 return __type(__x) * __type(__x);
2454 template<
typename _Tp>
2455 _GLIBCXX_CONSTEXPR
inline typename __gnu_cxx::__promote<_Tp>::__type
2459 template<
typename _Tp,
typename _Up>
2463 typedef typename __gnu_cxx::__promote_2<_Tp, _Up>::__type __type;
2467 template<
typename _Tp,
typename _Up>
2471 typedef typename __gnu_cxx::__promote_2<_Tp, _Up>::__type __type;
2475 template<
typename _Tp,
typename _Up>
2479 typedef typename __gnu_cxx::__promote_2<_Tp, _Up>::__type __type;
2486 template<
typename _Tp>
2490 template<
typename _Tp>
2495#if _GLIBCXX_USE_C99_COMPLEX
2496 inline complex<float>
2497 __complex_proj(
const complex<float>& __z)
2498 {
return __builtin_cprojf(__z.__rep()); }
2500 inline complex<double>
2501 __complex_proj(
const complex<double>& __z)
2502 {
return __builtin_cproj(__z.__rep()); }
2504 inline complex<long double>
2505 __complex_proj(
const complex<long double>& __z)
2506 {
return __builtin_cprojl(__z.__rep()); }
2508#if __cplusplus > 202002L
2509#if defined(__STDCPP_FLOAT16_T__) && defined(_GLIBCXX_FLOAT_IS_IEEE_BINARY32)
2510 inline __complex__ _Float16
2511 __complex_proj(__complex__ _Float16 __z)
2512 {
return static_cast<__complex__ _Float16
>(__builtin_cprojf(__z)); }
2515#if defined(__STDCPP_FLOAT32_T__) && defined(_GLIBCXX_FLOAT_IS_IEEE_BINARY32)
2516 inline __complex__ _Float32
2517 __complex_proj(__complex__ _Float32 __z)
2518 {
return __builtin_cprojf(__z); }
2521#if defined(__STDCPP_FLOAT64_T__) && defined(_GLIBCXX_DOUBLE_IS_IEEE_BINARY64)
2522 inline __complex__ _Float64
2523 __complex_proj(__complex__ _Float64 __z)
2524 {
return __builtin_cproj(__z); }
2527#if defined(__STDCPP_FLOAT128_T__) && defined(_GLIBCXX_LDOUBLE_IS_IEEE_BINARY128)
2528 inline __complex__ _Float128
2529 __complex_proj(__complex__ _Float128 __z)
2530 {
return __builtin_cprojl(__z); }
2531#elif defined(__STDCPP_FLOAT128_T__) && defined(_GLIBCXX_HAVE_FLOAT128_MATH)
2532 inline __complex__ _Float128
2533 __complex_proj(__complex__ _Float128 __z)
2534 {
return __builtin_cprojf128(__z); }
2537#if defined(__STDCPP_BFLOAT16_T__) && defined(_GLIBCXX_FLOAT_IS_IEEE_BINARY32)
2538 inline __complex__
decltype(0.0bf16)
2539 __complex_proj(__complex__
decltype(0.0bf16) __z)
2540 {
return static_cast<__complex__ decltype(0.0bf16)
>(__builtin_cprojf(__z)); }
2543 template<
typename _Tp>
2544 requires requires {
typename __complex_type<_Tp>::type; }
2546 __complex_proj(
const complex<_Tp>& __z)
2547 {
return __complex_proj(__z.__rep()); }
2550#elif defined _GLIBCXX_USE_C99_MATH_TR1
2551 inline complex<float>
2552 __complex_proj(
const complex<float>& __z)
2554 if (__builtin_isinf(__z.real()) || __builtin_isinf(__z.imag()))
2555 return complex<float>(__builtin_inff(),
2556 __builtin_copysignf(0.0f, __z.imag()));
2560 inline complex<double>
2561 __complex_proj(
const complex<double>& __z)
2563 if (__builtin_isinf(__z.real()) || __builtin_isinf(__z.imag()))
2564 return complex<double>(__builtin_inf(),
2565 __builtin_copysign(0.0, __z.imag()));
2569 inline complex<long double>
2570 __complex_proj(
const complex<long double>& __z)
2572 if (__builtin_isinf(__z.real()) || __builtin_isinf(__z.imag()))
2573 return complex<long double>(__builtin_infl(),
2574 __builtin_copysignl(0.0l, __z.imag()));
2579 template<
typename _Tp>
2582 {
return __complex_proj(__z); }
2585 template<
typename _Tp>
2589 typedef typename __gnu_cxx::__promote<_Tp>::__type __type;
2593 template<
typename _Tp>
2594 inline _GLIBCXX20_CONSTEXPR
2598 typedef typename __gnu_cxx::__promote<_Tp>::__type __type;
2602#if __cplusplus > 201103L
2604inline namespace literals {
2605inline namespace complex_literals {
2606#pragma GCC diagnostic push
2607#pragma GCC diagnostic ignored "-Wliteral-suffix"
2608#define __cpp_lib_complex_udls 201309L
2611 operator""if(
long double __num)
2615 operator""if(
unsigned long long __num)
2619 operator""i(
long double __num)
2623 operator""i(
unsigned long long __num)
2627 operator""il(
long double __num)
2631 operator""il(
unsigned long long __num)
2634#pragma GCC diagnostic pop
2640_GLIBCXX_END_NAMESPACE_VERSION
complex< _Tp > log10(const complex< _Tp > &)
Return complex base 10 logarithm of z.
constexpr complex< _Tp > operator*(const complex< _Tp > &__x, const complex< _Tp > &__y)
Return new complex value x times y.
complex< _Tp > sin(const complex< _Tp > &)
Return complex sine of z.
constexpr complex< _Tp > operator-(const complex< _Tp > &__x, const complex< _Tp > &__y)
Return new complex value x minus y.
constexpr complex< _Tp > & operator*=(const _Tp &)
Multiply this complex number by a scalar.
complex< _Tp > log(const complex< _Tp > &)
Return complex natural logarithm of z.
complex< _Tp > tan(const complex< _Tp > &)
Return complex tangent of z.
complex< _Tp > polar(const _Tp &, const _Tp &=0)
Return complex with magnitude rho and angle theta.
constexpr complex< _Tp > operator+(const complex< _Tp > &__x, const complex< _Tp > &__y)
Return new complex value x plus y.
_Tp abs(const complex< _Tp > &)
Return magnitude of z.
complex< _Tp > exp(const complex< _Tp > &)
Return complex base e exponential of z.
complex< _Tp > cosh(const complex< _Tp > &)
Return complex hyperbolic cosine of z.
_Tp arg(const complex< _Tp > &)
Return phase angle of z.
constexpr complex< _Tp > & operator=(const _Tp &)
Assign a scalar to this complex number.
complex< _Tp > tanh(const complex< _Tp > &)
Return complex hyperbolic tangent of z.
constexpr complex< _Tp > conj(const complex< _Tp > &)
Return complex conjugate of z.
complex< _Tp > pow(const complex< _Tp > &, int)
Return x to the y'th power.
constexpr complex< _Tp > operator/(const complex< _Tp > &__x, const complex< _Tp > &__y)
Return new complex value x divided by y.
complex< _Tp > sinh(const complex< _Tp > &)
Return complex hyperbolic sine of z.
_Tp constexpr norm(const complex< _Tp > &)
Return z magnitude squared.
constexpr complex< _Tp > & operator/=(const _Tp &)
Divide this complex number by a scalar.
complex< _Tp > cos(const complex< _Tp > &)
Return complex cosine of z.
complex< _Tp > sqrt(const complex< _Tp > &)
Return complex square root of z.
basic_ostream< char > ostream
Base class for char output streams.
basic_istream< char > istream
Base class for char input streams.
basic_ostream< wchar_t > wostream
Base class for wchar_t output streams.
basic_istream< wchar_t > wistream
Base class for wchar_t input streams.
constexpr const _Tp & max(const _Tp &, const _Tp &)
This does what you think it does.
ISO C++ entities toplevel namespace is std.
std::basic_istream< _CharT, _Traits > & operator>>(std::basic_istream< _CharT, _Traits > &__is, bitset< _Nb > &__x)
Global I/O operators for bitsets.
std::basic_ostream< _CharT, _Traits > & operator<<(std::basic_ostream< _CharT, _Traits > &__os, const bitset< _Nb > &__x)
Global I/O operators for bitsets.
GNU extensions for public use.
_Tp value_type
Value typedef.
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...
constexpr complex(const complex< _Up > &__z)
Converting constructor.
constexpr complex< _Tp > & operator-=(const _Tp &__t)
Subtract a scalar from this complex number.
constexpr complex< _Tp > & operator+=(const _Tp &__t)
Add a scalar to this complex number.
void setstate(iostate __state)
Sets additional flags in the error state.
char_type widen(char __c) const
Widens characters.
Template class basic_istream.
__istream_type & putback(char_type __c)
Unextracting a single character.
fmtflags flags() const
Access to format flags.
static const iostate failbit
Indicates that an input operation failed to read the expected characters, or that an output operation...