<complex>abs
· acos
· acosh
· arg
· asin
· asinh
· atan
· atanh
· complex
· complex<double>
· complex<float>
· complex<long double>
· conj
· cos
· cosh
· exp
· imag
· log
· log10
· norm
· operator!=
· operator*
· operator+
· operator-
· operator/
· operator<<
· operator==
· operator>>
· polar
· pow
· proj
· real
· sin
· sinh
· sqrt
· tan
· tanh
· __STD_COMPLEX
Include the standard header <complex>
to define template class complex and a host of
supporting template functions.
Unless otherwise specified,
functions that can return multiple values return an imaginary
part in the half-open interval (-pi, pi].
Beginning with C++11,
some functions and constructors declared in this header
use constexpr to signal that they are treated as
compile-time constants.
Many of the functions declared in this header have
additional overloads,
which behave much like the generic functions defined in the C99 header
<tgmath.h>.
The following functions have such additional overloads:
abs conj polar tanh acos cos pow acosh cosh proj arg exp real asin imag sin asinh log sinh atan log10 sqrt atanh norm tan
[These additional overloads are added with TR1]
namespace std {
#define __STD_COMPLEX
// TEMPLATE CLASSES
template<class Ty>
class complex;
template<>
class complex<float>;
template<>
class complex<double>;
template<>
class complex<long double>;
// TEMPLATE FUNCTIONS
template<class Ty>
complex<Ty> operator+(const complex<Ty>& left,
const complex<Ty>& right);
template<class Ty>
complex<Ty> operator+(const complex<Ty>& left,
const Ty& right);
template<class Ty>
complex<Ty> operator+(const Ty& left,
const complex<Ty>& right);
template<class Ty>
complex<Ty> operator-(const complex<Ty>& left,
const complex<Ty>& right);
template<class Ty>
complex<Ty> operator-(const complex<Ty>& left,
const Ty& right);
template<class Ty>
complex<Ty> operator-(const Ty& left,
const complex<Ty>& right);
template<class Ty>
complex<Ty> operator*(const complex<Ty>& left,
const complex<Ty>& right);
template<class Ty>
complex<Ty> operator*(const complex<Ty>& left,
const Ty& right);
template<class Ty>
complex<Ty> operator*(const Ty& left,
const complex<Ty>& right);
template<class Ty>
complex<Ty> operator/(const complex<Ty>& left,
const complex<Ty>& right);
template<class Ty>
complex<Ty> operator/(const complex<Ty>& left,
const Ty& right);
template<class Ty>
complex<Ty> operator/(const Ty& left,
const complex<Ty>& right);
template<class Ty>
complex<Ty> operator+(const complex<Ty>& left);
template<class Ty>
complex<Ty> operator-(const complex<Ty>& left);
template<class Ty>
constexpr bool operator==(const complex<Ty>& left,
const complex<Ty>& right);
template<class Ty>
constexpr bool operator==(const complex<Ty>& left,
const Ty& right);
template<class Ty>
constexpr bool operator==(const Ty& left,
const complex<Ty>& right);
template<class Ty>
constexpr bool operator!=(const complex<Ty>& left,
const complex<Ty>& right);
template<class Ty>
constexpr bool operator!=(const complex<Ty>& left,
const Ty& right);
template<class Ty>
constexpr bool operator!=(const Ty& left,
const complex<Ty>& right);
template<class Ty, class Elem, class Tr>
basic_istream<Elem, Tr>&
operator>>(basic_istream<Elem, Tr>& istr,
complex<Ty>& right);
template<class Ty, class Elem, class Tr>
basic_ostream<Elem, Tr>&
operator<<(basic_ostream<Elem, Tr>& ostr,
const complex<Ty>& right);
template<class Ty>
constexpr Ty real(const complex<Ty>& left);
template<class Ty>
constexpr Ty imag(const complex<Ty>& left);
template<class Ty>
Ty abs(const complex<Ty>& left);
template<class Ty>
Ty arg(const complex<Ty>& left);
template<class Ty>
Ty norm(const complex<Ty>& left);
template<class Ty>
complex<Ty> conj(const complex<Ty>& left);
double conj(const double&left); [added with C++11]
float conj(const float&left); [added with C++11]
long double conj(const long double&left); [added with C++11]
template<class Ty>
complex<Ty> proj(const complex<Ty>& left);
double proj(const double&left); [added with C++11]
float proj(const float&left); [added with C++11]
long double proj(const long double&left); [added with C++11]
template<class Ty>
complex<Ty> acos(const complex<Ty>& left); [added with C++11]
template<class Ty>
complex<Ty> acosh(const complex<Ty>& left); [added with C++11]
template<class Ty>
complex<Ty> asin(const complex<Ty>& left); [added with C++11]
template<class Ty>
complex<Ty> asinh(const complex<Ty>& left); [added with C++11]
template<class Ty>
complex<Ty> atan(const complex<Ty>& left); [added with C++11]
template<class Ty>
complex<Ty> atanh(const complex<Ty>& left); [added with C++11]
template<class Ty>
complex<Ty> polar(const Ty& rho, const Ty& theta = 0);
template<class Ty>
complex<Ty> cos(const complex<Ty>& left);
template<class Ty>
complex<Ty> cosh(const complex<Ty>& left);
template<class Ty>
complex<Ty> exp(const complex<Ty>& left);
template<class Ty>
complex<Ty> log(const complex<Ty>& left);
template<class Ty>
complex<Ty> log10(const complex<Ty>& left);
template<class Ty>
complex<Ty> pow(const complex<Ty>& left, const Ty& right);
template<class Ty>
complex<Ty> pow(const complex<Ty>& left,
const complex<Ty>& right);
template<class Ty>
complex<Ty> pow(const Ty& left, const complex<Ty>& right);
template<class Ty>
complex<Ty> sin(const complex<Ty>& left);
template<class Ty>
complex<Ty> sinh(const complex<Ty>& left);
template<class Ty>
complex<Ty> sqrt(const complex<Ty>& left);
} // namespace std
abstemplate<class Ty>
Ty abs(const complex<Ty>& left);
The function returns the magnitude of left.
acostemplate<class Ty>
complex<Ty> acos(const complex<Ty>& left); [added with C++11]
The function returns the arccosine of left.
acoshtemplate<class Ty>
complex<Ty> acosh(const complex<Ty>& left); [added with C++11]
The function returns the hyperbolic arccosine of left.
argtemplate<class Ty>
Ty arg(const complex<Ty>& left);
The function returns the phase angle of left.
asintemplate<class Ty>
complex<Ty> asin(const complex<Ty>& left); [added with C++11]
The function returns the arcsine of left.
asinhtemplate<class Ty>
complex<Ty> asinh(const complex<Ty>& left); [added with C++11]
The function returns the hyperbolic arcsine of left.
atantemplate<class Ty>
complex<Ty> atan(const complex<Ty>& left); [added with C++11]
The function returns the arctangent of left.
atanhtemplate<class Ty>
complex<Ty> atanh(const complex<Ty>& left); [added with C++11]
The function returns the hyperbolic arctangent of left.
complextemplate<class Ty>
class complex {
public:
typedef Ty value_type;
constexpr Ty real() const;
void real(Ty val);
constexpr Ty imag() const;
void imag(Ty val);
constexpr complex(const complex& right);
constexpr complex(const Ty& realval = 0, const Ty& imagval = 0);
template<class Other>
constexpr complex(const complex<Other>& right);
template<class Other>
complex& operator=(const complex<Other>& right);
template<class Other>
complex& operator+=(const complex<Other>& right);
template<class Other>
complex& operator-=(const complex<Other>& right);
template<class Other>
complex& operator*=(const complex<Other>& right);
template<class Other>
complex& operator/=(const complex<Other>& 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 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.
The type Ty must be one of the three floating-point types.
complex::complexcomplex(const complex& right);
complex(const Ty& realval = 0, const Ty& imagval = 0);template<class Other>
complex(const complex<Other>& right);
The first constructor initializes the object by copying right.
The second constructor initializes the stored real part to
realval and the stored imaginary part to imagval.
The third constructor initializes the stored real part to
right.real() and the stored imaginary part to
right.imag().
complex::imagconstexpr Ty imag() const; void imag(Ty val);
The first member function returns the stored imaginary part.
The second member function stores val in the imaginary part.
complex::operator*=template<class Other>
complex& operator*=(const complex<Other>& 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+=template<class Other>
complex& operator+=(const complex<Other>& 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-=template<class Other>
complex& operator-=(const complex<Other>& 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/=template<class Other>
complex& operator/=(const complex<Other>& 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=template<class Other>
complex& operator=(const complex<Other>& 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::realconstexpr Ty real() const; void real(Ty val);
The first member function returns the stored real part.
The second member function stores val in the real part.
complex::value_typetypedef Ty value_type;
The type is a synonym for the template parameter Ty.
complex<double>template<>
class complex<double> {
public:
constexpr complex(double realval = 0, double imagval = 0);
constexpr complex(const complex<float>& right);
constexpr explicit complex(const complex<long double>& right);
constexpr double real() const;
constexpr double imag() const;
// rest same as template class complex
};
The explicitly specialized template 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
explicit specialization differs only in the constructors it defines.
The first constructor initializes the stored real part to
realval and the stored imaginary part to imagval.
The remaining two constructors initialize the stored real part to
right.real() and the stored imaginary part to
right.imag().
complex<float>template<>
class complex<float> {
public:
constexpr complex(float realval = 0, float imagval = 0);
constexpr explicit complex(const complex<double>& right);
constexpr explicit complex(const complex<long double>& right);
constexpr float real() const;
constexpr float imag() const;
// rest same as template class complex
};
The explicitly specialized template 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
explicit specialization differs only in the constructors it defines.
The first constructor initializes the stored real part to
realval and the stored imaginary part to imagval.
The remaining two constructors initialize the stored real part to
right.real() and the stored imaginary part to
right.imag().
complex<long double>template<>
class complex<long double> {
public:
constexpr complex(long double realval = 0, long double imagval = 0);
constexpr complex(const complex<float>& right);
constexpr complex(const complex<double>& right);
constexpr long double real() const;
constexpr long double imag() const;
// rest same as template class complex
};
The explicitly specialized template class
describes an object that stores two objects
of type long double, one that represents the real part
of a complex number and one that represents the imaginary part. The
explicit specialization differs only in the constructors it defines.
The first constructor initializes the stored real part to
realval and the stored imaginary part to imagval.
The remaining two constructors initialize the stored real part to
right.real() and the stored imaginary part to
right.imag().
conjtemplate<class Ty>
complex<Ty> conj(const complex<Ty>& left);
double conj(const double&left); [added with C++11]
float_complex conj(const float_complex& left);
float conj(const float&left); [added with C++11]
long double conj(const long double&left); [added with C++11]
The functions return the conjugate of left.
costemplate<class Ty>
complex<Ty> cos(const complex<Ty>& left);
The function returns the cosine of left.
coshtemplate<class Ty>
complex<Ty> cosh(const complex<Ty>& left);
The function returns the hyperbolic cosine of left.
exptemplate<class Ty>
complex<Ty> exp(const complex<Ty>& left);
The function returns the exponential of left.
imagtemplate<class Ty>
constexpr Ty imag(const complex<Ty>& left);
The function returns the imaginary part of left.
logtemplate<class Ty>
complex<Ty> log(const complex<Ty>& left);
The function returns the logarithm of left.
The branch cuts are along the negative real axis.
log10template<class Ty>
complex<Ty> log10(const complex<Ty>& left);
The function returns the base 10
logarithm of left.
The branch cuts are along the negative real axis.
normtemplate<class Ty>
Ty norm(const complex<Ty>& left);
The function returns the squared magnitude of left.
operator!=template<class Ty>
constexpr bool operator!=(const complex<Ty>& left,
const complex<Ty>& right);
template<class Ty>
constexpr bool operator!=(const complex<Ty>& left,
const Ty& right);
template<class Ty>
constexpr bool operator!=(const Ty& left,
const complex<Ty>& right);
The operators each return true only if
real(left) != real(right) ||
imag(left) != imag(right).
operator*template<class Ty>
complex<Ty> operator*(const complex<Ty>& left,
const complex<Ty>& right);
template<class Ty>
complex<Ty> operator*(const complex<Ty>& left,
const Ty& right);
template<class Ty>
complex<Ty> operator*(const Ty& left,
const complex<Ty>& right);
The operators each convert both operands to the return type,
then return the complex product
of the converted left and right.
operator+template<class Ty>
complex<Ty> operator+(const complex<Ty>& left,
const complex<Ty>& right);
template<class Ty>
complex<Ty> operator+(const complex<Ty>& left,
const Ty& right);
template<class Ty>
complex<Ty> operator+(const Ty& left,
const complex<Ty>& right);
template<class Ty>
complex<Ty> operator+(const complex<Ty>& 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-template<class Ty>
complex<Ty> operator-(const complex<Ty>& left,
const complex<Ty>& right);
template<class Ty>
complex<Ty> operator-(const complex<Ty>& left,
const Ty& right);
template<class Ty>
complex<Ty> operator-(const Ty& left,
const complex<Ty>& right);
template<class Ty>
complex<Ty> operator-(const complex<Ty>& 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/template<class Ty>
complex<Ty> operator/(const complex<Ty>& left,
const complex<Ty>& right);
template<class Ty>
complex<Ty> operator/(const complex<Ty>& left,
const Ty& right);
template<class Ty>
complex<Ty> operator/(const Ty& left,
const complex<Ty>& right);
The operators each convert both operands to the return type,
then return the complex quotient
of the converted left and right.
operator<<template<class Ty, class Elem, class Tr>
basic_ostream<Elem, Tr>&
operator<<(basic_ostream<Elem, Tr>& ostr,
const complex<Ty>& right);
The template function inserts the complex value right
in the output stream os, effectively by executing:
basic_ostringstream<Elem, Tr> osstr;
osstr.flags(ostr.flags());
osstr.imbue(ostr.getloc());
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==template<class Ty>
constexpr bool operator==(const complex<Ty>& left,
const complex<Ty>& right);
template<class Ty>
constexpr bool operator==(const complex<Ty>& left,
const Ty& right);
template<class Ty>
constexpr bool operator==(const Ty& left,
const complex<Ty>& right);
The operators each return true only if
real(left) == real(right) &&
imag(left) == imag(right).
operator>>template<class Ty, class Elem, class Tr>
basic_istream<Elem, Tr>&
operator>>(basic_istream<Elem, Tr>& istr,
complex<Ty>& 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 Elem,
and re and im are objects of type Ty.
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.
polartemplate<class Ty>
complex<Ty> polar(const Ty& rho,
const Ty& theta = 0);
The function returns the complex value whose magnitude
is rho and whose phase angle is theta.
powtemplate<class Ty>
complex<Ty> pow(const complex<Ty>& left,
const Ty& right);
template<class Ty>
complex<Ty> pow(const complex<Ty>& left,
const complex<Ty>& right);
template<class Ty>
complex<Ty> pow(const Ty& left,
const complex<Ty>& 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.
projtemplate<class Ty>
complex<Ty> proj(const complex<Ty>& left);
double proj(const double&left); [added with C++11]
float_complex proj(const float_complex& left);
float proj(const float&left); [added with C++11]
long double proj(const long double&left); [added with C++11]
The functions return a projection of left onto the Riemann
sphere. Specifically, if either component of left is an
infinity of either sign, the functions return a value whose real part is
positive infinity and whose imaginary part is zero with the same sign
as the imaginary part of left. Otherwise, the functions return
left.
realtemplate<class Ty>
constexpr Ty real(const complex<Ty>& left);
The function returns the real part of left.
sintemplate<class Ty>
complex<Ty> sin(const complex<Ty>& left);
The function returns the sine of left.
sinhtemplate<class Ty>
complex<Ty> sinh(const complex<Ty>& left);
The function returns the hyperbolic sine of left.
sqrttemplate<class Ty>
complex<Ty> sqrt(const complex<Ty>& 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.
tantemplate<class Ty>
complex<Ty> tan(const complex<Ty>& left);
The function returns the tangent of left.
tanhtemplate<class Ty>
complex<Ty> tanh(const complex<Ty>& left);
The function returns the hyperbolic tangent of left.
See also the Table of Contents and the Index.
Copyright (c) by P.J. Plauger. All rights reserved.