Files
2025-10-25 03:02:53 +03:00

1007 lines
38 KiB
Markdown
Raw Permalink Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

[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 [<complex>](#header:%3ccomplex%3e "29.4.2Header <complex> 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.2Fundamental 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.1General"))[.](#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<T> then:
- [(4.1)](#general-4.1)
the expression reinterpret_cast<cv T(&)[2]>(z) is well-formed,
- [(4.2)](#general-4.2)
reinterpret_cast<cv T(&)[2]>(z)[0] designates the real part of z, and
- [(4.3)](#general-4.3)
reinterpret_cast<cv T(&)[2]>(z)[1] designates the imaginary part of z[.](#general-4.sentence-1)
Moreover, if a is an expression of type cv complex<T>* and the expression a[i] is well-defined for an integer expression i, then:
- [(4.4)](#general-4.4)
reinterpret_cast<cv T*>(a)[2 * i] designates the real part of a[i], and
- [(4.5)](#general-4.5)
reinterpret_cast<cv T*>(a)[2 * i + 1] designates the imaginary part of a[i][.](#general-4.sentence-2)
### [29.4.2](#complex.syn) Header <complex> synopsis [[complex.syn]](complex.syn)
[🔗](#header:%3ccomplex%3e)
namespace std {// [[complex]](#complex "29.4.3Class template complex"), class template complextemplate<class T> class complex; // [[complex.ops]](#complex.ops "29.4.6Non-member operations"), operatorstemplate<class T> constexpr complex<T> operator+(const complex<T>&, const complex<T>&); template<class T> constexpr complex<T> operator+(const complex<T>&, const T&); template<class T> constexpr complex<T> operator+(const T&, const complex<T>&); template<class T> constexpr complex<T> operator-(const complex<T>&, const complex<T>&); template<class T> constexpr complex<T> operator-(const complex<T>&, const T&); template<class T> constexpr complex<T> operator-(const T&, const complex<T>&); template<class T> constexpr complex<T> operator*(const complex<T>&, const complex<T>&); template<class T> constexpr complex<T> operator*(const complex<T>&, const T&); template<class T> constexpr complex<T> operator*(const T&, const complex<T>&); template<class T> constexpr complex<T> operator/(const complex<T>&, const complex<T>&); template<class T> constexpr complex<T> operator/(const complex<T>&, const T&); template<class T> constexpr complex<T> operator/(const T&, const complex<T>&); template<class T> constexpr complex<T> operator+(const complex<T>&); template<class T> constexpr complex<T> operator-(const complex<T>&); template<class T> constexpr bool operator==(const complex<T>&, const complex<T>&); template<class T> constexpr bool operator==(const complex<T>&, const T&); template<class T, class charT, class traits> basic_istream<charT, traits>& operator>>(basic_istream<charT, traits>&, complex<T>&); template<class T, class charT, class traits> basic_ostream<charT, traits>& operator<<(basic_ostream<charT, traits>&, const complex<T>&); // [[complex.value.ops]](#complex.value.ops "29.4.7Value operations"), valuestemplate<class T> constexpr T real(const complex<T>&); template<class T> constexpr T imag(const complex<T>&); template<class T> constexpr T abs(const complex<T>&); template<class T> constexpr T arg(const complex<T>&); template<class T> constexpr T norm(const complex<T>&); template<class T> constexpr complex<T> conj(const complex<T>&); template<class T> constexpr complex<T> proj(const complex<T>&); template<class T> constexpr complex<T> polar(const T&, const T& = T()); // [[complex.transcendentals]](#complex.transcendentals "29.4.8Transcendentals"), transcendentalstemplate<class T> constexpr complex<T> acos(const complex<T>&); template<class T> constexpr complex<T> asin(const complex<T>&); template<class T> constexpr complex<T> atan(const complex<T>&); template<class T> constexpr complex<T> acosh(const complex<T>&); template<class T> constexpr complex<T> asinh(const complex<T>&); template<class T> constexpr complex<T> atanh(const complex<T>&); template<class T> constexpr complex<T> cos (const complex<T>&); template<class T> constexpr complex<T> cosh (const complex<T>&); template<class T> constexpr complex<T> exp (const complex<T>&); template<class T> constexpr complex<T> log (const complex<T>&); template<class T> constexpr complex<T> log10(const complex<T>&); template<class T> constexpr complex<T> pow (const complex<T>&, const T&); template<class T> constexpr complex<T> pow (const complex<T>&, const complex<T>&); template<class T> constexpr complex<T> pow (const T&, const complex<T>&); template<class T> constexpr complex<T> sin (const complex<T>&); template<class T> constexpr complex<T> sinh (const complex<T>&); template<class T> constexpr complex<T> sqrt (const complex<T>&); template<class T> constexpr complex<T> tan (const complex<T>&); template<class T> constexpr complex<T> tanh (const complex<T>&); // [[complex.tuple]](#complex.tuple "29.4.9Tuple interface"), tuple interfacetemplate<class T> struct tuple_size; template<size_t I, class T> struct tuple_element; template<class T> struct tuple_size<complex<T>>; template<size_t I, class T> struct tuple_element<I, complex<T>>; template<size_t I, class T>constexpr T& get(complex<T>&) noexcept; template<size_t I, class T>constexpr T&& get(complex<T>&&) noexcept; template<size_t I, class T>constexpr const T& get(const complex<T>&) noexcept; template<size_t I, class T>constexpr const T&& get(const complex<T>&&) noexcept; // [[complex.literals]](#complex.literals "29.4.11Suffixes for complex number literals"), complex literalsinline namespace literals {inline namespace complex_literals {constexpr complex<long double> operator""il(long double); constexpr complex<long double> operator""il(unsigned long long); constexpr complex<double> operator""i(long double); constexpr complex<double> operator""i(unsigned long long); constexpr complex<float> operator""if(long double); constexpr complex<float> operator""if(unsigned long long); }}}
### [29.4.3](#complex) Class template complex [[complex]](complex)
[🔗](#lib:complex)
namespace std {template<class T> class complex {public:using value_type = T; constexpr complex(const T& re = T(), const T& im = T()); constexpr complex(const complex&) = default; template<class X> constexpr explicit(*see below*) complex(const complex<X>&); 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<class X> constexpr complex& operator= (const complex<X>&); template<class X> constexpr complex& operator+=(const complex<X>&); template<class X> constexpr complex& operator-=(const complex<X>&); template<class X> constexpr complex& operator*=(const complex<X>&); template<class X> constexpr complex& operator/=(const complex<X>&); };}
[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<class X> constexpr explicit(see below) complex(const complex<X>& 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<class X> constexpr complex& operator=(const complex<X>& 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<class X> constexpr complex& operator+=(const complex<X>& 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<class X> constexpr complex& operator-=(const complex<X>& 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<class X> constexpr complex& operator*=(const complex<X>& 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<class X> constexpr complex& operator/=(const complex<X>& 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<class T> constexpr complex<T> operator+(const complex<T>& lhs);
`
[1](#complex.ops-1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L606)
*Returns*: complex<T>(lhs)[.](#complex.ops-1.sentence-1)
[🔗](#complex.ops-itemdecl:2)
`template<class T> constexpr complex<T> operator+(const complex<T>& lhs, const complex<T>& rhs);
template<class T> constexpr complex<T> operator+(const complex<T>& lhs, const T& rhs);
template<class T> constexpr complex<T> operator+(const T& lhs, const complex<T>& rhs);
`
[2](#complex.ops-2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L618)
*Returns*: complex<T>(lhs) += rhs[.](#complex.ops-2.sentence-1)
[🔗](#lib:operator-,complex)
`template<class T> constexpr complex<T> operator-(const complex<T>& lhs);
`
[3](#complex.ops-3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L629)
*Returns*: complex<T>(-lhs.real(),-lhs.imag())[.](#complex.ops-3.sentence-1)
[🔗](#lib:operator-,complex_)
`template<class T> constexpr complex<T> operator-(const complex<T>& lhs, const complex<T>& rhs);
template<class T> constexpr complex<T> operator-(const complex<T>& lhs, const T& rhs);
template<class T> constexpr complex<T> operator-(const T& lhs, const complex<T>& rhs);
`
[4](#complex.ops-4)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L642)
*Returns*: complex<T>(lhs) -= rhs[.](#complex.ops-4.sentence-1)
[🔗](#lib:operator*,complex)
`template<class T> constexpr complex<T> operator*(const complex<T>& lhs, const complex<T>& rhs);
template<class T> constexpr complex<T> operator*(const complex<T>& lhs, const T& rhs);
template<class T> constexpr complex<T> operator*(const T& lhs, const complex<T>& rhs);
`
[5](#complex.ops-5)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L655)
*Returns*: complex<T>(lhs) *= rhs[.](#complex.ops-5.sentence-1)
[🔗](#lib:operator/,complex)
`template<class T> constexpr complex<T> operator/(const complex<T>& lhs, const complex<T>& rhs);
template<class T> constexpr complex<T> operator/(const complex<T>& lhs, const T& rhs);
template<class T> constexpr complex<T> operator/(const T& lhs, const complex<T>& rhs);
`
[6](#complex.ops-6)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L668)
*Returns*: complex<T>(lhs) /= rhs[.](#complex.ops-6.sentence-1)
[🔗](#lib:operator==,complex)
`template<class T> constexpr bool operator==(const complex<T>& lhs, const complex<T>& rhs);
template<class T> constexpr bool operator==(const complex<T>& 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<class T, class charT, class traits>
basic_istream<charT, traits>& operator>>(basic_istream<charT, traits>& is, complex<T>& 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.3Formatted 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.4Flags 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<class T, class charT, class traits>
basic_ostream<charT, traits>& operator<<(basic_ostream<charT, traits>& o, const complex<T>& 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<charT, traits> 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<class T> constexpr T real(const complex<T>& 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<class T> constexpr T imag(const complex<T>& 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<class T> constexpr T abs(const complex<T>& 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<class T> constexpr T arg(const complex<T>& 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<class T> constexpr T norm(const complex<T>& 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<class T> constexpr complex<T> conj(const complex<T>& 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<class T> constexpr complex<T> proj(const complex<T>& 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<class T> constexpr complex<T> 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<class T> constexpr complex<T> acos(const complex<T>& 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<class T> constexpr complex<T> asin(const complex<T>& 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<class T> constexpr complex<T> atan(const complex<T>& 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<class T> constexpr complex<T> acosh(const complex<T>& 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<class T> constexpr complex<T> asinh(const complex<T>& 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<class T> constexpr complex<T> atanh(const complex<T>& 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<class T> constexpr complex<T> cos(const complex<T>& 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<class T> constexpr complex<T> cosh(const complex<T>& 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<class T> constexpr complex<T> exp(const complex<T>& 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<class T> constexpr complex<T> log(const complex<T>& 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<class T> constexpr complex<T> log10(const complex<T>& 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<class T> constexpr complex<T> pow(const complex<T>& x, const complex<T>& y);
template<class T> constexpr complex<T> pow(const complex<T>& x, const T& y);
template<class T> constexpr complex<T> pow(const T& x, const complex<T>& 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<class T> constexpr complex<T> sin(const complex<T>& 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<class T> constexpr complex<T> sinh(const complex<T>& 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<class T> constexpr complex<T> sqrt(const complex<T>& 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<class T> constexpr complex<T> tan(const complex<T>& 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<class T> constexpr complex<T> tanh(const complex<T>& 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<class T>
struct tuple_size<complex<T>> : integral_constant<size_t, 2> {};
template<size_t I, class T>
struct tuple_element<I, complex<T>> {
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<size_t I, class T>
constexpr T& get(complex<T>& z) noexcept;
template<size_t I, class T>
constexpr T&& get(complex<T>&& z) noexcept;
template<size_t I, class T>
constexpr const T& get(const complex<T>& z) noexcept;
template<size_t I, class T>
constexpr const T&& get(const complex<T>&& 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<T>[.](#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<double>[.](#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<T1> and
the other argument of type T2 or complex<T2>,
both arguments are effectively cast to complex<common_type_t<T1, T3>>,
where T3 isdouble if T2 is an integer type and T2 otherwise[.](#cmplx.over-3.sentence-1)
If common_type_t<T1, T3> 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<double>, complex<long double>, andcomplex<float> 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<long double> operator""il(long double d);
constexpr complex<long double> operator""il(unsigned long long d);
`
[2](#complex.literals-2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L1226)
*Returns*: complex<long double>{0.0L, static_cast<long double>(d)}[.](#complex.literals-2.sentence-1)
[🔗](#lib:operator%22%22i,complex)
`constexpr complex<double> operator""i(long double d);
constexpr complex<double> operator""i(unsigned long long d);
`
[3](#complex.literals-3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L1238)
*Returns*: complex<double>{0.0, static_cast<double>(d)}[.](#complex.literals-3.sentence-1)
[🔗](#lib:operator%22%22if,complex)
`constexpr complex<float> operator""if(long double d);
constexpr complex<float> operator""if(unsigned long long d);
`
[4](#complex.literals-4)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/numerics.tex#L1250)
*Returns*: complex<float>{0.0f, static_cast<float>(d)}[.](#complex.literals-4.sentence-1)