# <complex>
<complex>
# ``
* * *
**`abs· arg· complex· complex· complex· complex· conj· cos· cosh· exp· 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 **``**
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]`.
Many of the functions declared in this header have
**additional overloads**.
The following functions have such additional overloads:
abs conj polar
acos cos pow
acosh cosh real
arg exp sin
asin imag sinh
asinh log sqrt
atan log10 tan
atanh norm tanhCopy to clipboard
* * *
namespace std {
#define __STD_COMPLEX
// TEMPLATE CLASSES
template
class complex;
template<>
class complex;
template<>
class complex;
template<>
class complex;
// TEMPLATE FUNCTIONS
template
complex operator+(const complex& left,
const complex& right);
template
complex operator+(const complex& left,
const Ty& right);
template
complex operator+(const Ty& left,
const complex& right);
template
complex operator-(const complex& left,
const complex& right);
template
complex operator-(const complex& left,
const Ty& right);
template
complex operator-(const Ty& left,
const complex& right);
template
complex operator*(const complex& left,
const complex& right);
template
complex operator*(const complex& left,
const Ty& right);
template
complex operator*(const Ty& left,
const complex& right);
template
complex operator/(const complex& left,
const complex& right);
template
complex operator/(const complex& left,
const Ty& right);
template
complex operator/(const Ty& left,
const complex& right);
template
complex operator+(const complex& left);
template
complex operator-(const complex& left);
template
bool operator==(const complex& left,
const complex& right);
template
bool operator==(const complex& left,
const Ty& right);
template
bool operator==(const Ty& left,
const complex& right);
template
bool operator!=(const complex& left,
const complex& right);
template
bool operator!=(const complex& left,
const Ty& right);
template
bool operator!=(const Ty& left,
const complex& right);
template
basic_istream&
operator>>(basic_istream& istr,
complex& right);
template
basic_ostream&
operator<<(basic_ostream& ostr,
const complex& right);
template
Ty real(const complex& left);
template
Ty imag(const complex& left);
template
Ty abs(const complex& left);
template
Ty arg(const complex& left);
template
Ty norm(const complex& left);
template
complex conj(const complex& left);
template
complex polar(const Ty& rho, const Ty& theta = 0);
template
complex cos(const complex& left);
template
complex cosh(const complex& left);
template
complex exp(const complex& left);
template
complex log(const complex& left);
template
complex log10(const complex& left);
template
complex pow(const complex& left, int right);
template
complex pow(const complex& left, const Ty& right);
template
complex pow(const complex& left,
const complex& right);
template
complex pow(const Ty& left, const complex& right);
template
complex sin(const complex& left);
template
complex sinh(const complex& left);
template
complex sqrt(const complex& left);
} // namespace stdCopy to clipboard
## `abs`
template
Ty abs(const complex& left);Copy to clipboard
The function returns the magnitude of `left`.
## `arg`
template
Ty arg(const complex& left);Copy to clipboard
The function returns the phase angle of `left`.
## `complex`
template
class complex {
public:
typedef Ty value_type;
Ty real() const;
Ty imag() const;
complex(const Ty& realval = 0, const Ty& imagval = 0);
template
complex(const complex& right);
template
complex& operator=(const complex& right);
template
complex& operator+=(const complex& right);
template
complex& operator-=(const complex& right);
template
complex& operator*=(const complex& right);
template
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);
};Copy to clipboard
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.
An object of class `Ty`:
- has a public default constructor, destructor,
copy constructor, and assignment operator -- with
conventional behavior
- can be assigned integer or floating-point values, or
type cast to such values -- with
conventional behavior
- defines the arithmetic operators and math functions, as needed,
that are defined for the floating-point
types -- with conventional behavior
In particular, no subtle differences may exist between copy construction
and default construction followed by assignment. And none of the operations
on objects of class `Ty` may throw exceptions.
Explicit specializations of template class `complex`
exist for the three floating-point types. In this
[implementation](https://docs.qualcomm.com/doc/80-N3040-23/topic/cpp_index.html#implementation), a value of any other
type `Ty` is type cast to *double* for actual calculations,
with the *double* result assigned back to the stored object
of type `Ty`.
### `complex::complex`
complex(const Ty& realval = 0, const Ty& imagval = 0);
template
complex(const complex& right);Copy to clipboard
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()`.
In this
[implementation](https://docs.qualcomm.com/doc/80-N3040-23/topic/cpp_index.html#implementation), if a
translator does not support member template functions, the template:
template
complex(const complex& right);Copy to clipboard
is replaced by:
complex(const complex& right);Copy to clipboard
which is the copy constructor.
### `complex::imag`
Ty imag() const;Copy to clipboard
The member function returns the stored imaginary part.
### `complex::operator*=`
template
complex& operator*=(const complex& right);
complex& operator*=(const Ty& right);Copy to clipboard
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`.
In this
[implementation](https://docs.qualcomm.com/doc/80-N3040-23/topic/cpp_index.html#implementation), if a
translator does not support member template functions, the template:
template
complex& operator*=(const complex& right);Copy to clipboard
is replaced by:
complex& operator*=(const complex& right);Copy to clipboard
### `complex::operator+=`
template
complex& operator+=(const complex& right);
complex& operator+=(const Ty& right);Copy to clipboard
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`.
In this
[implementation](https://docs.qualcomm.com/doc/80-N3040-23/topic/cpp_index.html#implementation), if a
translator does not support member template functions, the template:
template
complex& operator+=(const complex& right);Copy to clipboard
is replaced by:
complex& operator+=(const complex& right);Copy to clipboard
### `complex::operator-=`
template
complex& operator-=(const complex& right);
complex& operator-=(const Ty& right);Copy to clipboard
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`.
In this
[implementation](https://docs.qualcomm.com/doc/80-N3040-23/topic/cpp_index.html#implementation), if a
translator does not support member template functions, the template:
template
complex& operator-=(const complex& right);Copy to clipboard
is replaced by:
complex& operator-=(const complex& right);Copy to clipboard
### `complex::operator/=`
template
complex& operator/=(const complex& right);
complex& operator/=(const Ty& right);Copy to clipboard
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`.
In this
[implementation](https://docs.qualcomm.com/doc/80-N3040-23/topic/cpp_index.html#implementation), if a
translator does not support member template functions, the template:
template
complex& operator/=(const complex& right);Copy to clipboard
is replaced by:
complex& operator/=(const complex& right);Copy to clipboard
### `complex::operator=`
template
complex& operator=(const complex& right);
complex& operator=(const Ty& right);Copy to clipboard
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`.
In this
[implementation](https://docs.qualcomm.com/doc/80-N3040-23/topic/cpp_index.html#implementation), if a
translator does not support member template functions, the template:
template
complex& operator=(const complex& right);Copy to clipboard
is replaced by:
complex& operator=(const complex& right);Copy to clipboard
which is the default assignment operator.
### `complex::real`
Ty real() const;Copy to clipboard
The member function returns the stored real part.
### `complex::value_type`
typedef Ty value_type;Copy to clipboard
The type is a synonym for the template parameter `Ty`.
## `complex`
template<>
class complex {
public:
complex(double realval = 0, double imagval = 0);
complex(const complex& right);
explicit complex(const complex& right);
// rest same as template class complex
};Copy to clipboard
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`
template<>
class complex {
public:
complex(float realval = 0, float imagval = 0);
explicit complex(const complex& right);
explicit complex(const complex& right);
// rest same as template class complex
};Copy to clipboard
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`
template<>
class complex {
public:
complex(long double realval = 0, long double imagval = 0);
complex(const complex& right);
complex(const complex& right);
// rest same as template class complex
};Copy to clipboard
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()`.
## `conj`
template
complex conj(const complex& left);Copy to clipboard
The function returns the conjugate of `left`.
## `cos`
template
complex cos(const complex& left);Copy to clipboard
The function returns the cosine of `left`.
## `cosh`
template
complex cosh(const complex& left);Copy to clipboard
The function returns the hyperbolic cosine of `left`.
## `exp`
template
complex exp(const complex& left);Copy to clipboard
The function returns the exponential of `left`.
## `imag`
template
Ty imag(const complex& left);Copy to clipboard
The function returns the imaginary part of `left`.
## `log`
template
complex log(const complex& left);Copy to clipboard
The function returns the logarithm of `left`.
The branch cuts are along the negative real axis.
## `log10`
template
complex log10(const complex& left);Copy to clipboard
The function returns the base 10
logarithm of `left`.
The branch cuts are along the negative real axis.
## `norm`
template
Ty norm(const complex& left);Copy to clipboard
The function returns the squared magnitude of `left`.
## `operator!=`
template
bool operator!=(const complex& left,
const complex& right);
template
bool operator!=(const complex& left,
const Ty& right);
template
bool operator!=(const Ty& left,
const complex& right);Copy to clipboard
The operators each return true only if
`real(left) != real(right) ||
imag(left) != imag(right)`.
## `operator*`
template
complex operator*(const complex& left,
const complex& right);
template
complex operator*(const complex& left,
const Ty& right);
template
complex operator*(const Ty& left,
const complex& right);Copy to clipboard
The operators each convert both operands to the return type,
then return the complex product
of the converted `left` and `right`.
## `operator+`
template
complex operator+(const complex& left,
const complex& right);
template
complex operator+(const complex& left,
const Ty& right);
template
complex operator+(const Ty& left,
const complex& right);
template
complex operator+(const complex& left);Copy to clipboard
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
complex operator-(const complex& left,
const complex& right);
template
complex operator-(const complex& left,
const Ty& right);
template
complex operator-(const Ty& left,
const complex& right);
template
complex operator-(const complex& left);Copy to clipboard
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
complex operator/(const complex& left,
const complex& right);
template
complex operator/(const complex& left,
const Ty& right);
template