# 标准库头文件 <complex>

< cpp‎ | header

此头文件是数值库的一部分。

### 类

complex | 复数类型 (类模板)
`complex`<float>`complex`<double>`complex`<long double> | 复数类型 (类模板特化)

### 函数

##### 运算
operator+operator- | 对复数运用一元运算符 (函数模板)
operator+operator-operator*operator/ | 在两个复数，或一个复数与一个标量上进行复数算术运算 (函数模板)
operator==operator!= (C++20 中移除) | 比较两个复数，或一个复数与一个标量 (函数模板)
operator<<operator>> | 复数的序列化和反序列化 (函数模板)
real | 返回实部 (函数模板)
imag | 返回虚部 (函数模板)
abs(std::complex) | 返回复数的模 (函数模板)
arg | 返回辐角 (函数模板)
norm | 返回模(范数)的平方 (函数模板)
conj | 返回复共轭 (函数模板)
proj (C++11) | 返回到黎曼球上的投影 (函数模板)
polar | 从模和辐角构造复数 (函数模板)
##### 指数函数
exp(std::complex) | 以 e 为底复数的指数 (函数模板)
log(std::complex) | 沿负实轴切割的复自然对数 (函数模板)
log10(std::complex) | 沿负实轴分割的复常用对数 (函数模板)
##### 幂函数
pow(std::complex) | 复数幂，一或两个参数可为复数 (函数模板)
sqrt(std::complex) | 右半平面范围中的复平方根 (函数模板)
##### 三角函数
sin(std::complex) | 计算复数的正弦（ \({\small\sin{z} }\)sin(z) ） (函数模板)
cos(std::complex) | 计算复数的余弦（ \({\small\cos{z} }\)cos(z) ） (函数模板)
tan(std::complex) | 计算复数的正切（ \({\small\tan{z} }\)tan(z) ） (函数模板)
asin(std::complex) (C++11) | 计算复数的反正弦（ \({\small\arcsin{z} }\)arcsin(z) ） (函数模板)
acos(std::complex) (C++11) | 计算复数的反余弦（ \({\small\arccos{z} }\)arccos(z) ） (函数模板)
atan(std::complex) (C++11) | 计算复数的反正切（ \({\small\arctan{z} }\)arctan(z) ） (函数模板)
##### 双曲函数
sinh(std::complex) | 计算复数的双曲正弦（ \({\small\sinh{z} }\)sinh(z) ） (函数模板)
cosh(std::complex) | 计算复数的双曲余弦（ \({\small\cosh{z} }\)cosh(z) ） (函数模板)
tanh(std::complex) | 计算复数的双曲正切（ \({\small\tanh{z} }\)tanh(z) ） (函数模板)
asinh(std::complex) (C++11) | 计算复数的反双曲正弦（ \({\small\operatorname{arsinh}{z} }\)arsinh(z) ） (函数模板)
acosh(std::complex) (C++11) | 计算复数的反双曲余弦（ \({\small\operatorname{arcosh}{z} }\)arcosh(z) ） (函数模板)
atanh(std::complex) (C++11) | 计算复数的反双曲正切（ \({\small\operatorname{artanh}{z} }\)artanh(z) ） (函数模板)
##### 字面量
operator""if operator""i operator""il (C++14) | 表示纯虚数的 std::complex 字面量 (函数)

### 概要

    namespace std {

        template<class T> class complex;

        template<> class complex<float>;
        template<> class complex<double>;
        template<> class complex<long double>;

        // 运算符：
        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>&, 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> constexpr bool operator==(const T&, 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> constexpr bool operator!=(const T&, const complex<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>&);

        // 值：
        template<class T> constexpr T real(const complex<T>&);
        template<class T> constexpr T imag(const complex<T>&);

        template<class T> T abs(const complex<T>&);
        template<class T> 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> complex<T> proj(const complex<T>&);
        template<class T> complex<T> polar(const T&, const T& = 0);

        // 超越函数：
        template<class T> complex<T> acos(const complex<T>&);
        template<class T> complex<T> asin(const complex<T>&);
        template<class T> complex<T> atan(const complex<T>&);

        template<class T> complex<T> acosh(const complex<T>&);
        template<class T> complex<T> asinh(const complex<T>&);
        template<class T> complex<T> atanh(const complex<T>&);

        template<class T> complex<T> cos  (const complex<T>&);
        template<class T> complex<T> cosh (const complex<T>&);
        template<class T> complex<T> exp  (const complex<T>&);
        template<class T> complex<T> log  (const complex<T>&);
        template<class T> complex<T> log10(const complex<T>&);

        template<class T> complex<T> pow(const complex<T>&, const T&);
        template<class T> complex<T> pow(const complex<T>&, const complex<T>&);
        template<class T> complex<T> pow(const T&, const complex<T>&);

        template<class T> complex<T> sin    (const complex<T>&);
        template<class T> complex<T> sinh   (const complex<T>&);
        template<class T> complex<T> sqrt   (const complex<T>&);
        template<class T> complex<T> tan    (const complex<T>&);
        template<class T> complex<T> tanh   (const complex<T>&);

        // 复数字面量：
        inline 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);
        }
        }
    }

#### 类 std::complex

    template<class T>
    class complex {
    public:
        typedef T value_type;
        constexpr complex(const T& re = T(), const T& im = T());
        constexpr complex(const complex&);
        template<class X> constexpr complex(const complex<X>&);

        constexpr T real() const;
        constexpr void real(T);
        constexpr T imag() const;
        constexpr void imag(T);

        constexpr complex<T>& operator= (const T&);
        constexpr complex<T>& operator+=(const T&);
        constexpr complex<T>& operator-=(const T&);
        constexpr complex<T>& operator*=(const T&);
        constexpr complex<T>& operator/=(const T&);

        constexpr complex& operator=(const complex&);
        template<class X> constexpr complex<T>& operator= (const complex<X>&);
        template<class X> constexpr complex<T>& operator+=(const complex<X>&);
        template<class X> constexpr complex<T>& operator-=(const complex<X>&);
        template<class X> constexpr complex<T>& operator*=(const complex<X>&);
        template<class X> constexpr complex<T>& operator/=(const complex<X>&);

    };

#### std::complex 特化

    template<> class complex<float> {
    public:
        typedef float value_type;

        constexpr complex(float re = 0.0f, float im = 0.0f);
        explicit constexpr complex(const complex<double>&);
        explicit constexpr complex(const complex<long double>&);

        constexpr float real() const;
        constexpr void real(float);
        constexpr float imag() const;
        constexpr void imag(float);

        constexpr complex<float>& operator= (float);
        constexpr complex<float>& operator+=(float);
        constexpr complex<float>& operator-=(float);
        constexpr complex<float>& operator*=(float);
        constexpr complex<float>& operator/=(float);

        constexpr complex<float>& operator=(const complex<float>&);
        template<class X> constexpr complex<float>& operator= (const complex<X>&);
        template<class X> constexpr complex<float>& operator+=(const complex<X>&);
        template<class X> constexpr complex<float>& operator-=(const complex<X>&);
        template<class X> constexpr complex<float>& operator*=(const complex<X>&);
        template<class X> constexpr complex<float>& operator/=(const complex<X>&);
    };

    template<> class complex<double> {
    public:
        typedef double value_type;

        constexpr complex(double re = 0.0, double im = 0.0);
        constexpr complex(const complex<float>&);
        explicit constexpr complex(const complex<long double>&);

        constexpr double real() const;
        constexpr void real(double);
        constexpr double imag() const;
        constexpr void imag(double);

        constexpr complex<double>& operator= (double);
        constexpr complex<double>& operator+=(double);
        constexpr complex<double>& operator-=(double);
        constexpr complex<double>& operator*=(double);
        constexpr complex<double>& operator/=(double);

        constexpr complex<double>& operator=(const complex<double>&);
        template<class X> constexpr complex<double>& operator= (const complex<X>&);
        template<class X> constexpr complex<double>& operator+=(const complex<X>&);
        template<class X> constexpr complex<double>& operator-=(const complex<X>&);
        template<class X> constexpr complex<double>& operator*=(const complex<X>&);
        template<class X> constexpr complex<double>& operator/=(const complex<X>&);
    };

    template<> class complex<long double> {
    public:
        typedef long double value_type;

        constexpr complex(long double re = 0.0L, long double im = 0.0L);
        constexpr complex(const complex<float>&);
        constexpr complex(const complex<double>&);

        constexpr long double real() const;
        constexpr void real(long double);
        constexpr long double imag() const;
        constexpr void imag(long double);

        constexpr complex<long double>& operator=(const complex<long double>&);
        constexpr complex<long double>& operator= (long double);
        constexpr complex<long double>& operator+=(long double);
        constexpr complex<long double>& operator-=(long double);
        constexpr complex<long double>& operator*=(long double);
        constexpr complex<long double>& operator/=(long double);

        template<class X> constexpr complex<long double>& operator= (const complex<X>&);
        template<class X> constexpr complex<long double>& operator+=(const complex<X>&);
        template<class X> constexpr complex<long double>& operator-=(const complex<X>&);
        template<class X> constexpr complex<long double>& operator*=(const complex<X>&);
        template<class X> constexpr complex<long double>& operator/=(const complex<X>&);

    };