Warning: main(/www/www/htdocs/style/globals.php) [function.main]: failed to open stream: No such file or directory in /www/www/docs/6.4.1/dinkum_en/ecpp/complex.html on line 1

Warning: main() [function.include]: Failed opening '/www/www/htdocs/style/globals.php' for inclusion (include_path='.:/www/www/common:/www/www/php/lib/php') in /www/www/docs/6.4.1/dinkum_en/ecpp/complex.html on line 1

Warning: main(/www/www/htdocs/style/header.php) [function.main]: failed to open stream: No such file or directory in /www/www/docs/6.4.1/dinkum_en/ecpp/complex.html on line 4

Warning: main() [function.include]: Failed opening '/www/www/htdocs/style/header.php' for inclusion (include_path='.:/www/www/common:/www/www/php/lib/php') in /www/www/docs/6.4.1/dinkum_en/ecpp/complex.html on line 4
[Previous] [Contents] [Next]

<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


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].

        // DECLARATIONS
#define __STD_COMPLEX

        // CLASSES
class double_complex;
class float_complex;

        // double_complex FUNCTIONS
double_complex operator+(const double_complex& left,
    const double_complex& right);
double_complex operator+(const double_complex& left,
    const double& right);
double_complex operator+(const double& left,
    const double_complex& right);
double_complex operator-(const double_complex& left,
    const double_complex& right);
double_complex operator-(const double_complex& left,
    const double& right);
double_complex operator-(const double& left,
    const double_complex& right);
double_complex operator*(const double_complex& left,
    const double_complex& right);
double_complex operator*(const double_complex& left,
    const double& right);
double_complex operator*(const double& left,
    const double_complex& right);
double_complex operator/(const double_complex& left,
    const double_complex& right);
double_complex operator/(const double_complex& left,
    const double& right);
double_complex operator/(const double& left,
    const double_complex& right);
double_complex operator+(const double_complex& left);
double_complex operator-(const double_complex& left);
bool operator==(const double_complex& left,
    const double_complex& right);
bool operator==(const double_complex& left,
    const double& right);
bool operator==(const double& left,
    const double_complex& right);
bool operator!=(const double_complex& left,
    const double_complex& right);
bool operator!=(const double_complex& left,
    const double& right);
bool operator!=(const double& left,
    const double_complex& right);
istream& operator>>(istream& istr, double_complex& right);
ostream& operator<<(ostream& ostr, const double_complex& right);
double real(const double_complex& left);
double imag(const double_complex& left);
double abs(const double_complex& left);
double arg(const double_complex& left);
double norm(const double_complex& left);
double_complex conj(const double_complex& left);
double_complex polar(const double& rho,
    const double& theta = 0);
double_complex cos(const double_complex& left);
double_complex cosh(const double_complex& left);
double_complex exp(const double_complex& left);
double_complex log(const double_complex& left);
double_complex log10(const double_complex& left);
double_complex pow(const double_complex& left, int right);
double_complex pow(const double_complex& left,
    const double& right);
double_complex pow(const double_complex& left,
    const double_complex& right);
double_complex pow(const double& left,
    const double_complex& right);
double_complex sin(const double_complex& left);
double_complex sinh(const double_complex& left);
double_complex sqrt(const double_complex& left);

        // float_complex FUNCTIONS
bool operator==(const float& left,
    const float_complex& right);
bool operator!=(const float_complex& left,
    const float_complex& right);
bool operator!=(const float_complex& left,
    const float& right);
bool operator!=(const float& left,
    const float_complex& right);
istream& operator>>(istream& istr, float_complex& right);
ostream& operator<<(ostream& ostr, const float_complex& right);
float real(const float_complex& left);
float imag(const float_complex& left);
float abs(const float_complex& left);
float arg(const float_complex& left);
float norm(const float_complex& left);
float_complex conj(const float_complex& left);
float_complex polar(const float& rho,
    const float& theta = 0);
float_complex cos(const float_complex& left);
float_complex cosh(const float_complex& left);
float_complex exp(const float_complex& left);
float_complex log(const float_complex& left);
float_complex log10(const float_complex& left);
float_complex pow(const float_complex& left, int right);
float_complex pow(const float_complex& left,
    const float& right);
float_complex pow(const float_complex& left,
    const float_complex& right);
float_complex pow(const float& left,
    const float_complex& right);
float_complex sin(const float_complex& left);
float_complex sinh(const float_complex& left);
float_complex sqrt(const float_complex& left);
        // END OF DECLARATIONS

abs

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

The function returns the magnitude of left.

arg

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

The function returns the phase angle of left.

complex

template<class Ty>
    class complex {
public:
    typedef Ty value_type;
    Ty real() const;
    Ty imag() const;
    complex(const Ty& realval = 0, const Ty& imagval = 0);
    complex(const complex& right);
    complex& operator=(const complex& right);
    complex& operator+=(const complex& right);
    complex& operator-=(const complex& right);
    complex& operator*=(const complex& right);
    complex& operator/=(const complex& right);
    complex& operator=(const Ty& right);
    complex& operator=(const Ty& right);
    complex& operator+=(const Ty& right);
    complex& operator-=(const Ty& right);
    complex& operator*=(const Ty& right);
    complex& operator/=(const Ty& right);
    };

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 Ty, one that represents the real part of a complex number and one that represents the imaginary part.

complex::complex

complex(const Ty& realval = 0, const Ty& imagval = 0);
complex(const complex& right);

The first constructor initializes the stored real part to realval and the stored imaginary part to imagval. The second constructor initializes the stored real part to right.real() and the stored imaginary part to right.imag().

complex::imag

Ty imag() const;

The member function returns the stored imaginary part.

complex::operator*=

complex& operator*=(const complex& right);
complex& operator*=(const Ty& right);

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

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

complex::operator+=

complex& operator+=(const complex& right);
complex& operator+=(const Ty& right);

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

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

complex::operator-=

complex& operator-=(const complex& right);
complex& operator-=(const Ty& right);

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

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

complex::operator/=

complex& operator/=(const complex& right);
complex& operator/=(const Ty& right);

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

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

complex::operator=

complex& operator=(const complex& right);
complex& operator=(const Ty& right);

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

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

complex::real

Ty real() const;

The member function returns the stored real part.

complex::value_type

typedef Ty value_type;

The type is a synonym for the template parameter Ty.

conj

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

The function returns the conjugate of left.

cos

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

The function returns the cosine of left.

cosh

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

The function returns the hyperbolic cosine of left.

double_complex

class double_complex : public complex<double> {
public:
    double_complex(double realval = 0, double imagval = 0);
    double_complex(const float_complex& right);
    double_complex& operator=(const double right);
    };

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 realval and the stored imaginary part to imagval. The second constructor initializes the stored real part to right.real() and the stored imaginary part to right.imag(). The assignment operator stores right in the stored real part and zero in the stored imaginary part.

exp

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

The function returns the exponential of left.

float_complex

class float_complex : public complex<float> {
public:
    float_complex(float realval = 0, float imagval = 0);
    explicit float_complex(const double_complex& right);
    float_complex& operator=(const float right);
    };

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 realval and the stored imaginary part to imagval. The second constructor initializes the stored real part to right.real() and the stored imaginary part to right.imag(). The assignment operator stores right in the stored real part and zero in the stored imaginary part.

imag

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

The function returns the imaginary part of left.

log

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

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

log10

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

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

norm

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

The function returns the squared magnitude of left.

operator!=

bool operator!=(const double_complex& left,
    const double_complex& right);
bool operator!=(const double_complex& left,
    const double& right);
bool operator!=(const double& left,
    const double_complex& right);
bool operator!=(const float_complex& left,
    const float_complex& right);
bool operator!=(const float_complex& left,
    const float& right);
bool operator!=(const float& left,
    const float_complex& right);

The operators each return true only if real(left) != real(right) || imag(left) != imag(right).

operator*

double_complex operator*(const double_complex& left,
    const double_complex;& right);
double_complex operator*(const double_complex& left,
    const double& right);
double_complex operator*(const double& left,
    const double_complex& right);
float_complex operator*(const float_complex& left,
    const float_complex;& right);
float_complex operator*(const float_complex& left,
    const float& right);
float_complex operator*(const float& left,
    const float_complex& right);

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

operator+

double_complex operator+(const double_complex& left,
    const double_complex;& right);
double_complex operator+(const double_complex& left,
    const double& right);
double_complex operator+(const double& left,
    const double_complex& right);
double_complex operator+(const double_complex& left);
float_complex operator+(const float_complex& left,
    const float_complex;& right);
float_complex operator+(const float_complex& left,
    const float& right);
float_complex operator+(const float& left,
    const float_complex& right);
float_complex operator+(const float_complex& left);

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

The unary operator returns left.

operator-

double_complex operator-(const double_complex& left,
    const double_complex;& right);
double_complex operator-(const double_complex& left,
    const double& right);
double_complex operator-(const double& left,
    const double_complex& right);
double_complex operator-(const double_complex& left);
float_complex operator-(const float_complex& left,
    const float_complex;& right);
float_complex operator-(const float_complex& left,
    const float& right);
float_complex operator-(const float& left,
    const float_complex& right);
float_complex operator-(const float_complex& left);

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

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

operator/

double_complex operator/(const double_complex& left,
    const double_complex;& right);
double_complex operator/(const double_complex& left,
    const double& right);
double_complex operator/(const double& left,
    const double_complex& right);
float_complex operator/(const float_complex& left,
    const float_complex;& right);
float_complex operator/(const float_complex& left,
    const float& right);
float_complex operator/(const float& left,
    const float_complex& right);

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

operator<<

ostream& operator<<(ostream& ostr,
    const double_complex& right);
ostream& operator<<(ostream& ostr,
    const float_complex& right);

The template function inserts the complex value right in the output stream ostr, effectively by executing:

ostringstream osstr;
osstr.flags(ostr.flags());
osstr.precision(ostr.precision());
osstr << '(' << real(right) << ','
    << imag(right) << ')';
ostr << osstr.str().c_str();

Thus, if ostr.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 ostr.

operator==

bool operator==(const double_complex& left,
    const double_complex& right);
bool operator==(const double_complex& left,
    const double& right);
bool operator==(const double& left,
    const double_complex& right);
bool operator==(const float_complex& left,
    const float_complex& right);
bool operator==(const float_complex& left,
    const float& right);
bool operator==(const float& left,
    const float_complex& right);

The operators each return true only if real(left) == real(right) && imag(left) == imag(right).

operator>>

istream& operator>>(istream& istr,
    double_complex& right);
istream& operator>>(istream& istr,
    float_complex& right);

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

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

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

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

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& left, int right);
double_complex pow(const double_complex& left, const Ty& right);
double_complex pow(const double_complex& left,
    const double_complex& right);
double_complex pow(const Ty& left, const double_complex& right);
float_complex pow(const float_complex& left, int right);
float_complex pow(const float_complex& left, const Ty& right);
float_complex pow(const float_complex& left,
    const float_complex& right);
float_complex pow(const Ty& left, const float_complex& right);

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

real

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

The function returns the real part of left.

sin

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

The function returns the sine of left.

sinh

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

The function returns the hyperbolic sine of left.

sqrt

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

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

__STD_COMPLEX

#define __STD_COMPLEX

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

tan

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

The function returns the tangent of left.

tanh

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

The function returns the hyperbolic tangent of left.


See also the Table of Contents and the Index.

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

[Previous] [Contents] [Next]

Warning: main(/www/www/htdocs/style/footer.php) [function.main]: failed to open stream: No such file or directory in /www/www/docs/6.4.1/dinkum_en/ecpp/complex.html on line 690

Warning: main() [function.include]: Failed opening '/www/www/htdocs/style/footer.php' for inclusion (include_path='.:/www/www/common:/www/www/php/lib/php') in /www/www/docs/6.4.1/dinkum_en/ecpp/complex.html on line 690