std::complex (3) - Linux Manuals
std::complex: std::complex
NAME
Synopsis
Defined in header <complex>
template< class T > (1)
class complex;
template<> class complex<float>; (2)
template<> class complex<double>; (3)
template<> class complex<long double>; (4)
The specializations std::complex<float>, std::complex<double>, and std::complex<long double> are LiteralTypes for representing and manipulating complex_numbers.
The effect of instantiating the template complex for any other type is unspecified.
Member types
Member type Definition
value_type T
Member functions
constructor (public member function)
operator= (public member function)
real (public member function)
imag (public member function)
operator+= compound assignment of two complex numbers or a complex and a scalar
operator-= (public member function)
operator*=
operator/=
Non-member functions
operator+ (function template)
operator-
operator+ performs complex number arithmetics on two complex values or a complex and a scalar
operator- (function template)
operator*
operator/
operator== (function template)
operator!=
operator<< (function template)
operator>>
real (function template)
imag (function template)
abs(std::complex) (function template)
arg (function template)
norm (function template)
conj (function template)
proj returns the projection onto the Riemann sphere
(C++11)
polar (function template)
Exponential functions
exp(std::complex) (function template)
log(std::complex) (function template)
log10(std::complex) (function template)
Power functions
pow(std::complex) (function template)
sqrt(std::complex) (function template)
Trigonometric functions
sin(std::complex) (function template)
cos(std::complex) (function template)
tan(std::complex) (function template)
asin(std::complex) computes arc sine of a complex number (arcsin(z))
(C++11)
acos(std::complex) computes arc cosine of a complex number (arccos(z))
(C++11)
atan(std::complex) computes arc tangent of a complex number (arctan(z))
(C++11)
Hyperbolic functions
sinh(std::complex) (function template)
cosh(std::complex) (function template)
tanh(std::complex) (function template)
asinh(std::complex) computes area hyperbolic sine of a complex number
(C++11)
acosh(std::complex) computes area hyperbolic cosine of a complex number
(C++11)
atanh(std::complex) computes area hyperbolic tangent of a complex number
(C++11)
Array-oriented access
For any object z of type complex<T>, reinterpret_cast<T(&)[2]>(z)[0] is the real part of z and reinterpret_cast<T(&)[2]>(z)[1] is the imaginary part of z.
For any pointer to an element of an array of complex<T> named p and any valid array index i, reinterpret_cast<T*>(p)[2*i] is the real part of the complex number p[i], and reinterpret_cast<T*>(p)[2*i + 1] is the imaginary part of the complex number p[i] (since C++11)
The intent of this requirement is to preserve binary compatibility between the C++ library complex number types and the C_language_complex_number_types (and arrays thereof), which have an identical object representation requirement.
Implementation notes
In order to satisfy the requirements of array-oriented access, an implementation is constrained to store the real and imaginary components of a std::complex specialization in separate and adjacent memory locations. Possible declarations for its non-static data members include:
* an array of type value_type[2], with the first element holding the real component and the second element holding the imaginary component (e.g. Microsoft Visual Studio)
* a single member of type value_type _Complex (encapsulating the corresponding C_language_complex_number_type) (e.g. GNU libstdc++); (since C++11)
* two members of type value_type, with the same member access, holding the real and the imaginary components respectively (e.g. LLVM libc++).
An implementation cannot declare additional non-static data members that would occupy storage disjoint from the real and imaginary components, and must ensure that the class template specialization does not contain any padding. The implementation must also ensure that optimizations to array access account for the possibility that a pointer to value_type may be aliasing a std::complex specialization or array thereof.
Literals
Defined in inline namespace std::literals::complex_literals
operator""if
operator""i A std::complex literal representing pure imaginary number
operator""il (function)
(C++14)
Example
// Run this code
Output:
See also