36#ifndef _GLIBCXX_COMPLEX
37#define _GLIBCXX_COMPLEX 1
39#pragma GCC system_header
51#pragma clang diagnostic push
52#pragma clang diagnostic ignored "-Wc99-extensions"
55#define __glibcxx_want_constexpr_complex
56#define __glibcxx_want_complex_udls
59namespace std _GLIBCXX_VISIBILITY(default)
61_GLIBCXX_BEGIN_NAMESPACE_VERSION
72 template<
typename _Tp>
class complex;
73 template<>
class complex<float>;
74 template<>
class complex<double>;
75 template<>
class complex<long double>;
78 template<
typename _Tp> _Tp
abs(
const complex<_Tp>&);
80 template<
typename _Tp> _Tp
arg(
const complex<_Tp>&);
82 template<
typename _Tp> _Tp _GLIBCXX20_CONSTEXPR
norm(
const complex<_Tp>&);
85 template<
typename _Tp>
86 _GLIBCXX20_CONSTEXPR complex<_Tp>
conj(
const complex<_Tp>&);
88 template<
typename _Tp> complex<_Tp>
polar(
const _Tp&,
const _Tp& = 0);
92 template<
typename _Tp> complex<_Tp>
cos(
const complex<_Tp>&);
94 template<
typename _Tp> complex<_Tp>
cosh(
const complex<_Tp>&);
96 template<
typename _Tp> complex<_Tp>
exp(
const complex<_Tp>&);
98 template<
typename _Tp> complex<_Tp>
log(
const complex<_Tp>&);
100 template<
typename _Tp> complex<_Tp>
log10(
const complex<_Tp>&);
102 template<
typename _Tp> complex<_Tp>
pow(
const complex<_Tp>&,
int);
104 template<
typename _Tp> complex<_Tp>
pow(
const complex<_Tp>&,
const _Tp&);
106 template<
typename _Tp> complex<_Tp>
pow(
const complex<_Tp>&,
107 const complex<_Tp>&);
109 template<
typename _Tp> complex<_Tp>
pow(
const _Tp&,
const complex<_Tp>&);
111 template<
typename _Tp> complex<_Tp>
sin(
const complex<_Tp>&);
113 template<
typename _Tp> complex<_Tp>
sinh(
const complex<_Tp>&);
115 template<
typename _Tp> complex<_Tp>
sqrt(
const complex<_Tp>&);
117 template<
typename _Tp> complex<_Tp>
tan(
const complex<_Tp>&);
119 template<
typename _Tp> complex<_Tp>
tanh(
const complex<_Tp>&);
131 template<
typename _Tp>
140 _GLIBCXX_CONSTEXPR
complex(
const _Tp& __r = _Tp(),
const _Tp& __i = _Tp())
141 : _M_real(__r), _M_imag(__i) { }
144#if __cplusplus >= 201103L
149 template<
typename _Up>
150#if __cplusplus > 202002L
151 explicit(!
requires(_Up __u) { _Tp{__u}; })
154 : _M_real(_Tp(__z.real())), _M_imag(_Tp(__z.imag())) { }
156#if __cplusplus >= 201103L
159 _GLIBCXX_ABI_TAG_CXX11
161 real()
const {
return _M_real; }
163 _GLIBCXX_ABI_TAG_CXX11
165 imag()
const {
return _M_imag; }
169 real() {
return _M_real; }
173 real()
const {
return _M_real; }
177 imag() {
return _M_imag; }
181 imag()
const {
return _M_imag; }
186 _GLIBCXX20_CONSTEXPR
void
187 real(_Tp __val) { _M_real = __val; }
189 _GLIBCXX20_CONSTEXPR
void
190 imag(_Tp __val) { _M_imag = __val; }
193 _GLIBCXX20_CONSTEXPR complex<_Tp>&
operator=(
const _Tp&);
197 _GLIBCXX20_CONSTEXPR complex<_Tp>&
219#if __cplusplus >= 201103L
224 template<
typename _Up>
227 template<
typename _Up>
230 template<
typename _Up>
233 template<
typename _Up>
236 template<
typename _Up>
239 _GLIBCXX_CONSTEXPR
complex __rep()
const
247 template<
typename _Tp>
248 _GLIBCXX20_CONSTEXPR complex<_Tp>&
257 template<
typename _Tp>
267 template<
typename _Tp>
276 template<
typename _Tp>
277 template<
typename _Up>
281 _M_real = __z.real();
282 _M_imag = __z.imag();
287 template<
typename _Tp>
288 template<
typename _Up>
292 _M_real += __z.real();
293 _M_imag += __z.imag();
298 template<
typename _Tp>
299 template<
typename _Up>
303 _M_real -= __z.real();
304 _M_imag -= __z.imag();
310 template<
typename _Tp>
311 template<
typename _Up>
315 const _Tp __r = _M_real * __z.real() - _M_imag * __z.imag();
316 _M_imag = _M_real * __z.imag() + _M_imag * __z.real();
323 template<
typename _Tp>
324 template<
typename _Up>
328 const _Tp __r = _M_real * __z.real() + _M_imag * __z.imag();
330 _M_imag = (_M_imag * __z.real() - _M_real * __z.imag()) / __n;
338 template<
typename _Tp>
347 template<
typename _Tp>
348 inline _GLIBCXX20_CONSTEXPR complex<_Tp>
356 template<
typename _Tp>
357 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>
386 template<
typename _Tp>
387 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>
416 template<
typename _Tp>
417 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>
446 template<
typename _Tp>
447 inline _GLIBCXX20_CONSTEXPR complex<_Tp>
457 template<
typename _Tp>
458 inline _GLIBCXX20_CONSTEXPR complex<_Tp>
463 template<
typename _Tp>
464 inline _GLIBCXX20_CONSTEXPR complex<_Tp>
470 template<
typename _Tp>
471 inline _GLIBCXX_CONSTEXPR
bool
473 {
return __x.real() == __y.real() && __x.imag() == __y.imag(); }
475 template<
typename _Tp>
476 inline _GLIBCXX_CONSTEXPR
bool
478 {
return __x.real() == __y && __x.imag() == _Tp(); }
480#if !(__cpp_impl_three_way_comparison >= 201907L)
481 template<
typename _Tp>
482 inline _GLIBCXX_CONSTEXPR
bool
483 operator==(
const _Tp& __x,
const complex<_Tp>& __y)
484 {
return __x == __y.real() && _Tp() == __y.imag(); }
489 template<
typename _Tp>
490 inline _GLIBCXX_CONSTEXPR
bool
491 operator!=(
const complex<_Tp>& __x,
const complex<_Tp>& __y)
492 {
return __x.real() != __y.real() || __x.imag() != __y.imag(); }
494 template<
typename _Tp>
495 inline _GLIBCXX_CONSTEXPR
bool
496 operator!=(
const complex<_Tp>& __x,
const _Tp& __y)
497 {
return __x.real() != __y || __x.imag() != _Tp(); }
499 template<
typename _Tp>
500 inline _GLIBCXX_CONSTEXPR
bool
501 operator!=(
const _Tp& __x,
const complex<_Tp>& __y)
502 {
return __x != __y.real() || _Tp() != __y.imag(); }
507 template<
typename _Tp,
typename _CharT,
class _Traits>
508 basic_istream<_CharT, _Traits>&
515 if (_Traits::eq(__ch, __is.
widen(
'(')))
518 if (__is >> __u >> __ch)
520 const _CharT __rparen = __is.
widen(
')');
521 if (_Traits::eq(__ch, __rparen))
526 else if (_Traits::eq(__ch, __is.
widen(
',')))
529 if (__is >> __v >> __ch)
531 if (_Traits::eq(__ch, __rparen))
561 template<
typename _Tp,
typename _CharT,
class _Traits>
562 basic_ostream<_CharT, _Traits>&
563 operator<<(basic_ostream<_CharT, _Traits>& __os,
const complex<_Tp>& __x)
565 basic_ostringstream<_CharT, _Traits> __s;
566 __s.
flags(__os.flags());
567 __s.imbue(__os.getloc());
568 __s.precision(__os.precision());
569 __s <<
'(' << __x.real() <<
',' << __x.imag() <<
')';
570 return __os << __s.str();
574#if __cplusplus >= 201103L
575 template<
typename _Tp>
577 real(
const complex<_Tp>& __z)
578 {
return __z.real(); }
580 template<
typename _Tp>
582 imag(
const complex<_Tp>& __z)
583 {
return __z.imag(); }
585 template<
typename _Tp>
587 real(complex<_Tp>& __z)
588 {
return __z.real(); }
590 template<
typename _Tp>
592 real(
const complex<_Tp>& __z)
593 {
return __z.real(); }
595 template<
typename _Tp>
597 imag(complex<_Tp>& __z)
598 {
return __z.imag(); }
600 template<
typename _Tp>
602 imag(
const complex<_Tp>& __z)
603 {
return __z.imag(); }
606#if _GLIBCXX_USE_C99_COMPLEX
607#if defined(__STDCPP_FLOAT16_T__) && defined(_GLIBCXX_FLOAT_IS_IEEE_BINARY32)
609 __complex_abs(__complex__ _Float16 __z)
610 {
return _Float16(__builtin_cabsf(__z)); }
613 __complex_arg(__complex__ _Float16 __z)
614 {
return _Float16(__builtin_cargf(__z)); }
616 inline __complex__ _Float16
617 __complex_cos(__complex__ _Float16 __z)
618 {
return static_cast<__complex__ _Float16
>(__builtin_ccosf(__z)); }
620 inline __complex__ _Float16
621 __complex_cosh(__complex__ _Float16 __z)
622 {
return static_cast<__complex__ _Float16
>(__builtin_ccoshf(__z)); }
624 inline __complex__ _Float16
625 __complex_exp(__complex__ _Float16 __z)
626 {
return static_cast<__complex__ _Float16
>(__builtin_cexpf(__z)); }
628 inline __complex__ _Float16
629 __complex_log(__complex__ _Float16 __z)
630 {
return static_cast<__complex__ _Float16
>(__builtin_clogf(__z)); }
632 inline __complex__ _Float16
633 __complex_sin(__complex__ _Float16 __z)
634 {
return static_cast<__complex__ _Float16
>(__builtin_csinf(__z)); }
636 inline __complex__ _Float16
637 __complex_sinh(__complex__ _Float16 __z)
638 {
return static_cast<__complex__ _Float16
>(__builtin_csinhf(__z)); }
640 inline __complex__ _Float16
641 __complex_sqrt(__complex__ _Float16 __z)
642 {
return static_cast<__complex__ _Float16
>(__builtin_csqrtf(__z)); }
644 inline __complex__ _Float16
645 __complex_tan(__complex__ _Float16 __z)
646 {
return static_cast<__complex__ _Float16
>(__builtin_ctanf(__z)); }
648 inline __complex__ _Float16
649 __complex_tanh(__complex__ _Float16 __z)
650 {
return static_cast<__complex__ _Float16
>(__builtin_ctanhf(__z)); }
652 inline __complex__ _Float16
653 __complex_pow(__complex__ _Float16 __x, __complex__ _Float16 __y)
654 {
return static_cast<__complex__ _Float16
>(__builtin_cpowf(__x, __y)); }
657#if defined(__STDCPP_FLOAT32_T__) && defined(_GLIBCXX_FLOAT_IS_IEEE_BINARY32)
659 __complex_abs(__complex__ _Float32 __z) {
return __builtin_cabsf(__z); }
662 __complex_arg(__complex__ _Float32 __z) {
return __builtin_cargf(__z); }
664 inline __complex__ _Float32
665 __complex_cos(__complex__ _Float32 __z) {
return __builtin_ccosf(__z); }
667 inline __complex__ _Float32
668 __complex_cosh(__complex__ _Float32 __z) {
return __builtin_ccoshf(__z); }
670 inline __complex__ _Float32
671 __complex_exp(__complex__ _Float32 __z) {
return __builtin_cexpf(__z); }
673 inline __complex__ _Float32
674 __complex_log(__complex__ _Float32 __z) {
return __builtin_clogf(__z); }
676 inline __complex__ _Float32
677 __complex_sin(__complex__ _Float32 __z) {
return __builtin_csinf(__z); }
679 inline __complex__ _Float32
680 __complex_sinh(__complex__ _Float32 __z) {
return __builtin_csinhf(__z); }
682 inline __complex__ _Float32
683 __complex_sqrt(__complex__ _Float32 __z) {
return __builtin_csqrtf(__z); }
685 inline __complex__ _Float32
686 __complex_tan(__complex__ _Float32 __z) {
return __builtin_ctanf(__z); }
688 inline __complex__ _Float32
689 __complex_tanh(__complex__ _Float32 __z) {
return __builtin_ctanhf(__z); }
691 inline __complex__ _Float32
692 __complex_pow(__complex__ _Float32 __x, __complex__ _Float32 __y)
693 {
return __builtin_cpowf(__x, __y); }
696#if defined(__STDCPP_FLOAT64_T__) && defined(_GLIBCXX_DOUBLE_IS_IEEE_BINARY64)
698 __complex_abs(__complex__ _Float64 __z) {
return __builtin_cabs(__z); }
701 __complex_arg(__complex__ _Float64 __z) {
return __builtin_carg(__z); }
703 inline __complex__ _Float64
704 __complex_cos(__complex__ _Float64 __z) {
return __builtin_ccos(__z); }
706 inline __complex__ _Float64
707 __complex_cosh(__complex__ _Float64 __z) {
return __builtin_ccosh(__z); }
709 inline __complex__ _Float64
710 __complex_exp(__complex__ _Float64 __z) {
return __builtin_cexp(__z); }
712 inline __complex__ _Float64
713 __complex_log(__complex__ _Float64 __z) {
return __builtin_clog(__z); }
715 inline __complex__ _Float64
716 __complex_sin(__complex__ _Float64 __z) {
return __builtin_csin(__z); }
718 inline __complex__ _Float64
719 __complex_sinh(__complex__ _Float64 __z) {
return __builtin_csinh(__z); }
721 inline __complex__ _Float64
722 __complex_sqrt(__complex__ _Float64 __z) {
return __builtin_csqrt(__z); }
724 inline __complex__ _Float64
725 __complex_tan(__complex__ _Float64 __z) {
return __builtin_ctan(__z); }
727 inline __complex__ _Float64
728 __complex_tanh(__complex__ _Float64 __z) {
return __builtin_ctanh(__z); }
730 inline __complex__ _Float64
731 __complex_pow(__complex__ _Float64 __x, __complex__ _Float64 __y)
732 {
return __builtin_cpow(__x, __y); }
735#if defined(__STDCPP_FLOAT128_T__) && defined(_GLIBCXX_LDOUBLE_IS_IEEE_BINARY128)
737 __complex_abs(__complex__ _Float128 __z) {
return __builtin_cabsl(__z); }
740 __complex_arg(__complex__ _Float128 __z) {
return __builtin_cargl(__z); }
742 inline __complex__ _Float128
743 __complex_cos(__complex__ _Float128 __z) {
return __builtin_ccosl(__z); }
745 inline __complex__ _Float128
746 __complex_cosh(__complex__ _Float128 __z) {
return __builtin_ccoshl(__z); }
748 inline __complex__ _Float128
749 __complex_exp(__complex__ _Float128 __z) {
return __builtin_cexpl(__z); }
751 inline __complex__ _Float128
752 __complex_log(__complex__ _Float128 __z) {
return __builtin_clogl(__z); }
754 inline __complex__ _Float128
755 __complex_sin(__complex__ _Float128 __z) {
return __builtin_csinl(__z); }
757 inline __complex__ _Float128
758 __complex_sinh(__complex__ _Float128 __z) {
return __builtin_csinhl(__z); }
760 inline __complex__ _Float128
761 __complex_sqrt(__complex__ _Float128 __z) {
return __builtin_csqrtl(__z); }
763 inline __complex__ _Float128
764 __complex_tan(__complex__ _Float128 __z) {
return __builtin_ctanl(__z); }
766 inline __complex__ _Float128
767 __complex_tanh(__complex__ _Float128 __z) {
return __builtin_ctanhl(__z); }
769 inline __complex__ _Float128
770 __complex_pow(__complex__ _Float128 __x, __complex__ _Float128 __y)
771 {
return __builtin_cpowl(__x, __y); }
772#elif defined(__STDCPP_FLOAT128_T__) && defined(_GLIBCXX_HAVE_FLOAT128_MATH)
774 __complex_abs(__complex__ _Float128 __z) {
return __builtin_cabsf128(__z); }
777 __complex_arg(__complex__ _Float128 __z) {
return __builtin_cargf128(__z); }
779 inline __complex__ _Float128
780 __complex_cos(__complex__ _Float128 __z) {
return __builtin_ccosf128(__z); }
782 inline __complex__ _Float128
783 __complex_cosh(__complex__ _Float128 __z) {
return __builtin_ccoshf128(__z); }
785 inline __complex__ _Float128
786 __complex_exp(__complex__ _Float128 __z) {
return __builtin_cexpf128(__z); }
788 inline __complex__ _Float128
789 __complex_log(__complex__ _Float128 __z) {
return __builtin_clogf128(__z); }
791 inline __complex__ _Float128
792 __complex_sin(__complex__ _Float128 __z) {
return __builtin_csinf128(__z); }
794 inline __complex__ _Float128
795 __complex_sinh(__complex__ _Float128 __z) {
return __builtin_csinhf128(__z); }
797 inline __complex__ _Float128
798 __complex_sqrt(__complex__ _Float128 __z) {
return __builtin_csqrtf128(__z); }
800 inline __complex__ _Float128
801 __complex_tan(__complex__ _Float128 __z) {
return __builtin_ctanf128(__z); }
803 inline __complex__ _Float128
804 __complex_tanh(__complex__ _Float128 __z) {
return __builtin_ctanhf128(__z); }
806 inline __complex__ _Float128
807 __complex_pow(__complex__ _Float128 __x, __complex__ _Float128 __y)
808 {
return __builtin_cpowf128(__x, __y); }
811#if defined(__STDCPP_BFLOAT16_T__) && defined(_GLIBCXX_FLOAT_IS_IEEE_BINARY32)
812 inline __gnu_cxx::__bfloat16_t
813 __complex_abs(__complex__
decltype(0.0bf16) __z)
814 {
return __gnu_cxx::__bfloat16_t(__builtin_cabsf(__z)); }
816 inline __gnu_cxx::__bfloat16_t
817 __complex_arg(__complex__
decltype(0.0bf16) __z)
818 {
return __gnu_cxx::__bfloat16_t(__builtin_cargf(__z)); }
820 inline __complex__
decltype(0.0bf16)
821 __complex_cos(__complex__
decltype(0.0bf16) __z)
822 {
return static_cast<__complex__ decltype(0.0bf16)
>(__builtin_ccosf(__z)); }
824 inline __complex__
decltype(0.0bf16)
825 __complex_cosh(__complex__
decltype(0.0bf16) __z)
826 {
return static_cast<__complex__ decltype(0.0bf16)
>(__builtin_ccoshf(__z)); }
828 inline __complex__
decltype(0.0bf16)
829 __complex_exp(__complex__
decltype(0.0bf16) __z)
830 {
return static_cast<__complex__ decltype(0.0bf16)
>(__builtin_cexpf(__z)); }
832 inline __complex__
decltype(0.0bf16)
833 __complex_log(__complex__
decltype(0.0bf16) __z)
834 {
return static_cast<__complex__ decltype(0.0bf16)
>(__builtin_clogf(__z)); }
836 inline __complex__
decltype(0.0bf16)
837 __complex_sin(__complex__
decltype(0.0bf16) __z)
838 {
return static_cast<__complex__ decltype(0.0bf16)
>(__builtin_csinf(__z)); }
840 inline __complex__
decltype(0.0bf16)
841 __complex_sinh(__complex__
decltype(0.0bf16) __z)
842 {
return static_cast<__complex__ decltype(0.0bf16)
>(__builtin_csinhf(__z)); }
844 inline __complex__
decltype(0.0bf16)
845 __complex_sqrt(__complex__
decltype(0.0bf16) __z)
846 {
return static_cast<__complex__ decltype(0.0bf16)
>(__builtin_csqrtf(__z)); }
848 inline __complex__
decltype(0.0bf16)
849 __complex_tan(__complex__
decltype(0.0bf16) __z)
850 {
return static_cast<__complex__ decltype(0.0bf16)
>(__builtin_ctanf(__z)); }
852 inline __complex__
decltype(0.0bf16)
853 __complex_tanh(__complex__
decltype(0.0bf16) __z)
854 {
return static_cast<__complex__ decltype(0.0bf16)
>(__builtin_ctanhf(__z)); }
856 inline __complex__
decltype(0.0bf16)
857 __complex_pow(__complex__
decltype(0.0bf16) __x,
858 __complex__
decltype(0.0bf16) __y)
859 {
return static_cast<__complex__ decltype(0.0bf16)
>(__builtin_cpowf(__x,
865 template<
typename _Tp>
867 __complex_abs(
const complex<_Tp>& __z)
869 _Tp __x = __z.real();
870 _Tp __y = __z.imag();
876 return __s *
sqrt(__x * __x + __y * __y);
879#if _GLIBCXX_USE_C99_COMPLEX
881 __complex_abs(__complex__
float __z) {
return __builtin_cabsf(__z); }
884 __complex_abs(__complex__
double __z) {
return __builtin_cabs(__z); }
887 __complex_abs(
const __complex__
long double& __z)
888 {
return __builtin_cabsl(__z); }
890 template<
typename _Tp>
892 abs(
const complex<_Tp>& __z) {
return __complex_abs(__z.__rep()); }
894 template<
typename _Tp>
901 template<
typename _Tp>
903 __complex_arg(
const complex<_Tp>& __z)
904 {
return atan2(__z.imag(), __z.real()); }
906#if _GLIBCXX_USE_C99_COMPLEX
908 __complex_arg(__complex__
float __z) {
return __builtin_cargf(__z); }
911 __complex_arg(__complex__
double __z) {
return __builtin_carg(__z); }
914 __complex_arg(
const __complex__
long double& __z)
915 {
return __builtin_cargl(__z); }
917 template<
typename _Tp>
919 arg(
const complex<_Tp>& __z) {
return __complex_arg(__z.__rep()); }
921 template<
typename _Tp>
934 template<
typename _Tp>
935 static inline _GLIBCXX20_CONSTEXPR _Tp _S_do_it(
const complex<_Tp>& __z)
937 const _Tp __x = __z.real();
938 const _Tp __y = __z.imag();
939 return __x * __x + __y * __y;
944 struct _Norm_helper<true>
946 template<
typename _Tp>
947 static inline _GLIBCXX20_CONSTEXPR _Tp _S_do_it(
const complex<_Tp>& __z)
951 const _Tp __x = __z.real();
952 const _Tp __y = __z.imag();
953 return __x * __x + __y * __y;
957 template<
typename _Tp>
958 inline _GLIBCXX20_CONSTEXPR _Tp
961 return _Norm_helper<__is_floating<_Tp>::__value
962 && !_GLIBCXX_FAST_MATH>::_S_do_it(__z);
965 template<
typename _Tp>
967 polar(
const _Tp& __rho,
const _Tp& __theta)
969 __glibcxx_assert( __rho >= 0 );
973 template<
typename _Tp>
974 inline _GLIBCXX20_CONSTEXPR complex<_Tp>
981 template<
typename _Tp>
983 __complex_cos(
const complex<_Tp>& __z)
985 const _Tp __x = __z.real();
986 const _Tp __y = __z.imag();
987 return complex<_Tp>(cos(__x) * cosh(__y), -sin(__x) * sinh(__y));
990#if _GLIBCXX_USE_C99_COMPLEX
991 inline __complex__
float
992 __complex_cos(__complex__
float __z) {
return __builtin_ccosf(__z); }
994 inline __complex__
double
995 __complex_cos(__complex__
double __z) {
return __builtin_ccos(__z); }
997 inline __complex__
long double
998 __complex_cos(
const __complex__
long double& __z)
999 {
return __builtin_ccosl(__z); }
1001 template<
typename _Tp>
1003 cos(
const complex<_Tp>& __z) {
return __complex_cos(__z.__rep()); }
1005 template<
typename _Tp>
1011 template<
typename _Tp>
1013 __complex_cosh(
const complex<_Tp>& __z)
1015 const _Tp __x = __z.real();
1016 const _Tp __y = __z.imag();
1017 return complex<_Tp>(cosh(__x) * cos(__y), sinh(__x) * sin(__y));
1020#if _GLIBCXX_USE_C99_COMPLEX
1021 inline __complex__
float
1022 __complex_cosh(__complex__
float __z) {
return __builtin_ccoshf(__z); }
1024 inline __complex__
double
1025 __complex_cosh(__complex__
double __z) {
return __builtin_ccosh(__z); }
1027 inline __complex__
long double
1028 __complex_cosh(
const __complex__
long double& __z)
1029 {
return __builtin_ccoshl(__z); }
1031 template<
typename _Tp>
1033 cosh(
const complex<_Tp>& __z) {
return __complex_cosh(__z.__rep()); }
1035 template<
typename _Tp>
1041 template<
typename _Tp>
1043 __complex_exp(
const complex<_Tp>& __z)
1044 {
return std::polar<_Tp>(exp(__z.real()), __z.imag()); }
1046#if _GLIBCXX_USE_C99_COMPLEX
1047 inline __complex__
float
1048 __complex_exp(__complex__
float __z) {
return __builtin_cexpf(__z); }
1050 inline __complex__
double
1051 __complex_exp(__complex__
double __z) {
return __builtin_cexp(__z); }
1053 inline __complex__
long double
1054 __complex_exp(
const __complex__
long double& __z)
1055 {
return __builtin_cexpl(__z); }
1057 template<
typename _Tp>
1059 exp(
const complex<_Tp>& __z) {
return __complex_exp(__z.__rep()); }
1061 template<
typename _Tp>
1068 template<
typename _Tp>
1070 __complex_log(
const complex<_Tp>& __z)
1073#if _GLIBCXX_USE_C99_COMPLEX
1074 inline __complex__
float
1075 __complex_log(__complex__
float __z) {
return __builtin_clogf(__z); }
1077 inline __complex__
double
1078 __complex_log(__complex__
double __z) {
return __builtin_clog(__z); }
1080 inline __complex__
long double
1081 __complex_log(
const __complex__
long double& __z)
1082 {
return __builtin_clogl(__z); }
1084 template<
typename _Tp>
1086 log(
const complex<_Tp>& __z) {
return __complex_log(__z.__rep()); }
1088 template<
typename _Tp>
1093 template<
typename _Tp>
1099 template<
typename _Tp>
1101 __complex_sin(
const complex<_Tp>& __z)
1103 const _Tp __x = __z.real();
1104 const _Tp __y = __z.imag();
1105 return complex<_Tp>(sin(__x) * cosh(__y), cos(__x) * sinh(__y));
1108#if _GLIBCXX_USE_C99_COMPLEX
1109 inline __complex__
float
1110 __complex_sin(__complex__
float __z) {
return __builtin_csinf(__z); }
1112 inline __complex__
double
1113 __complex_sin(__complex__
double __z) {
return __builtin_csin(__z); }
1115 inline __complex__
long double
1116 __complex_sin(
const __complex__
long double& __z)
1117 {
return __builtin_csinl(__z); }
1119 template<
typename _Tp>
1121 sin(
const complex<_Tp>& __z) {
return __complex_sin(__z.__rep()); }
1123 template<
typename _Tp>
1129 template<
typename _Tp>
1131 __complex_sinh(
const complex<_Tp>& __z)
1133 const _Tp __x = __z.real();
1134 const _Tp __y = __z.imag();
1135 return complex<_Tp>(sinh(__x) * cos(__y), cosh(__x) * sin(__y));
1138#if _GLIBCXX_USE_C99_COMPLEX
1139 inline __complex__
float
1140 __complex_sinh(__complex__
float __z) {
return __builtin_csinhf(__z); }
1142 inline __complex__
double
1143 __complex_sinh(__complex__
double __z) {
return __builtin_csinh(__z); }
1145 inline __complex__
long double
1146 __complex_sinh(
const __complex__
long double& __z)
1147 {
return __builtin_csinhl(__z); }
1149 template<
typename _Tp>
1151 sinh(
const complex<_Tp>& __z) {
return __complex_sinh(__z.__rep()); }
1153 template<
typename _Tp>
1160 template<
typename _Tp>
1162 __complex_sqrt(
const complex<_Tp>& __z)
1164 _Tp __x = __z.real();
1165 _Tp __y = __z.imag();
1169 _Tp __t = sqrt(abs(__y) / 2);
1170 return complex<_Tp>(__t, __y < _Tp() ? -__t : __t);
1177 ? complex<_Tp>(__u, __y / __t)
1178 : complex<_Tp>(
abs(__y) / __t, __y < _Tp() ? -__u : __u);
1182#if _GLIBCXX_USE_C99_COMPLEX
1183 inline __complex__
float
1184 __complex_sqrt(__complex__
float __z) {
return __builtin_csqrtf(__z); }
1186 inline __complex__
double
1187 __complex_sqrt(__complex__
double __z) {
return __builtin_csqrt(__z); }
1189 inline __complex__
long double
1190 __complex_sqrt(
const __complex__
long double& __z)
1191 {
return __builtin_csqrtl(__z); }
1193 template<
typename _Tp>
1195 sqrt(
const complex<_Tp>& __z) {
return __complex_sqrt(__z.__rep()); }
1197 template<
typename _Tp>
1204 template<
typename _Tp>
1206 __complex_tan(
const complex<_Tp>& __z)
1209#if _GLIBCXX_USE_C99_COMPLEX
1210 inline __complex__
float
1211 __complex_tan(__complex__
float __z) {
return __builtin_ctanf(__z); }
1213 inline __complex__
double
1214 __complex_tan(__complex__
double __z) {
return __builtin_ctan(__z); }
1216 inline __complex__
long double
1217 __complex_tan(
const __complex__
long double& __z)
1218 {
return __builtin_ctanl(__z); }
1220 template<
typename _Tp>
1222 tan(
const complex<_Tp>& __z) {
return __complex_tan(__z.__rep()); }
1224 template<
typename _Tp>
1232 template<
typename _Tp>
1234 __complex_tanh(
const complex<_Tp>& __z)
1237#if _GLIBCXX_USE_C99_COMPLEX
1238 inline __complex__
float
1239 __complex_tanh(__complex__
float __z) {
return __builtin_ctanhf(__z); }
1241 inline __complex__
double
1242 __complex_tanh(__complex__
double __z) {
return __builtin_ctanh(__z); }
1244 inline __complex__
long double
1245 __complex_tanh(
const __complex__
long double& __z)
1246 {
return __builtin_ctanhl(__z); }
1248 template<
typename _Tp>
1250 tanh(
const complex<_Tp>& __z) {
return __complex_tanh(__z.__rep()); }
1252 template<
typename _Tp>
1261 template<
typename _Tp>
1263 __complex_pow_unsigned(complex<_Tp> __x,
unsigned __n)
1265 complex<_Tp> __y = __n % 2 ? __x : complex<_Tp>(1);
1283 template<
typename _Tp>
1288 ?
complex<_Tp>(1) / std::__complex_pow_unsigned(__z, -(
unsigned)__n)
1289 : std::__complex_pow_unsigned(__z, __n);
1292 template<
typename _Tp>
1296#if ! _GLIBCXX_USE_C99_COMPLEX
1300 if (__x.imag() == _Tp() && __x.real() > _Tp())
1301 return pow(__x.real(), __y);
1304 return std::polar<_Tp>(
exp(__y * __t.real()), __y * __t.imag());
1307 template<
typename _Tp>
1309 __complex_pow(
const complex<_Tp>& __x,
const complex<_Tp>& __y)
1310 {
return __x == _Tp() ? _Tp() :
std::exp(__y *
std::log(__x)); }
1312#if _GLIBCXX_USE_C99_COMPLEX
1313 inline __complex__
float
1314 __complex_pow(__complex__
float __x, __complex__
float __y)
1315 {
return __builtin_cpowf(__x, __y); }
1317 inline __complex__
double
1318 __complex_pow(__complex__
double __x, __complex__
double __y)
1319 {
return __builtin_cpow(__x, __y); }
1321 inline __complex__
long double
1322 __complex_pow(
const __complex__
long double& __x,
1323 const __complex__
long double& __y)
1324 {
return __builtin_cpowl(__x, __y); }
1326 template<
typename _Tp>
1328 pow(
const complex<_Tp>& __x,
const complex<_Tp>& __y)
1329 {
return __complex_pow(__x.__rep(), __y.__rep()); }
1331 template<
typename _Tp>
1334 {
return __complex_pow(__x, __y); }
1337 template<
typename _Tp>
1341 return __x > _Tp() ? std::polar<_Tp>(
pow(__x, __y.real()),
1342 __y.imag() *
log(__x))
1353 typedef __complex__
float _ComplexT;
1355 _GLIBCXX_CONSTEXPR
complex(_ComplexT __z) : _M_value(__z) { }
1357 _GLIBCXX_CONSTEXPR
complex(
float __r = 0.0f,
float __i = 0.0f)
1358#if __cplusplus >= 201103L
1359 : _M_value{ __r, __i } { }
1362 __real__ _M_value = __r;
1363 __imag__ _M_value = __i;
1367#if __cplusplus >= 201103L
1371#if __cplusplus > 202002L
1372 template<
typename _Up>
1373 explicit(!
requires(_Up __u) { value_type{__u}; })
1381#if __cplusplus >= 201103L
1384 __attribute ((__abi_tag__ (
"cxx11")))
1386 real()
const {
return __real__ _M_value; }
1388 __attribute ((__abi_tag__ (
"cxx11")))
1390 imag()
const {
return __imag__ _M_value; }
1393 real() {
return __real__ _M_value; }
1396 real()
const {
return __real__ _M_value; }
1399 imag() {
return __imag__ _M_value; }
1402 imag()
const {
return __imag__ _M_value; }
1407 _GLIBCXX20_CONSTEXPR
void
1408 real(
float __val) { __real__ _M_value = __val; }
1410 _GLIBCXX20_CONSTEXPR
void
1411 imag(
float __val) { __imag__ _M_value = __val; }
1450#if __cplusplus >= 201103L
1454 template<
typename _Tp>
1458 __real__ _M_value = __z.real();
1459 __imag__ _M_value = __z.imag();
1463 template<
typename _Tp>
1467 _M_value += __z.__rep();
1475 _M_value -= __z.__rep();
1483 const _ComplexT __t = __z.__rep();
1492 const _ComplexT __t = __z.__rep();
1497 _GLIBCXX_CONSTEXPR _ComplexT __rep()
const {
return _M_value; }
1510 typedef __complex__
double _ComplexT;
1512 _GLIBCXX_CONSTEXPR
complex(_ComplexT __z) : _M_value(__z) { }
1514 _GLIBCXX_CONSTEXPR
complex(
double __r = 0.0,
double __i = 0.0)
1515#if __cplusplus >= 201103L
1516 : _M_value{ __r, __i } { }
1519 __real__ _M_value = __r;
1520 __imag__ _M_value = __i;
1524#if __cplusplus >= 201103L
1528#if __cplusplus > 202002L
1529 template<
typename _Up>
1530 explicit(!
requires(_Up __u) { value_type{__u}; })
1535 : _M_value(__z.__rep()) { }
1540#if __cplusplus >= 201103L
1543 __attribute ((__abi_tag__ (
"cxx11")))
1545 real()
const {
return __real__ _M_value; }
1547 __attribute ((__abi_tag__ (
"cxx11")))
1549 imag()
const {
return __imag__ _M_value; }
1552 real() {
return __real__ _M_value; }
1555 real()
const {
return __real__ _M_value; }
1558 imag() {
return __imag__ _M_value; }
1561 imag()
const {
return __imag__ _M_value; }
1566 _GLIBCXX20_CONSTEXPR
void
1567 real(
double __val) { __real__ _M_value = __val; }
1569 _GLIBCXX20_CONSTEXPR
void
1570 imag(
double __val) { __imag__ _M_value = __val; }
1608#if __cplusplus >= 201103L
1612 template<
typename _Tp>
1616 _M_value = __z.__rep();
1620 template<
typename _Tp>
1624 _M_value += __z.__rep();
1628 template<
typename _Tp>
1632 _M_value -= __z.__rep();
1636 template<
typename _Tp>
1640 const _ComplexT __t = __z.__rep();
1645 template<
typename _Tp>
1649 const _ComplexT __t = __z.__rep();
1654 _GLIBCXX_CONSTEXPR _ComplexT __rep()
const {
return _M_value; }
1667 typedef __complex__
long double _ComplexT;
1669 _GLIBCXX_CONSTEXPR
complex(_ComplexT __z) : _M_value(__z) { }
1671 _GLIBCXX_CONSTEXPR
complex(
long double __r = 0.0L,
1672 long double __i = 0.0L)
1673#if __cplusplus >= 201103L
1674 : _M_value{ __r, __i } { }
1677 __real__ _M_value = __r;
1678 __imag__ _M_value = __i;
1682#if __cplusplus >= 201103L
1686#if __cplusplus > 202002L
1687 template<
typename _Up>
1688 explicit(!
requires(_Up __u) { value_type{__u}; })
1693 : _M_value(__z.__rep()) { }
1696 : _M_value(__z.__rep()) { }
1699#if __cplusplus >= 201103L
1702 __attribute ((__abi_tag__ (
"cxx11")))
1703 constexpr long double
1704 real()
const {
return __real__ _M_value; }
1706 __attribute ((__abi_tag__ (
"cxx11")))
1707 constexpr long double
1708 imag()
const {
return __imag__ _M_value; }
1711 real() {
return __real__ _M_value; }
1714 real()
const {
return __real__ _M_value; }
1717 imag() {
return __imag__ _M_value; }
1720 imag()
const {
return __imag__ _M_value; }
1725 _GLIBCXX20_CONSTEXPR
void
1726 real(
long double __val) { __real__ _M_value = __val; }
1728 _GLIBCXX20_CONSTEXPR
void
1729 imag(
long double __val) { __imag__ _M_value = __val; }
1767#if __cplusplus >= 201103L
1771 template<
typename _Tp>
1775 _M_value = __z.__rep();
1779 template<
typename _Tp>
1783 _M_value += __z.__rep();
1787 template<
typename _Tp>
1791 _M_value -= __z.__rep();
1795 template<
typename _Tp>
1799 const _ComplexT __t = __z.__rep();
1804 template<
typename _Tp>
1808 const _ComplexT __t = __z.__rep();
1813 _GLIBCXX_CONSTEXPR _ComplexT __rep()
const {
return _M_value; }
1819#if __cplusplus > 202002L
1820 template<
typename _Tp>
1821 struct __complex_type
1824#ifdef __STDCPP_FLOAT16_T__
1826 struct __complex_type<_Float16>
1827 {
typedef __complex__ _Float16 type; };
1830#ifdef __STDCPP_FLOAT32_T__
1832 struct __complex_type<_Float32>
1833 {
typedef __complex__ _Float32 type; };
1836#ifdef __STDCPP_FLOAT64_T__
1838 struct __complex_type<_Float64>
1839 {
typedef __complex__ _Float64 type; };
1842#ifdef __STDCPP_FLOAT128_T__
1844 struct __complex_type<_Float128>
1845 {
typedef __complex__ _Float128 type; };
1848#ifdef __STDCPP_BFLOAT16_T__
1850 struct __complex_type<
__gnu_cxx::__bfloat16_t>
1851 {
typedef __complex__
decltype(0.0bf16) type; };
1854 template<
typename _Tp>
1855 requires requires {
typename __complex_type<_Tp>::type; }
1860 typedef typename std::__complex_type<_Tp>::type _ComplexT;
1862 constexpr complex(_ComplexT __z) : _M_value(__z) { }
1864 constexpr complex(_Tp __r = _Tp(), _Tp __i = _Tp())
1865 : _M_value{ __r, __i } { }
1867 template<
typename _Up>
1868 explicit(!
requires(_Up __u) {
value_type{__u}; })
1869 constexpr complex(
const complex<_Up>& __z)
1873 real()
const {
return __real__ _M_value; }
1876 imag()
const {
return __imag__ _M_value; }
1879 real(_Tp __val) { __real__ _M_value = __val; }
1882 imag(_Tp __val) { __imag__ _M_value = __val; }
1921 constexpr complex(
const complex&) =
default;
1924 template<
typename _Up>
1928 __real__ _M_value = __z.real();
1929 __imag__ _M_value = __z.imag();
1933 template<
typename _Up>
1937 _M_value += __z.__rep();
1945 _M_value -= __z.__rep();
1953 const _ComplexT __t = __z.__rep();
1962 const _ComplexT __t = __z.__rep();
1967 constexpr _ComplexT __rep()
const {
return _M_value; }
1974#if __cplusplus <= 202002L
1977 inline _GLIBCXX_CONSTEXPR
1979 : _M_value(__z.__rep()) { }
1981 inline _GLIBCXX_CONSTEXPR
1983 : _M_value(__z.__rep()) { }
1985 inline _GLIBCXX_CONSTEXPR
1987 : _M_value(__z.__rep()) { }
1993#if _GLIBCXX_EXTERN_TEMPLATE
2001#ifdef _GLIBCXX_USE_WCHAR_T
2013_GLIBCXX_END_NAMESPACE_VERSION
2016#if __cplusplus >= 201103L
2018namespace std _GLIBCXX_VISIBILITY(
default)
2020_GLIBCXX_BEGIN_NAMESPACE_VERSION
2033 template<
typename _Tp>
2038 const _Tp __pi_2 = 1.5707963267948966192313216916397514L;
2042#if _GLIBCXX_USE_C99_COMPLEX_ARC
2043#if defined(__STDCPP_FLOAT16_T__) && defined(_GLIBCXX_FLOAT_IS_IEEE_BINARY32)
2044 inline __complex__ _Float16
2045 __complex_acos(__complex__ _Float16 __z)
2046 {
return static_cast<__complex__ _Float16
>(__builtin_cacosf(__z)); }
2048 inline __complex__ _Float16
2049 __complex_asin(__complex__ _Float16 __z)
2050 {
return static_cast<__complex__ _Float16
>(__builtin_casinf(__z)); }
2052 inline __complex__ _Float16
2053 __complex_atan(__complex__ _Float16 __z)
2054 {
return static_cast<__complex__ _Float16
>(__builtin_catanf(__z)); }
2056 inline __complex__ _Float16
2057 __complex_acosh(__complex__ _Float16 __z)
2058 {
return static_cast<__complex__ _Float16
>(__builtin_cacoshf(__z)); }
2060 inline __complex__ _Float16
2061 __complex_asinh(__complex__ _Float16 __z)
2062 {
return static_cast<__complex__ _Float16
>(__builtin_casinhf(__z)); }
2064 inline __complex__ _Float16
2065 __complex_atanh(__complex__ _Float16 __z)
2066 {
return static_cast<__complex__ _Float16
>(__builtin_catanhf(__z)); }
2069#if defined(__STDCPP_FLOAT32_T__) && defined(_GLIBCXX_FLOAT_IS_IEEE_BINARY32)
2070 inline __complex__ _Float32
2071 __complex_acos(__complex__ _Float32 __z)
2072 {
return __builtin_cacosf(__z); }
2074 inline __complex__ _Float32
2075 __complex_asin(__complex__ _Float32 __z)
2076 {
return __builtin_casinf(__z); }
2078 inline __complex__ _Float32
2079 __complex_atan(__complex__ _Float32 __z)
2080 {
return __builtin_catanf(__z); }
2082 inline __complex__ _Float32
2083 __complex_acosh(__complex__ _Float32 __z)
2084 {
return __builtin_cacoshf(__z); }
2086 inline __complex__ _Float32
2087 __complex_asinh(__complex__ _Float32 __z)
2088 {
return __builtin_casinhf(__z); }
2090 inline __complex__ _Float32
2091 __complex_atanh(__complex__ _Float32 __z)
2092 {
return __builtin_catanhf(__z); }
2095#if defined(__STDCPP_FLOAT64_T__) && defined(_GLIBCXX_DOUBLE_IS_IEEE_BINARY64)
2096 inline __complex__ _Float64
2097 __complex_acos(__complex__ _Float64 __z)
2098 {
return __builtin_cacos(__z); }
2100 inline __complex__ _Float64
2101 __complex_asin(__complex__ _Float64 __z)
2102 {
return __builtin_casin(__z); }
2104 inline __complex__ _Float64
2105 __complex_atan(__complex__ _Float64 __z)
2106 {
return __builtin_catan(__z); }
2108 inline __complex__ _Float64
2109 __complex_acosh(__complex__ _Float64 __z)
2110 {
return __builtin_cacosh(__z); }
2112 inline __complex__ _Float64
2113 __complex_asinh(__complex__ _Float64 __z)
2114 {
return __builtin_casinh(__z); }
2116 inline __complex__ _Float64
2117 __complex_atanh(__complex__ _Float64 __z)
2118 {
return __builtin_catanh(__z); }
2121#if defined(__STDCPP_FLOAT128_T__) && defined(_GLIBCXX_LDOUBLE_IS_IEEE_BINARY128)
2122 inline __complex__ _Float128
2123 __complex_acos(__complex__ _Float128 __z)
2124 {
return __builtin_cacosl(__z); }
2126 inline __complex__ _Float128
2127 __complex_asin(__complex__ _Float128 __z)
2128 {
return __builtin_casinl(__z); }
2130 inline __complex__ _Float128
2131 __complex_atan(__complex__ _Float128 __z)
2132 {
return __builtin_catanl(__z); }
2134 inline __complex__ _Float128
2135 __complex_acosh(__complex__ _Float128 __z)
2136 {
return __builtin_cacoshl(__z); }
2138 inline __complex__ _Float128
2139 __complex_asinh(__complex__ _Float128 __z)
2140 {
return __builtin_casinhl(__z); }
2142 inline __complex__ _Float128
2143 __complex_atanh(__complex__ _Float128 __z)
2144 {
return __builtin_catanhl(__z); }
2145#elif defined(__STDCPP_FLOAT128_T__) && defined(_GLIBCXX_HAVE_FLOAT128_MATH)
2146 inline __complex__ _Float128
2147 __complex_acos(__complex__ _Float128 __z)
2148 {
return __builtin_cacosf128(__z); }
2150 inline __complex__ _Float128
2151 __complex_asin(__complex__ _Float128 __z)
2152 {
return __builtin_casinf128(__z); }
2154 inline __complex__ _Float128
2155 __complex_atan(__complex__ _Float128 __z)
2156 {
return __builtin_catanf128(__z); }
2158 inline __complex__ _Float128
2159 __complex_acosh(__complex__ _Float128 __z)
2160 {
return __builtin_cacoshf128(__z); }
2162 inline __complex__ _Float128
2163 __complex_asinh(__complex__ _Float128 __z)
2164 {
return __builtin_casinhf128(__z); }
2166 inline __complex__ _Float128
2167 __complex_atanh(__complex__ _Float128 __z)
2168 {
return __builtin_catanhf128(__z); }
2171#if defined(__STDCPP_BFLOAT16_T__) && defined(_GLIBCXX_FLOAT_IS_IEEE_BINARY32)
2172 inline __complex__
decltype(0.0bf16)
2173 __complex_acos(__complex__
decltype(0.0bf16) __z)
2174 {
return static_cast<__complex__ decltype(0.0bf16)
>(__builtin_cacosf(__z)); }
2176 inline __complex__
decltype(0.0bf16)
2177 __complex_asin(__complex__
decltype(0.0bf16) __z)
2178 {
return static_cast<__complex__ decltype(0.0bf16)
>(__builtin_casinf(__z)); }
2180 inline __complex__
decltype(0.0bf16)
2181 __complex_atan(__complex__
decltype(0.0bf16) __z)
2182 {
return static_cast<__complex__ decltype(0.0bf16)
>(__builtin_catanf(__z)); }
2184 inline __complex__
decltype(0.0bf16)
2185 __complex_acosh(__complex__
decltype(0.0bf16) __z)
2186 {
return static_cast<__complex__ decltype(0.0bf16)
>(__builtin_cacoshf(__z)); }
2188 inline __complex__
decltype(0.0bf16)
2189 __complex_asinh(__complex__
decltype(0.0bf16) __z)
2190 {
return static_cast<__complex__ decltype(0.0bf16)
>(__builtin_casinhf(__z)); }
2192 inline __complex__
decltype(0.0bf16)
2193 __complex_atanh(__complex__
decltype(0.0bf16) __z)
2194 {
return static_cast<__complex__ decltype(0.0bf16)
>(__builtin_catanhf(__z)); }
2198#if _GLIBCXX_USE_C99_COMPLEX_ARC
2199 inline __complex__
float
2200 __complex_acos(__complex__
float __z)
2201 {
return __builtin_cacosf(__z); }
2203 inline __complex__
double
2204 __complex_acos(__complex__
double __z)
2205 {
return __builtin_cacos(__z); }
2207 inline __complex__
long double
2208 __complex_acos(
const __complex__
long double& __z)
2209 {
return __builtin_cacosl(__z); }
2211 template<
typename _Tp>
2214 {
return __complex_acos(__z.__rep()); }
2219 template<
typename _Tp>
2222 {
return __complex_acos(__z); }
2225 template<
typename _Tp>
2230 __t = std::asinh(__t);
2234#if _GLIBCXX_USE_C99_COMPLEX_ARC
2235 inline __complex__
float
2236 __complex_asin(__complex__
float __z)
2237 {
return __builtin_casinf(__z); }
2239 inline __complex__
double
2240 __complex_asin(__complex__
double __z)
2241 {
return __builtin_casin(__z); }
2243 inline __complex__
long double
2244 __complex_asin(
const __complex__
long double& __z)
2245 {
return __builtin_casinl(__z); }
2247 template<
typename _Tp>
2250 {
return __complex_asin(__z.__rep()); }
2255 template<
typename _Tp>
2258 {
return __complex_asin(__z); }
2261 template<
typename _Tp>
2265 const _Tp __r2 = __z.real() * __z.real();
2266 const _Tp __x = _Tp(1.0) - __r2 - __z.imag() * __z.imag();
2268 _Tp __num = __z.imag() + _Tp(1.0);
2269 _Tp __den = __z.imag() - _Tp(1.0);
2271 __num = __r2 + __num * __num;
2272 __den = __r2 + __den * __den;
2275 _Tp(0.25) *
log(__num / __den));
2278#if _GLIBCXX_USE_C99_COMPLEX_ARC
2279 inline __complex__
float
2280 __complex_atan(__complex__
float __z)
2281 {
return __builtin_catanf(__z); }
2283 inline __complex__
double
2284 __complex_atan(__complex__
double __z)
2285 {
return __builtin_catan(__z); }
2287 inline __complex__
long double
2288 __complex_atan(
const __complex__
long double& __z)
2289 {
return __builtin_catanl(__z); }
2291 template<
typename _Tp>
2294 {
return __complex_atan(__z.__rep()); }
2299 template<
typename _Tp>
2302 {
return __complex_atan(__z); }
2305 template<
typename _Tp>
2311 +
std::sqrt(_Tp(0.5) * (__z - _Tp(1.0))));
2314#if _GLIBCXX_USE_C99_COMPLEX_ARC
2315 inline __complex__
float
2316 __complex_acosh(__complex__
float __z)
2317 {
return __builtin_cacoshf(__z); }
2319 inline __complex__
double
2320 __complex_acosh(__complex__
double __z)
2321 {
return __builtin_cacosh(__z); }
2323 inline __complex__
long double
2324 __complex_acosh(
const __complex__
long double& __z)
2325 {
return __builtin_cacoshl(__z); }
2327 template<
typename _Tp>
2330 {
return __complex_acosh(__z.__rep()); }
2335 template<
typename _Tp>
2338 {
return __complex_acosh(__z); }
2341 template<
typename _Tp>
2346 * (__z.real() + __z.imag()) + _Tp(1.0),
2347 _Tp(2.0) * __z.real() * __z.imag());
2353#if _GLIBCXX_USE_C99_COMPLEX_ARC
2354 inline __complex__
float
2355 __complex_asinh(__complex__
float __z)
2356 {
return __builtin_casinhf(__z); }
2358 inline __complex__
double
2359 __complex_asinh(__complex__
double __z)
2360 {
return __builtin_casinh(__z); }
2362 inline __complex__
long double
2363 __complex_asinh(
const __complex__
long double& __z)
2364 {
return __builtin_casinhl(__z); }
2366 template<
typename _Tp>
2369 {
return __complex_asinh(__z.__rep()); }
2374 template<
typename _Tp>
2377 {
return __complex_asinh(__z); }
2380 template<
typename _Tp>
2384 const _Tp __i2 = __z.imag() * __z.imag();
2385 const _Tp __x = _Tp(1.0) - __i2 - __z.real() * __z.real();
2387 _Tp __num = _Tp(1.0) + __z.real();
2388 _Tp __den = _Tp(1.0) - __z.real();
2390 __num = __i2 + __num * __num;
2391 __den = __i2 + __den * __den;
2394 _Tp(0.5) * atan2(_Tp(2.0) * __z.imag(), __x));
2397#if _GLIBCXX_USE_C99_COMPLEX_ARC
2398 inline __complex__
float
2399 __complex_atanh(__complex__
float __z)
2400 {
return __builtin_catanhf(__z); }
2402 inline __complex__
double
2403 __complex_atanh(__complex__
double __z)
2404 {
return __builtin_catanh(__z); }
2406 inline __complex__
long double
2407 __complex_atanh(
const __complex__
long double& __z)
2408 {
return __builtin_catanhl(__z); }
2410 template<
typename _Tp>
2413 {
return __complex_atanh(__z.__rep()); }
2418 template<
typename _Tp>
2421 {
return __complex_atanh(__z); }
2424 template<
typename _Tp>
2433 template<
typename _Tp>
2434 inline typename __gnu_cxx::__promote<_Tp>::__type
2437 typedef typename __gnu_cxx::__promote<_Tp>::__type __type;
2438#if (_GLIBCXX11_USE_C99_MATH && !_GLIBCXX_USE_C99_FP_MACROS_DYNAMIC)
2439 return std::signbit(__x) ? __type(3.1415926535897932384626433832795029L)
2446 template<
typename _Tp>
2447 _GLIBCXX_CONSTEXPR
inline typename __gnu_cxx::__promote<_Tp>::__type
2451 template<
typename _Tp>
2452 _GLIBCXX20_CONSTEXPR
inline typename __gnu_cxx::__promote<_Tp>::__type
2455 typedef typename __gnu_cxx::__promote<_Tp>::__type __type;
2456 return __type(__x) * __type(__x);
2459 template<
typename _Tp>
2460 _GLIBCXX_CONSTEXPR
inline typename __gnu_cxx::__promote<_Tp>::__type
2464 template<
typename _Tp,
typename _Up>
2468 typedef typename __gnu_cxx::__promote_2<_Tp, _Up>::__type __type;
2472 template<
typename _Tp,
typename _Up>
2476 typedef typename __gnu_cxx::__promote_2<_Tp, _Up>::__type __type;
2480 template<
typename _Tp,
typename _Up>
2484 typedef typename __gnu_cxx::__promote_2<_Tp, _Up>::__type __type;
2491 template<
typename _Tp>
2495 template<
typename _Tp>
2500#if _GLIBCXX_USE_C99_COMPLEX
2501 inline complex<float>
2502 __complex_proj(
const complex<float>& __z)
2503 {
return __builtin_cprojf(__z.__rep()); }
2505 inline complex<double>
2506 __complex_proj(
const complex<double>& __z)
2507 {
return __builtin_cproj(__z.__rep()); }
2509 inline complex<long double>
2510 __complex_proj(
const complex<long double>& __z)
2511 {
return __builtin_cprojl(__z.__rep()); }
2513#if __cplusplus > 202002L
2514#if defined(__STDCPP_FLOAT16_T__) && defined(_GLIBCXX_FLOAT_IS_IEEE_BINARY32)
2515 inline __complex__ _Float16
2516 __complex_proj(__complex__ _Float16 __z)
2517 {
return static_cast<__complex__ _Float16
>(__builtin_cprojf(__z)); }
2520#if defined(__STDCPP_FLOAT32_T__) && defined(_GLIBCXX_FLOAT_IS_IEEE_BINARY32)
2521 inline __complex__ _Float32
2522 __complex_proj(__complex__ _Float32 __z)
2523 {
return __builtin_cprojf(__z); }
2526#if defined(__STDCPP_FLOAT64_T__) && defined(_GLIBCXX_DOUBLE_IS_IEEE_BINARY64)
2527 inline __complex__ _Float64
2528 __complex_proj(__complex__ _Float64 __z)
2529 {
return __builtin_cproj(__z); }
2532#if defined(__STDCPP_FLOAT128_T__) && defined(_GLIBCXX_LDOUBLE_IS_IEEE_BINARY128)
2533 inline __complex__ _Float128
2534 __complex_proj(__complex__ _Float128 __z)
2535 {
return __builtin_cprojl(__z); }
2536#elif defined(__STDCPP_FLOAT128_T__) && defined(_GLIBCXX_HAVE_FLOAT128_MATH)
2537 inline __complex__ _Float128
2538 __complex_proj(__complex__ _Float128 __z)
2539 {
return __builtin_cprojf128(__z); }
2542#if defined(__STDCPP_BFLOAT16_T__) && defined(_GLIBCXX_FLOAT_IS_IEEE_BINARY32)
2543 inline __complex__
decltype(0.0bf16)
2544 __complex_proj(__complex__
decltype(0.0bf16) __z)
2545 {
return static_cast<__complex__ decltype(0.0bf16)
>(__builtin_cprojf(__z)); }
2548 template<
typename _Tp>
2549 requires requires {
typename __complex_type<_Tp>::type; }
2551 __complex_proj(
const complex<_Tp>& __z)
2552 {
return __complex_proj(__z.__rep()); }
2555#elif defined _GLIBCXX_USE_C99_MATH_FUNCS
2556 inline complex<float>
2557 __complex_proj(
const complex<float>& __z)
2559 if (__builtin_isinf(__z.real()) || __builtin_isinf(__z.imag()))
2560 return complex<float>(__builtin_inff(),
2561 __builtin_copysignf(0.0f, __z.imag()));
2565 inline complex<double>
2566 __complex_proj(
const complex<double>& __z)
2568 if (__builtin_isinf(__z.real()) || __builtin_isinf(__z.imag()))
2569 return complex<double>(__builtin_inf(),
2570 __builtin_copysign(0.0, __z.imag()));
2574 inline complex<long double>
2575 __complex_proj(
const complex<long double>& __z)
2577 if (__builtin_isinf(__z.real()) || __builtin_isinf(__z.imag()))
2578 return complex<long double>(__builtin_infl(),
2579 __builtin_copysignl(0.0l, __z.imag()));
2584 template<
typename _Tp>
2587 {
return __complex_proj(__z); }
2590 template<
typename _Tp>
2594 typedef typename __gnu_cxx::__promote<_Tp>::__type __type;
2598 template<
typename _Tp>
2599 inline _GLIBCXX20_CONSTEXPR
2603 typedef typename __gnu_cxx::__promote<_Tp>::__type __type;
2607#ifdef __cpp_lib_complex_udls
2609inline namespace literals {
2610inline namespace complex_literals {
2611#pragma GCC diagnostic push
2612#pragma GCC diagnostic ignored "-Wliteral-suffix"
2615 operator""if(
long double __num)
2619 operator""if(
unsigned long long __num)
2623 operator""i(
long double __num)
2627 operator""i(
unsigned long long __num)
2631 operator""il(
long double __num)
2635 operator""il(
unsigned long long __num)
2638#pragma GCC diagnostic pop
2644_GLIBCXX_END_NAMESPACE_VERSION
2650#pragma clang diagnostic pop
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...