<complex>


abs · arg · complex · conj · cos · cosh · double_complex · exp · float_complex · imag · log · log10 · norm · operator!= · operator* · operator+ · operator- · operator/ · operator<< · operator== · operator>> · polar · pow · real · sin · sinh · sqrt · tan · tanh · __STD_COMPLEX


namespace std {
#define __STD_COMPLEX
//    CLASSES
class double_complex;
class float_complex;
//    double_complex FUNCTIONS
double_complex operator+(const double_complex& lhs,
    const double_complex& rhs);
double_complex operator+(const double_complex& lhs,
    const double& rhs);
double_complex operator+(const double& lhs,
    const double_complex& rhs);
double_complex operator-(const double_complex& lhs,
    const double_complex& rhs);
double_complex operator-(const double_complex& lhs,
    const double& rhs);
double_complex operator-(const double& lhs,
    const double_complex& rhs);
double_complex operator*(const double_complex& lhs,
    const double_complex& rhs);
double_complex operator*(const double_complex& lhs,
    const double& rhs);
double_complex operator*(const double& lhs,
    const double_complex& rhs);
double_complex operator/(const double_complex& lhs,
    const double_complex& rhs);
double_complex operator/(const double_complex& lhs,
    const double& rhs);
double_complex operator/(const double& lhs,
    const double_complex& rhs);
double_complex operator+(const double_complex& lhs);
double_complex operator-(const double_complex& lhs);
bool operator==(const double_complex& lhs,
    const double_complex& rhs);
bool operator==(const double_complex& lhs,
    const double& rhs);
bool operator==(const double& lhs,
    const double_complex& rhs);
bool operator!=(const double_complex& lhs,
    const double_complex& rhs);
bool operator!=(const double_complex& lhs,
    const double& rhs);
bool operator!=(const double& lhs,
    const double_complex& rhs);
istream& operator>>(istream& is, double_complex& x);
ostream& operator<<(ostream& os, const double_complex& x);
double real(const double_complex& x);
double imag(const double_complex& x);
double abs(const double_complex& x);
double arg(const double_complex& x);
double norm(const double_complex& x);
double_complex conj(const double_complex& x);
double_complex polar(const double& rho,
    const double& theta = 0);
double_complex cos(const double_complex& x);
double_complex cosh(const double_complex& x);
double_complex exp(const double_complex& x);
double_complex log(const double_complex& x);
double_complex log10(const double_complex& x);
double_complex pow(const double_complex& x, int y);
double_complex pow(const double_complex& x,
    const double& y);
double_complex pow(const double_complex& x,
    const double_complex& y);
double_complex pow(const double& x,
    const double_complex& y);
double_complex sin(const double_complex& x);
double_complex sinh(const double_complex& x);
double_complex sqrt(const double_complex& x);
//    float_complex FUNCTIONS
bool operator==(const float& lhs,
    const float_complex& rhs);
bool operator!=(const float_complex& lhs,
    const float_complex& rhs);
bool operator!=(const float_complex& lhs,
    const float& rhs);
bool operator!=(const float& lhs,
    const float_complex& rhs);
istream& operator>>(istream& is, float_complex& x);
ostream& operator<<(ostream& os, const float_complex& x);
float real(const float_complex& x);
float imag(const float_complex& x);
float abs(const float_complex& x);
float arg(const float_complex& x);
float norm(const float_complex& x);
float_complex conj(const float_complex& x);
float_complex polar(const float& rho,
    const float& theta = 0);
float_complex cos(const float_complex& x);
float_complex cosh(const float_complex& x);
float_complex exp(const float_complex& x);
float_complex log(const float_complex& x);
float_complex log10(const float_complex& x);
float_complex pow(const float_complex& x, int y);
float_complex pow(const float_complex& x,
    const float& y);
float_complex pow(const float_complex& x,
    const float_complex& y);
float_complex pow(const float& x,
    const float_complex& y);
float_complex sin(const float_complex& x);
float_complex sinh(const float_complex& x);
float_complex sqrt(const float_complex& x);
    };

Include the standard header <complex> to define classes double_complex and float_complex and a host of supporting functions. Unless otherwise specified, functions that can return multiple values return an imaginary part in the half-open interval (-pi, pi].

abs

double abs(const double_complex& x);
float abs(const float_complex& x);

The function returns the magnitude of x.

arg

double arg(const double_complex& x);
float arg(const float_complex& x);

The function returns the phase angle of x.

complex

template<class T>
    class complex {
public:
    typedef T value_type;
    T real() const;
    T imag() const;
    complex(const T& re = 0, const T& im = 0);
    complex(const complex& x);
    complex& operator=(const complex& rhs);
    complex& operator+=(const complex& rhs);
    complex& operator-=(const complex& rhs);
    complex& operator*=(const complex& rhs);
    complex& operator/=(const complex& rhs);
    complex& operator=(const T& rhs);
    complex& operator=(const T& rhs);
    complex& operator+=(const T& rhs);
    complex& operator-=(const T& rhs);
    complex& operator*=(const T& rhs);
    complex& operator/=(const T& rhs);
    friend complex
        operator+(const complex& lhs, const T& rhs);
    friend complex
        operator+(const T& lhs, const complex& rhs);
    friend complex
        operator-(const complex& lhs, const T& rhs);
    friend complex
        operator-(const T& lhs, const complex& rhs);
    friend complex
        operator*(const complex& lhs, const T& rhs);
    friend complex
        operator*(const T& lhs, const complex& rhs);
    friend complex
        operator/(const complex& lhs, const T& rhs);
    friend complex
        operator/(const T& lhs, const complex& rhs);
    friend bool
        operator==(const complex& lhs, const T& rhs);
    friend bool
        operator==(const T& lhs, const complex& rhs);
    friend bool
        operator!=(const complex& lhs, const T& rhs);
    friend bool
        operator!=(const T& lhs, const complex& rhs);
    };

The template class doesn't really exist. It is a convenient fiction for describing the behavior common to the two types:

The template class describes an object that stores two objects of type T, one that represents the real part of a complex number and one that represents the imaginary part.

complex::complex

complex(const T& re = 0, const T& im = 0);
complex(const complex& x);

The first constructor initializes the stored real part to re and the stored imaginary part to im. The second constructor initializes the stored real part to x.real() and the stored imaginary part to x.imag().

In this implementation, if a translator does not support member template functions, the template:

template<class U>
    complex(const complex<U>& x);

is replaced by:

complex(const complex& x);

which is the copy constructor.

complex::imag

T imag() const;

The member function returns the stored imaginary part.

complex::operator*=

complex& operator*=(const complex& rhs);
complex& operator*=(const T& rhs);

The first member function replaces the stored real and imaginary parts with those corresponding to the complex product of *this and rhs. It then returns *this.

The second member function multiplies both the stored real part and the stored imaginary part with rhs. It then returns *this.

In this implementation, if a translator does not support member template functions, the template:

template<class U>
    complex& operator*=(const complex<U>& rhs);

is replaced by:

complex& operator*=(const complex& rhs);

complex::operator+=

complex& operator+=(const complex& rhs);
complex& operator+=(const T& rhs);

The first member function replaces the stored real and imaginary parts with those corresponding to the complex sum of *this and rhs. It then returns *this.

The second member function adds rhs to the stored real part. It then returns *this.

In this implementation, if a translator does not support member template functions, the template:

template<class U>
    complex& operator+=(const complex<U>& rhs);

is replaced by:

complex& operator+=(const complex& rhs);

complex::operator-=

complex& operator-=(const complex& rhs);
complex& operator-=(const T& rhs);

The first member function replaces the stored real and imaginary parts with those corresponding to the complex difference of *this and rhs. It then returns *this.

The second member function subtracts rhs from the stored real part. It then returns *this.

In this implementation, if a translator does not support member template functions, the template:

template<class U>
    complex& operator-=(const complex<U>& rhs);

is replaced by:

complex& operator-=(const complex& rhs);

complex::operator/=

complex& operator/=(const complex& rhs);
complex& operator/=(const T& rhs);

The first member function replaces the stored real and imaginary parts with those corresponding to the complex quotient of *this and rhs. It then returns *this.

The second member function multiplies both the stored real part and the stored imaginary part with rhs. It then returns *this.

In this implementation, if a translator does not support member template functions, the template:

template<class U>
    complex& operator/=(const complex<U>& rhs);

is replaced by:

complex& operator/=(const complex& rhs);

complex::operator=

complex& operator=(const complex& rhs);
complex& operator=(const T& rhs);

The first member function replaces the stored real part with rhs.real() and the stored imaginary part with rhs.imag(). It then returns *this.

The second member function replaces the stored real part with rhs and the stored imaginary part with zero. It then returns *this.

In this implementation, if a translator does not support member template functions, the template:

template<class U>
    complex& operator=(const complex<U>& rhs);

is replaced by:

complex& operator=(const complex& rhs);

which is the default assignment operator.

complex::real

T real() const;

The member function returns the stored real part.

complex::value_type

typedef T value_type;

The type is a synonym for the template parameter T.

conj

double_complex conj(const double_complex& x);
float_complex conj(const float_complex& x);

The function returns the conjugate of x.

cos

double_complex cos(const double_complex& x);
float_complex cos(const float_complex& x);

The function returns the cosine of x.

cosh

double_complex cosh(const double_complex& x);
float_complex cosh(const float_complex& x);

The function returns the hyperbolic cosine of x.

double_complex

class double_complex : public complex<double> {
public:
    double_complex(double re = 0, double im = 0);
    double_complex(const float_complex& x);
    double_complex& operator=(const double x);
    };

The class describes an object that stores two objects of type double, one that represents the real part of a complex number and one that represents the imaginary part. The class differs from its fictitious base class complex<double> only in the constructors it defines. The first constructor initializes the stored real part to re and the stored imaginary part to im. The second constructor initializes the stored real part to x.real() and the stored imaginary part to x.imag(). The assignment operator stores x in the stored real part and zero in the stored imaginary part.

exp

double_complex exp(const double_complex& x);
float_complex exp(const float_complex& x);

The function returns the exponential of x.

float_complex

class float_complex : public complex<float> {
public:
    float_complex(float re = 0, float im = 0);
    explicit float_complex(const double_complex& x);
    float_complex& operator=(const float x);
    };

The class describes an object that stores two objects of type float, one that represents the real part of a complex number and one that represents the imaginary part. The class differs from its fictitious base class complex<float> only in the constructors it defines. The first constructor initializes the stored real part to re and the stored imaginary part to im. The second constructor initializes the stored real part to x.real() and the stored imaginary part to x.imag(). The assignment operator stores x in the stored real part and zero in the stored imaginary part.

imag

double imag(const double_complex& x);
float imag(const float_complex& x);

The function returns the imaginary part of x.

log

double_complex log(const double_complex& x);
float_complex log(const float_complex& x);

The function returns the logarithm of x. The branch cuts are along the negative real axis.

log10

double_complex log10(const double_complex& x);
float_complex log10(const float_complex& x);

The function returns the base 10 logarithm of x. The branch cuts are along the negative real axis.

norm

double norm(const double_complex& x);
float norm(const float_complex& x);

The function returns the squared magnitude of x.

operator!=

bool operator!=(const double_complex& lhs,
    const double_complex& rhs);
bool operator!=(const double_complex& lhs,
    const double& rhs);
bool operator!=(const double& lhs,
    const double_complex& rhs);
bool operator!=(const float_complex& lhs,
    const float_complex& rhs);
bool operator!=(const float_complex& lhs,
    const float& rhs);
bool operator!=(const float& lhs,
    const float_complex& rhs);

The operators each return true only if real(lhs) != real(rhs) || imag(lhs) != imag(rhs).

operator*

double_complex operator*(const double_complex& lhs,
    const double_complex;& rhs);
double_complex operator*(const double_complex& lhs,
    const double& rhs);
double_complex operator*(const double& lhs,
    const double_complex& rhs);
float_complex operator*(const float_complex& lhs,
    const float_complex;& rhs);
float_complex operator*(const float_complex& lhs,
    const float& rhs);
float_complex operator*(const float& lhs,
    const float_complex& rhs);

The operators each convert both operands to the return type, then return the complex product of the converted lhs and rhs.

operator+

double_complex operator+(const double_complex& lhs,
    const double_complex;& rhs);
double_complex operator+(const double_complex& lhs,
    const double& rhs);
double_complex operator+(const double& lhs,
    const double_complex& rhs);
double_complex operator+(const double_complex& lhs);
float_complex operator+(const float_complex& lhs,
    const float_complex;& rhs);
float_complex operator+(const float_complex& lhs,
    const float& rhs);
float_complex operator+(const float& lhs,
    const float_complex& rhs);
float_complex operator+(const float_complex& lhs);

The binary operators each convert both operands to the return type, then return the complex sum of the converted lhs and rhs.

The unary operator returns lhs.

operator-

double_complex operator-(const double_complex& lhs,
    const double_complex;& rhs);
double_complex operator-(const double_complex& lhs,
    const double& rhs);
double_complex operator-(const double& lhs,
    const double_complex& rhs);
double_complex operator-(const double_complex& lhs);
float_complex operator-(const float_complex& lhs,
    const float_complex;& rhs);
float_complex operator-(const float_complex& lhs,
    const float& rhs);
float_complex operator-(const float& lhs,
    const float_complex& rhs);
float_complex operator-(const float_complex& lhs);

The binary operators each convert both operands to the return type, then return the complex difference of the converted lhs and rhs.

The unary operator returns a value whose real part is -real(lhs) and whose imaginary part is -imag(lhs).

operator/

double_complex operator/(const double_complex& lhs,
    const double_complex;& rhs);
double_complex operator/(const double_complex& lhs,
    const double& rhs);
double_complex operator/(const double& lhs,
    const double_complex& rhs);
float_complex operator/(const float_complex& lhs,
    const float_complex;& rhs);
float_complex operator/(const float_complex& lhs,
    const float& rhs);
float_complex operator/(const float& lhs,
    const float_complex& rhs);

The operators each convert both operands to the return type, then return the complex quotient of the converted lhs and rhs.

operator<<

ostream& operator<<(ostream& os,
    const double_complex& x);
ostream& operator<<(ostream& os,
    const float_complex& x);

The template function inserts the complex value x in the output stream os, effectively by executing:

ostringstream ostr;
ostr.flags(os.flags());
ostr.precision(os.precision());
ostr << '(' << real(x) << ','
    << imag(x) << ')';
os << ostr.str().c_str();

Thus, if os.width() is greater than zero, any padding occurs either before or after the parenthesized pair of values, which itself contains no padding. The function returns os.

operator==

bool operator==(const double_complex& lhs,
    const double_complex& rhs);
bool operator==(const double_complex& lhs,
    const double& rhs);
bool operator==(const double& lhs,
    const double_complex& rhs);
bool operator==(const float_complex& lhs,
    const float_complex& rhs);
bool operator==(const float_complex& lhs,
    const float& rhs);
bool operator==(const float& lhs,
    const float_complex& rhs);

The operators each return true only if real(lhs) == real(rhs) && imag(lhs) == imag(rhs).

operator>>

istream& operator>>(istream& is,
    double_complex& x);
istream& operator>>(istream& is,
    float_complex& x);

The template function attempts to extract a complex value from the input stream is, effectively by executing:

is >> ch && ch == '('
    is >> re >> ch && ch == ','
    is >> im >> ch && ch == ')'

Here, ch is an object of type char, and re and im are objects of the same type as x.real().

If the result of this expression is true, the function stores re in the real part and im in the imaginary part of x. In any event, the function returns is.

polar

double_complex polar(const double& rho,
    const double& theta = 0);
float_complex polar(const float& rho,
    const float& theta);

The function returns the complex value whose magnitude is rho and whose phase angle is theta.

pow

double_complex pow(const double_complex& x, int y);
double_complex pow(const double_complex& x, const T& y);
double_complex pow(const double_complex& x,
    const double_complex& y);
double_complex pow(const T& x, const double_complex& y);
float_complex pow(const float_complex& x, int y);
float_complex pow(const float_complex& x, const T& y);
float_complex pow(const float_complex& x,
    const float_complex& y);
float_complex pow(const T& x, const float_complex& y);

The functions each effectively convert both operands to the return type, then return the converted x to the power y. The branch cut for x is along the negative real axis.

real

double real(const double_complex& x);
float real(const float_complex& x);

The function returns the real part of x.

sin

double_complex sin(const double_complex& x);
float_complex sin(const float_complex& x);

The function returns the sine of x.

sinh

double_complex sinh(const double_complex& x);
float_complex sinh(const float_complex& x);

The function returns the hyperbolic sine of x.

sqrt

double_complex sqrt(const double_complex& x);
float_complex sqrt(const float_complex& x);

The function returns the square root of x, with phase angle in the half-open interval (-pi/2, pi/2]. The branch cuts are along the negative real axis.

tan

double_complex tan(const double_complex& x);
float_complex tan(const float_complex& x);

The function returns the tangent of x.

tanh

double_complex tanh(const double_complex& x);
float_complex tanh(const float_complex& x);

The function returns the hyperbolic tangent of x.

__STD_COMPLEX

#define __STD_COMPLEX

The macro is defined, with an unspecified expansion, to indicate compliance with the specifications of this header.


See also the Table of Contents and the Index.

Copyright © 1992-1996 by P.J. Plauger. All rights reserved.