[complex.numbers] # 29 Numerics library [[numerics]](./#numerics) ## 29.4 Complex numbers [complex.numbers] ### [29.4.1](#general) General [[complex.numbers.general]](complex.numbers.general) [1](#general-1) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L180) The header [](#header:%3ccomplex%3e "29.4.2 Header synopsis [complex.syn]") defines a class template, and numerous functions for representing and manipulating complex numbers[.](#general-1.sentence-1) [2](#general-2) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L184) The effect of instantiating the primary template of complex for any type that is not a cv-unqualified floating-point type ([[basic.fundamental]](basic.fundamental "6.9.2 Fundamental types")) is unspecified[.](#general-2.sentence-1) Specializations of complex for cv-unqualified floating-point types are trivially copyable literal types ([[basic.types.general]](basic.types.general#term.literal.type "6.9.1 General"))[.](#general-2.sentence-2) [3](#general-3) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L191) If the result of a function is not mathematically defined or not in the range of representable values for its type, the behavior is undefined[.](#general-3.sentence-1) [4](#general-4) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L196) If z is an lvalue of type cv complex then: - [(4.1)](#general-4.1) the expression reinterpret_cast(z) is well-formed, - [(4.2)](#general-4.2) reinterpret_cast(z)[0] designates the real part of z, and - [(4.3)](#general-4.3) reinterpret_cast(z)[1] designates the imaginary part of z[.](#general-4.sentence-1) Moreover, if a is an expression of type cv complex* and the expression a[i] is well-defined for an integer expression i, then: - [(4.4)](#general-4.4) reinterpret_cast(a)[2 * i] designates the real part of a[i], and - [(4.5)](#general-4.5) reinterpret_cast(a)[2 * i + 1] designates the imaginary part of a[i][.](#general-4.sentence-2) ### [29.4.2](#complex.syn) Header synopsis [[complex.syn]](complex.syn) [🔗](#header:%3ccomplex%3e) namespace std {// [[complex]](#complex "29.4.3 Class template complex"), class template complextemplate class complex; // [[complex.ops]](#complex.ops "29.4.6 Non-member operations"), operatorstemplate constexpr complex operator+(const complex&, const complex&); template constexpr complex operator+(const complex&, const T&); template constexpr complex operator+(const T&, const complex&); template constexpr complex operator-(const complex&, const complex&); template constexpr complex operator-(const complex&, const T&); template constexpr complex operator-(const T&, const complex&); template constexpr complex operator*(const complex&, const complex&); template constexpr complex operator*(const complex&, const T&); template constexpr complex operator*(const T&, const complex&); template constexpr complex operator/(const complex&, const complex&); template constexpr complex operator/(const complex&, const T&); template constexpr complex operator/(const T&, const complex&); template constexpr complex operator+(const complex&); template constexpr complex operator-(const complex&); template constexpr bool operator==(const complex&, const complex&); template constexpr bool operator==(const complex&, const T&); template basic_istream& operator>>(basic_istream&, complex&); template basic_ostream& operator<<(basic_ostream&, const complex&); // [[complex.value.ops]](#complex.value.ops "29.4.7 Value operations"), valuestemplate constexpr T real(const complex&); template constexpr T imag(const complex&); template constexpr T abs(const complex&); template constexpr T arg(const complex&); template constexpr T norm(const complex&); template constexpr complex conj(const complex&); template constexpr complex proj(const complex&); template constexpr complex polar(const T&, const T& = T()); // [[complex.transcendentals]](#complex.transcendentals "29.4.8 Transcendentals"), transcendentalstemplate constexpr complex acos(const complex&); template constexpr complex asin(const complex&); template constexpr complex atan(const complex&); template constexpr complex acosh(const complex&); template constexpr complex asinh(const complex&); template constexpr complex atanh(const complex&); template constexpr complex cos (const complex&); template constexpr complex cosh (const complex&); template constexpr complex exp (const complex&); template constexpr complex log (const complex&); template constexpr complex log10(const complex&); template constexpr complex pow (const complex&, const T&); template constexpr complex pow (const complex&, const complex&); template constexpr complex pow (const T&, const complex&); template constexpr complex sin (const complex&); template constexpr complex sinh (const complex&); template constexpr complex sqrt (const complex&); template constexpr complex tan (const complex&); template constexpr complex tanh (const complex&); // [[complex.tuple]](#complex.tuple "29.4.9 Tuple interface"), tuple interfacetemplate struct tuple_size; template struct tuple_element; template struct tuple_size>; template struct tuple_element>; templateconstexpr T& get(complex&) noexcept; templateconstexpr T&& get(complex&&) noexcept; templateconstexpr const T& get(const complex&) noexcept; templateconstexpr const T&& get(const complex&&) noexcept; // [[complex.literals]](#complex.literals "29.4.11 Suffixes for complex number literals"), complex literalsinline namespace literals {inline namespace complex_literals {constexpr complex operator""il(long double); constexpr complex operator""il(unsigned long long); constexpr complex operator""i(long double); constexpr complex operator""i(unsigned long long); constexpr complex operator""if(long double); constexpr complex operator""if(unsigned long long); }}} ### [29.4.3](#complex) Class template complex [[complex]](complex) [🔗](#lib:complex) namespace std {template class complex {public:using value_type = T; constexpr complex(const T& re = T(), const T& im = T()); constexpr complex(const complex&) = default; template constexpr explicit(*see below*) complex(const complex&); constexpr T real() const; constexpr void real(T); constexpr T imag() const; constexpr void imag(T); constexpr complex& operator= (const T&); constexpr complex& operator+=(const T&); constexpr complex& operator-=(const T&); constexpr complex& operator*=(const T&); constexpr complex& operator/=(const T&); constexpr complex& operator=(const complex&); template constexpr complex& operator= (const complex&); template constexpr complex& operator+=(const complex&); template constexpr complex& operator-=(const complex&); template constexpr complex& operator*=(const complex&); template constexpr complex& operator/=(const complex&); };} [1](#complex-1) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L347) The classcomplex describes an object that can store the Cartesian components,real() andimag(), of a complex number[.](#complex-1.sentence-1) ### [29.4.4](#complex.members) Member functions [[complex.members]](complex.members) [🔗](#lib:complex,constructor) `constexpr complex(const T& re = T(), const T& im = T()); ` [1](#complex.members-1) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L366) *Postconditions*: real() == re && imag() == im is true[.](#complex.members-1.sentence-1) [🔗](#lib:complex,constructor_) `template constexpr explicit(see below) complex(const complex& other); ` [2](#complex.members-2) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L377) *Effects*: Initializes the real part with other.real() and the imaginary part with other.imag()[.](#complex.members-2.sentence-1) [3](#complex.members-3) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L382) *Remarks*: The expression inside explicit evaluates to false if and only if the floating-point conversion rank of T is greater than or equal to the floating-point conversion rank of X[.](#complex.members-3.sentence-1) [🔗](#lib:real,complex) `constexpr T real() const; ` [4](#complex.members-4) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L395) *Returns*: The value of the real component[.](#complex.members-4.sentence-1) [🔗](#lib:real,complex_) `constexpr void real(T val); ` [5](#complex.members-5) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L406) *Effects*: Assigns val to the real component[.](#complex.members-5.sentence-1) [🔗](#lib:imag,complex) `constexpr T imag() const; ` [6](#complex.members-6) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L417) *Returns*: The value of the imaginary component[.](#complex.members-6.sentence-1) [🔗](#lib:imag,complex_) `constexpr void imag(T val); ` [7](#complex.members-7) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L428) *Effects*: Assigns val to the imaginary component[.](#complex.members-7.sentence-1) ### [29.4.5](#complex.member.ops) Member operators [[complex.member.ops]](complex.member.ops) [🔗](#lib:operator+=,complex) `constexpr complex& operator+=(const T& rhs); ` [1](#complex.member.ops-1) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L441) *Effects*: Adds the scalar value rhs to the real part of the complex value*this and stores the result in the real part of*this, leaving the imaginary part unchanged[.](#complex.member.ops-1.sentence-1) [2](#complex.member.ops-2) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L449) *Returns*: *this[.](#complex.member.ops-2.sentence-1) [🔗](#lib:operator-=,complex) `constexpr complex& operator-=(const T& rhs); ` [3](#complex.member.ops-3) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L460) *Effects*: Subtracts the scalar value rhs from the real part of the complex value*this and stores the result in the real part of*this, leaving the imaginary part unchanged[.](#complex.member.ops-3.sentence-1) [4](#complex.member.ops-4) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L468) *Returns*: *this[.](#complex.member.ops-4.sentence-1) [🔗](#lib:operator*=,complex) `constexpr complex& operator*=(const T& rhs); ` [5](#complex.member.ops-5) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L479) *Effects*: Multiplies the scalar value rhs by the complex value*this and stores the result in*this[.](#complex.member.ops-5.sentence-1) [6](#complex.member.ops-6) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L486) *Returns*: *this[.](#complex.member.ops-6.sentence-1) [🔗](#lib:operator/=,complex) `constexpr complex& operator/=(const T& rhs); ` [7](#complex.member.ops-7) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L497) *Effects*: Divides the scalar value rhs into the complex value*this and stores the result in*this[.](#complex.member.ops-7.sentence-1) [8](#complex.member.ops-8) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L504) *Returns*: *this[.](#complex.member.ops-8.sentence-1) [🔗](#lib:operator=,complex) `template constexpr complex& operator=(const complex& rhs); ` [9](#complex.member.ops-9) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L515) *Effects*: Assigns the value rhs.real() to the real part and the value rhs.imag() to the imaginary part of the complex value *this[.](#complex.member.ops-9.sentence-1) [10](#complex.member.ops-10) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L521) *Returns*: *this[.](#complex.member.ops-10.sentence-1) [🔗](#lib:operator+=,complex_) `template constexpr complex& operator+=(const complex& rhs); ` [11](#complex.member.ops-11) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L532) *Effects*: Adds the complex value rhs to the complex value*this and stores the sum in*this[.](#complex.member.ops-11.sentence-1) [12](#complex.member.ops-12) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L539) *Returns*: *this[.](#complex.member.ops-12.sentence-1) [🔗](#lib:operator-=,complex_) `template constexpr complex& operator-=(const complex& rhs); ` [13](#complex.member.ops-13) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L550) *Effects*: Subtracts the complex value rhs from the complex value*this and stores the difference in*this[.](#complex.member.ops-13.sentence-1) [14](#complex.member.ops-14) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L557) *Returns*: *this[.](#complex.member.ops-14.sentence-1) [🔗](#lib:operator*=,complex_) `template constexpr complex& operator*=(const complex& rhs); ` [15](#complex.member.ops-15) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L568) *Effects*: Multiplies the complex value rhs by the complex value*this and stores the product in*this[.](#complex.member.ops-15.sentence-1) [16](#complex.member.ops-16) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L575) *Returns*: *this[.](#complex.member.ops-16.sentence-1) [🔗](#lib:operator/=,complex_) `template constexpr complex& operator/=(const complex& rhs); ` [17](#complex.member.ops-17) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L586) *Effects*: Divides the complex value rhs into the complex value*this and stores the quotient in*this[.](#complex.member.ops-17.sentence-1) [18](#complex.member.ops-18) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L593) *Returns*: *this[.](#complex.member.ops-18.sentence-1) ### [29.4.6](#complex.ops) Non-member operations [[complex.ops]](complex.ops) [🔗](#lib:operator+,complex) `template constexpr complex operator+(const complex& lhs); ` [1](#complex.ops-1) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L606) *Returns*: complex(lhs)[.](#complex.ops-1.sentence-1) [🔗](#complex.ops-itemdecl:2) `template constexpr complex operator+(const complex& lhs, const complex& rhs); template constexpr complex operator+(const complex& lhs, const T& rhs); template constexpr complex operator+(const T& lhs, const complex& rhs); ` [2](#complex.ops-2) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L618) *Returns*: complex(lhs) += rhs[.](#complex.ops-2.sentence-1) [🔗](#lib:operator-,complex) `template constexpr complex operator-(const complex& lhs); ` [3](#complex.ops-3) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L629) *Returns*: complex(-lhs.real(),-lhs.imag())[.](#complex.ops-3.sentence-1) [🔗](#lib:operator-,complex_) `template constexpr complex operator-(const complex& lhs, const complex& rhs); template constexpr complex operator-(const complex& lhs, const T& rhs); template constexpr complex operator-(const T& lhs, const complex& rhs); ` [4](#complex.ops-4) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L642) *Returns*: complex(lhs) -= rhs[.](#complex.ops-4.sentence-1) [🔗](#lib:operator*,complex) `template constexpr complex operator*(const complex& lhs, const complex& rhs); template constexpr complex operator*(const complex& lhs, const T& rhs); template constexpr complex operator*(const T& lhs, const complex& rhs); ` [5](#complex.ops-5) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L655) *Returns*: complex(lhs) *= rhs[.](#complex.ops-5.sentence-1) [🔗](#lib:operator/,complex) `template constexpr complex operator/(const complex& lhs, const complex& rhs); template constexpr complex operator/(const complex& lhs, const T& rhs); template constexpr complex operator/(const T& lhs, const complex& rhs); ` [6](#complex.ops-6) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L668) *Returns*: complex(lhs) /= rhs[.](#complex.ops-6.sentence-1) [🔗](#lib:operator==,complex) `template constexpr bool operator==(const complex& lhs, const complex& rhs); template constexpr bool operator==(const complex& lhs, const T& rhs); ` [7](#complex.ops-7) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L680) *Returns*: lhs.real() == rhs.real() && lhs.imag() == rhs.imag()[.](#complex.ops-7.sentence-1) [8](#complex.ops-8) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L684) *Remarks*: The imaginary part is assumed to beT(), or 0.0, for theT arguments[.](#complex.ops-8.sentence-1) [🔗](#lib:operator%3e%3e,complex) `template basic_istream& operator>>(basic_istream& is, complex& x); ` [9](#complex.ops-9) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L700) *Preconditions*: The input values are convertible toT[.](#complex.ops-9.sentence-1) [10](#complex.ops-10) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L705) *Effects*: Extracts a complex number x of the form:u,(u), or(u,v), whereu is the real part andv is the imaginary part ([[istream.formatted]](istream.formatted "31.7.5.3 Formatted input functions"))[.](#complex.ops-10.sentence-1) [11](#complex.ops-11) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L718) If bad input is encountered, callsis.setstate(ios_base​::​failbit) (which may throwios_base​::​​failure ([[iostate.flags]](iostate.flags "31.5.4.4 Flags functions")))[.](#complex.ops-11.sentence-1) [12](#complex.ops-12) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L724) *Returns*: is[.](#complex.ops-12.sentence-1) [13](#complex.ops-13) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L728) *Remarks*: This extraction is performed as a series of simpler extractions[.](#complex.ops-13.sentence-1) Therefore, the skipping of whitespace is specified to be the same for each of the simpler extractions[.](#complex.ops-13.sentence-2) [🔗](#lib:operator%3c%3c,complex) `template basic_ostream& operator<<(basic_ostream& o, const complex& x); ` [14](#complex.ops-14) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L743) *Effects*: Inserts the complex number x onto the stream o as if it were implemented as follows:basic_ostringstream s; s.flags(o.flags()); s.imbue(o.getloc()); s.precision(o.precision()); s << '(' << x.real() << ',' << x.imag() << ')';return o << s.str(); [15](#complex.ops-15) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L756) [*Note [1](#complex.ops-note-1)*: In a locale in which comma is used as a decimal point character, the use of comma as a field separator can be ambiguous[.](#complex.ops-15.sentence-1) Insertingshowpoint into the output stream forces all outputs to show an explicit decimal point character; as a result, all inserted sequences of complex numbers can be extracted unambiguously[.](#complex.ops-15.sentence-2) — *end note*] ### [29.4.7](#complex.value.ops) Value operations [[complex.value.ops]](complex.value.ops) [🔗](#lib:real,complex__) `template constexpr T real(const complex& x); ` [1](#complex.value.ops-1) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L774) *Returns*: x.real()[.](#complex.value.ops-1.sentence-1) [🔗](#lib:imag,complex__) `template constexpr T imag(const complex& x); ` [2](#complex.value.ops-2) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L785) *Returns*: x.imag()[.](#complex.value.ops-2.sentence-1) [🔗](#lib:abs,complex) `template constexpr T abs(const complex& x); ` [3](#complex.value.ops-3) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L796) *Returns*: The magnitude of x[.](#complex.value.ops-3.sentence-1) [🔗](#lib:arg,complex) `template constexpr T arg(const complex& x); ` [4](#complex.value.ops-4) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L807) *Returns*: The phase angle of x, or atan2(imag(x), real(x))[.](#complex.value.ops-4.sentence-1) [🔗](#lib:norm,complex) `template constexpr T norm(const complex& x); ` [5](#complex.value.ops-5) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L818) *Returns*: The squared magnitude of x[.](#complex.value.ops-5.sentence-1) [🔗](#lib:conj,complex) `template constexpr complex conj(const complex& x); ` [6](#complex.value.ops-6) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L829) *Returns*: The complex conjugate of x[.](#complex.value.ops-6.sentence-1) [🔗](#lib:proj,complex) `template constexpr complex proj(const complex& x); ` [7](#complex.value.ops-7) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L840) *Returns*: The projection of x onto the Riemann sphere[.](#complex.value.ops-7.sentence-1) [8](#complex.value.ops-8) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L844) *Remarks*: Behaves the same as the C function cproj[.](#complex.value.ops-8.sentence-1) See also: ISO/IEC 9899:2024, 7.3.9.5 [🔗](#lib:polar,complex) `template constexpr complex polar(const T& rho, const T& theta = T()); ` [9](#complex.value.ops-9) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L856) *Preconditions*: rho is non-negative and non-NaN[.](#complex.value.ops-9.sentence-1) theta is finite[.](#complex.value.ops-9.sentence-2) [10](#complex.value.ops-10) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L860) *Returns*: Thecomplex value corresponding to a complex number whose magnitude is rho and whose phase angle is theta[.](#complex.value.ops-10.sentence-1) ### [29.4.8](#complex.transcendentals) Transcendentals [[complex.transcendentals]](complex.transcendentals) [🔗](#lib:acos,complex) `template constexpr complex acos(const complex& x); ` [1](#complex.transcendentals-1) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L878) *Returns*: The complex arc cosine of x[.](#complex.transcendentals-1.sentence-1) [2](#complex.transcendentals-2) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L882) *Remarks*: Behaves the same as the C function cacos[.](#complex.transcendentals-2.sentence-1) See also: ISO/IEC 9899:2024, 7.3.5.1 [🔗](#lib:asin,complex) `template constexpr complex asin(const complex& x); ` [3](#complex.transcendentals-3) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L895) *Returns*: The complex arc sine of x[.](#complex.transcendentals-3.sentence-1) [4](#complex.transcendentals-4) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L899) *Remarks*: Behaves the same as the C function casin[.](#complex.transcendentals-4.sentence-1) See also: ISO/IEC 9899:2024, 7.3.5.2 [🔗](#lib:atan,complex) `template constexpr complex atan(const complex& x); ` [5](#complex.transcendentals-5) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L912) *Returns*: The complex arc tangent of x[.](#complex.transcendentals-5.sentence-1) [6](#complex.transcendentals-6) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L916) *Remarks*: Behaves the same as the C function catan[.](#complex.transcendentals-6.sentence-1) See also: ISO/IEC 9899:2024, 7.3.5.3 [🔗](#lib:acosh,complex) `template constexpr complex acosh(const complex& x); ` [7](#complex.transcendentals-7) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L929) *Returns*: The complex arc hyperbolic cosine of x[.](#complex.transcendentals-7.sentence-1) [8](#complex.transcendentals-8) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L933) *Remarks*: Behaves the same as the C function cacosh[.](#complex.transcendentals-8.sentence-1) See also: ISO/IEC 9899:2024, 7.3.6.1 [🔗](#lib:asinh,complex) `template constexpr complex asinh(const complex& x); ` [9](#complex.transcendentals-9) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L946) *Returns*: The complex arc hyperbolic sine of x[.](#complex.transcendentals-9.sentence-1) [10](#complex.transcendentals-10) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L950) *Remarks*: Behaves the same as the C function casinh[.](#complex.transcendentals-10.sentence-1) See also: ISO/IEC 9899:2024, 7.3.6.2 [🔗](#lib:atanh,complex) `template constexpr complex atanh(const complex& x); ` [11](#complex.transcendentals-11) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L963) *Returns*: The complex arc hyperbolic tangent of x[.](#complex.transcendentals-11.sentence-1) [12](#complex.transcendentals-12) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L967) *Remarks*: Behaves the same as the C function catanh[.](#complex.transcendentals-12.sentence-1) See also: ISO/IEC 9899:2024, 7.3.6.3 [🔗](#lib:cos,complex) `template constexpr complex cos(const complex& x); ` [13](#complex.transcendentals-13) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L979) *Returns*: The complex cosine of x[.](#complex.transcendentals-13.sentence-1) [🔗](#lib:cosh,complex) `template constexpr complex cosh(const complex& x); ` [14](#complex.transcendentals-14) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L990) *Returns*: The complex hyperbolic cosine of x[.](#complex.transcendentals-14.sentence-1) [🔗](#lib:exp,complex) `template constexpr complex exp(const complex& x); ` [15](#complex.transcendentals-15) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L1001) *Returns*: The complex base-e exponential of x[.](#complex.transcendentals-15.sentence-1) [🔗](#lib:log,complex) `template constexpr complex log(const complex& x); ` [16](#complex.transcendentals-16) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L1012) *Returns*: The complex natural (base-e) logarithm of x[.](#complex.transcendentals-16.sentence-1) For all x,imag(log(x)) lies in the interval [−π, π][.](#complex.transcendentals-16.sentence-2) [*Note [1](#complex.transcendentals-note-1)*: The semantics of this function are intended to be the same in C++ as they are for clog in C[.](#complex.transcendentals-16.sentence-3) — *end note*] [17](#complex.transcendentals-17) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L1021) *Remarks*: The branch cuts are along the negative real axis[.](#complex.transcendentals-17.sentence-1) [🔗](#lib:log10,complex) `template constexpr complex log10(const complex& x); ` [18](#complex.transcendentals-18) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L1032) *Returns*: The complex common (base-10) logarithm of x, defined aslog(x) / log(10)[.](#complex.transcendentals-18.sentence-1) [19](#complex.transcendentals-19) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L1037) *Remarks*: The branch cuts are along the negative real axis[.](#complex.transcendentals-19.sentence-1) [🔗](#lib:pow,complex) `template constexpr complex pow(const complex& x, const complex& y); template constexpr complex pow(const complex& x, const T& y); template constexpr complex pow(const T& x, const complex& y); ` [20](#complex.transcendentals-20) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L1050) *Returns*: The complex power of base x raised to the yth power, defined asexp(y * log(x))[.](#complex.transcendentals-20.sentence-1) The value returned forpow(0, 0) is implementation-defined[.](#complex.transcendentals-20.sentence-2) [21](#complex.transcendentals-21) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L1059) *Remarks*: The branch cuts are along the negative real axis[.](#complex.transcendentals-21.sentence-1) [🔗](#lib:sin,complex) `template constexpr complex sin(const complex& x); ` [22](#complex.transcendentals-22) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L1070) *Returns*: The complex sine of x[.](#complex.transcendentals-22.sentence-1) [🔗](#lib:sinh,complex) `template constexpr complex sinh(const complex& x); ` [23](#complex.transcendentals-23) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L1081) *Returns*: The complex hyperbolic sine of x[.](#complex.transcendentals-23.sentence-1) [🔗](#lib:sqrt,complex) `template constexpr complex sqrt(const complex& x); ` [24](#complex.transcendentals-24) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L1092) *Returns*: The complex square root of x, in the range of the right half-plane[.](#complex.transcendentals-24.sentence-1) [*Note [2](#complex.transcendentals-note-2)*: The semantics of this function are intended to be the same in C++ as they are for csqrt in C[.](#complex.transcendentals-24.sentence-2) — *end note*] [25](#complex.transcendentals-25) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L1101) *Remarks*: The branch cuts are along the negative real axis[.](#complex.transcendentals-25.sentence-1) [🔗](#lib:tan,complex) `template constexpr complex tan(const complex& x); ` [26](#complex.transcendentals-26) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L1112) *Returns*: The complex tangent of x[.](#complex.transcendentals-26.sentence-1) [🔗](#lib:tanh,complex) `template constexpr complex tanh(const complex& x); ` [27](#complex.transcendentals-27) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L1123) *Returns*: The complex hyperbolic tangent of x[.](#complex.transcendentals-27.sentence-1) ### [29.4.9](#complex.tuple) Tuple interface [[complex.tuple]](complex.tuple) [🔗](#lib:tuple_size) `template struct tuple_size> : integral_constant {}; template struct tuple_element> { using type = T; }; ` [1](#complex.tuple-1) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L1143) *Mandates*: I < 2 is true[.](#complex.tuple-1.sentence-1) [🔗](#lib:get,complex) `template constexpr T& get(complex& z) noexcept; template constexpr T&& get(complex&& z) noexcept; template constexpr const T& get(const complex& z) noexcept; template constexpr const T&& get(const complex&& z) noexcept; ` [2](#complex.tuple-2) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L1161) *Mandates*: I < 2 is true[.](#complex.tuple-2.sentence-1) [3](#complex.tuple-3) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L1165) *Returns*: A reference to the real part of z if I == 0 is true, otherwise a reference to the imaginary part of z[.](#complex.tuple-3.sentence-1) ### [29.4.10](#cmplx.over) Additional overloads [[cmplx.over]](cmplx.over) [1](#cmplx.over-1) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L1173) The following function templates have additional constexpr overloads:arg norm conj proj imag real [2](#cmplx.over-2) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L1186) The additional constexpr overloads are sufficient to ensure: - [(2.1)](#cmplx.over-2.1) If the argument has a floating-point type T, then it is effectively cast to complex[.](#cmplx.over-2.1.sentence-1) - [(2.2)](#cmplx.over-2.2) Otherwise, if the argument has integer type, then it is effectively cast to complex[.](#cmplx.over-2.2.sentence-1) [3](#cmplx.over-3) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L1198) Function template pow has additional constexpr overloads sufficient to ensure, for a call with one argument of type complex and the other argument of type T2 or complex, both arguments are effectively cast to complex>, where T3 isdouble if T2 is an integer type and T2 otherwise[.](#cmplx.over-3.sentence-1) If common_type_t is not well-formed, then the program is ill-formed[.](#cmplx.over-3.sentence-2) ### [29.4.11](#complex.literals) Suffixes for complex number literals [[complex.literals]](complex.literals) [1](#complex.literals-1) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L1212) This subclause describes literal suffixes for constructing complex number literals[.](#complex.literals-1.sentence-1) The suffixes i, il, and if create complex numbers of the types complex, complex, andcomplex respectively, with their imaginary part denoted by the given literal number and the real part being zero[.](#complex.literals-1.sentence-2) [🔗](#lib:operator%22%22il,complex) `constexpr complex operator""il(long double d); constexpr complex operator""il(unsigned long long d); ` [2](#complex.literals-2) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L1226) *Returns*: complex{0.0L, static_cast(d)}[.](#complex.literals-2.sentence-1) [🔗](#lib:operator%22%22i,complex) `constexpr complex operator""i(long double d); constexpr complex operator""i(unsigned long long d); ` [3](#complex.literals-3) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L1238) *Returns*: complex{0.0, static_cast(d)}[.](#complex.literals-3.sentence-1) [🔗](#lib:operator%22%22if,complex) `constexpr complex operator""if(long double d); constexpr complex operator""if(unsigned long long d); ` [4](#complex.literals-4) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L1250) *Returns*: complex{0.0f, static_cast(d)}[.](#complex.literals-4.sentence-1)