##### cppreference.com

##### Search

Create account

##### Namespaces

- Page
- Discussion

##### Variants

##### Views

- View
- Edit
- History

##### Actions

# Standard library header <complex>

From cppreference.com
< cpp‎ | header

This header is part of the numeric library.

### [edit] Classes

complex | a complex number type (class template)
`complex`<float>`complex`<double>`complex`<long double> | a complex number type (class template specialization)

### [edit] Functions

##### Operations
operator+operator- | applies unary operators to complex numbers (function template) [edit]
operator+operator-operator*operator/ | performs complex number arithmetics on two complex values or a complex and a scalar (function template) [edit]
operator==operator!= | compares two complex numbers or a complex and a scalar (function template) [edit]
operator<<operator>> | serializes and deserializes a complex number (function template) [edit]
real | returns the real component (function template) [edit]
imag | returns the imaginary component (function template) [edit]
abs(std::complex) | returns the magnitude of a complex number (function template) [edit]
arg | returns the phase angle (function template) [edit]
norm | returns the squared magnitude (function template) [edit]
conj | returns the complex conjugate (function template) [edit]
proj (C++11) | returns the projection onto the Riemann sphere (function template) [edit]
polar | constructs a complex number from magnitude and phase angle (function template) [edit]
##### Exponential functions
exp(std::complex) | complex base e exponential (function template) [edit]
log(std::complex) | complex natural logarithm with the branch cuts along the negative real axis (function template) [edit]
log10(std::complex) | complex common logarithm with the branch cuts along the negative real axis (function template) [edit]
##### Power functions
pow(std::complex) | complex power, one or both arguments may be a complex number (function template) [edit]
sqrt(std::complex) | complex square root in the range of the right half-plane (function template) [edit]
##### Trigonometric functions
sin(std::complex) | computes sine of a complex number (sin(z)) (function template) [edit]
cos(std::complex) | computes cosine of a complex number (cos(z)) (function template) [edit]
tan(std::complex) | computes tangent of a complex number (tan(z)) (function template) [edit]
asin(std::complex) (C++11) | computes arc sine of a complex number (arcsin(z)) (function template) [edit]
acos(std::complex) (C++11) | computes arc cosine of a complex number (arccos(z)) (function template) [edit]
atan(std::complex) (C++11) | computes arc tangent of a complex number (arctan(z)) (function template) [edit]
##### Hyperbolic functions
sinh(std::complex) | computes hyperbolic sine of a complex number (sh(z)) (function template) [edit]
cosh(std::complex) | computes hyperbolic cosine of a complex number (ch(z)) (function template) [edit]
tanh(std::complex) | computes hyperbolic tangent of a complex number (function template) [edit]
asinh(std::complex) (C++11) | computes area hyperbolic sine of a complex number (function template) [edit]
acosh(std::complex) (C++11) | computes area hyperbolic cosine of a complex number (function template) [edit]
atanh(std::complex) (C++11) | computes area hyperbolic tangent of a complex number (function template) [edit]

### [edit] Synopsis

    namespace std {

        template<class T> class complex;

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

        // operators:
        template<class T>
        complex<T> operator+(const complex<T>&, const complex<T>&);
        template<class T> complex<T> operator+(const complex<T>&, const T&);
        template<class T> complex<T> operator+(const T&, const complex<T>&);

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

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

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

        template<class T> complex<T> operator+(const complex<T>&);
        template<class T> complex<T> operator-(const complex<T>&);

        template<class T> bool operator==(
            const complex<T>&, const complex<T>&);
        template<class T> bool operator==(const complex<T>&, const T&);
        template<class T> bool operator==(const T&, const complex<T>&);

        template<class T> bool operator!=(const complex<T>&, const complex<T>&);
        template<class T> bool operator!=(const complex<T>&, const T&);
        template<class T> 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>&);

        // values:
        template<class T> T real(const complex<T>&);
        template<class T> T imag(const complex<T>&);

        template<class T> T abs(const complex<T>&);
        template<class T> T arg(const complex<T>&);
        template<class T> T norm(const complex<T>&);

        template<class T> 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);

        // transcendentals:
        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>&);

    }

#### [edit] Class std::complex

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

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

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

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

    };

#### [edit] std::complex specializations

    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();
        void real(float);
        constexpr float imag();
        void imag(float);

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

        complex<float>& operator=(const complex<float>&);
        template<class X> complex<float>& operator= (const complex<X>&);
        template<class X> complex<float>& operator+=(const complex<X>&);
        template<class X> complex<float>& operator-=(const complex<X>&);
        template<class X> complex<float>& operator*=(const complex<X>&);
        template<class X> 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();
        void real(double);
        constexpr double imag();
        void imag(double);

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

        complex<double>& operator=(const complex<double>&);
        template<class X> complex<double>& operator= (const complex<X>&);
        template<class X> complex<double>& operator+=(const complex<X>&);
        template<class X> complex<double>& operator-=(const complex<X>&);
        template<class X> complex<double>& operator*=(const complex<X>&);
        template<class X> 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();
        void real(long double);
        constexpr long double imag();
        void imag(long double);

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

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

    };

Retrieved from "http://en.cppreference.com/mwiki/index.php?title=cpp/header/complex&oldid=57454"