operator+,-,*,/ (std::complex)
| Common mathematical functions | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Mathematical special functions (C++17) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Mathematical constants (C++20) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Basic linear algebra algorithms (C++26) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Data-parallel types (SIMD) (C++26) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Floating-point environment (C++11) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Complex numbers | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Numeric array (valarray) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Pseudo-random number generation | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Bit manipulation (C++20) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Saturation arithmetic (C++26) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Factor operations | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Interpolations | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Generic numeric operations | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| C-style checked integer arithmetic | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Member functions | ||||||||||||||||||||||||||
| Non-member functions | ||||||||||||||||||||||||||
| ||||||||||||||||||||||||||
| Exponential functions | ||||||||||||||||||||||||||
| Power functions | ||||||||||||||||||||||||||
| Trigonometric functions | ||||||||||||||||||||||||||
| Hyperbolic functions | ||||||||||||||||||||||||||
| Helper types | ||||||||||||||||||||||||||
(C++26) | ||||||||||||||||||||||||||
(C++26) | ||||||||||||||||||||||||||
| (1) | ||
template< class T > std::complex<T> operator+( const std::complex<T>& lhs, |
(until C++20) | |
| template< class T > constexpr std::complex<T> operator+( const std::complex<T>& lhs, |
(since C++20) | |
| (2) | ||
template< class T > std::complex<T> operator+( const std::complex<T>& lhs, |
(until C++20) | |
| template< class T > constexpr std::complex<T> operator+( const std::complex<T>& lhs, |
(since C++20) | |
| (3) | ||
template< class T > std::complex<T> operator+( const T& lhs, |
(until C++20) | |
| template< class T > constexpr std::complex<T> operator+( const T& lhs, |
(since C++20) | |
| (4) | ||
template< class T > std::complex<T> operator-( const std::complex<T>& lhs, |
(until C++20) | |
| template< class T > constexpr std::complex<T> operator-( const std::complex<T>& lhs, |
(since C++20) | |
| (5) | ||
template< class T > std::complex<T> operator-( const std::complex<T>& lhs, |
(until C++20) | |
| template< class T > constexpr std::complex<T> operator-( const std::complex<T>& lhs, |
(since C++20) | |
| (6) | ||
template< class T > std::complex<T> operator-( const T& lhs, |
(until C++20) | |
| template< class T > constexpr std::complex<T> operator-( const T& lhs, |
(since C++20) | |
| (7) | ||
template< class T > std::complex<T> operator*( const std::complex<T>& lhs, |
(until C++20) | |
| template< class T > constexpr std::complex<T> operator*( const std::complex<T>& lhs, |
(since C++20) | |
| (8) | ||
template< class T > std::complex<T> operator*( const std::complex<T>& lhs, |
(until C++20) | |
| template< class T > constexpr std::complex<T> operator*( const std::complex<T>& lhs, |
(since C++20) | |
| (9) | ||
template< class T > std::complex<T> operator*( const T& lhs, |
(until C++20) | |
| template< class T > constexpr std::complex<T> operator*( const T& lhs, |
(since C++20) | |
| (10) | ||
template< class T > std::complex<T> operator/( const std::complex<T>& lhs, |
(until C++20) | |
| template< class T > constexpr std::complex<T> operator/( const std::complex<T>& lhs, |
(since C++20) | |
| (11) | ||
template< class T > std::complex<T> operator/( const std::complex<T>& lhs, |
(until C++20) | |
| template< class T > constexpr std::complex<T> operator/( const std::complex<T>& lhs, |
(since C++20) | |
| (12) | ||
template< class T > std::complex<T> operator/( const T& lhs, |
(until C++20) | |
| template< class T > constexpr std::complex<T> operator/( const T& lhs, |
(since C++20) | |
Implements the binary operators for complex arithmetic and for mixed complex/scalar arithmetic. Scalar arguments are treated as complex numbers with the real part equal to the argument and the imaginary part set to zero.
Contents |
[edit] Parameters
| lhs, rhs | - | the arguments: either both complex numbers or one complex and one scalar of matching type (float, double, long double) |
[edit] Return value
[edit] Notes
Because template argument deduction does not consider implicit conversions, these operators cannot be used for mixed integer/complex arithmetic. In all cases, the scalar must have the same type as the underlying type of the complex number.
The GCC flag "-fcx-limited-range" (included by "-ffast-math") changes the behavior of complex multiply/division by removing checks for floating point edge cases. This impacts loop vectorization.
[edit] Example
#include <complex> #include <iostream> int main() { std::complex<double> c2(2.0, 0.0); std::complex<double> ci(0.0, 1.0); std::cout << ci << " + " << c2 << " = " << ci + c2 << '\n' << ci << " * " << ci << " = " << ci * ci << '\n' << ci << " + " << c2 << " / " << ci << " = " << ci + c2 / ci << '\n' << 1 << " / " << ci << " = " << 1.0 / ci << '\n'; / std::cout << 1.0f / ci; / compile error / std::cout << 1 / ci; / compile error }
Output:
(0,1) + (2,0) = (2,1) (0,1) * (0,1) = (-1,0) (0,1) + (2,0) / (0,1) = (0,-1) 1 / (0,1) = (0,-1)
[edit] See also
| compound assignment of two complex numbers or a complex and a scalar (public member function) [edit] | |
| applies unary operators to complex numbers (function template) [edit] |