std::complex::operator+(binary), operator-(binary), operator*, operator/
来自cppreference.com
该页由英文版wiki使用Google Translate机器翻译而来。
该翻译可能存在错误或用词不当。鼠标停留在文本上可以看到原版本。你可以帮助我们修正错误或改进翻译。参见说明请点击这里. |
template< class T > complex<T> operator+( const complex<T>& lhs, const complex<T>& rhs); |
(1) | |
template< class T > complex<T> operator+( const complex<T>& lhs, const T& rhs); |
(2) | |
template< class T > complex<T> operator+( const T& lhs, const complex<T>& rhs); |
(3) | |
template< class T > complex<T> operator-( const complex<T>& lhs, const complex<T>& rhs); |
(4) | |
template< class T > complex<T> operator-( const complex<T>& lhs, const T& rhs); |
(5) | |
template< class T > complex<T> operator-( const T& lhs, const complex<T>& rhs); |
(6) | |
template< class T > complex<T> operator*( const complex<T>& lhs, const complex<T>& rhs); |
(7) | |
template< class T > complex<T> operator*( const complex<T>& lhs, const T& rhs); |
(8) | |
template< class T > complex<T> operator*( const T& lhs, const complex<T>& rhs); |
(9) | |
template< class T > complex<T> operator/( const complex<T>& lhs, const complex<T>& rhs); |
(10) | |
template< class T > complex<T> operator/( const complex<T>& lhs, const T& rhs); |
(11) | |
template< class T > complex<T> operator/( const T& lhs, const complex<T>& rhs); |
(12) | |
实现复杂的算术和混合的复杂/标量运算的二元运算符。标量参数被视为等于该参数的实部和虚部设置为零的复数.
原文:
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.
1-3)
返回其参数的总和
4-6)
返回减去
rhs
从lhs
结果原文:
Returns the result of subtracting
rhs
from lhs
7-9)
它的参数相乘
10-12)
目录 |
[编辑] 参数
lhs, rhs | - | 参数:无论是复杂的数字或一个复杂的和一个标量的匹配类型(float,double,long double)
原文: the arguments: either both complex numbers or one complex and one scalar of matching type (float, double, long double) |
[编辑] 返回值
1-3) complex<T>(lhs) += rhs
4-6) complex<T>(lhs) -= rhs
7-9) complex<T>(lhs) *= rhs
10-12) complex<T>(lhs) /= rhs
[编辑] 示例
#include <iostream> #include <complex> int main() { std::complex<double> c2(2, 0); std::complex<double> ci(0, 1); std::cout << ci << " + " << c2 << " = " << ci+c2 << '\n' << ci << " * " << ci << " = " << ci*ci << '\n' << ci << " + " << c2 << " / " << ci << " = " << ci+c2/ci << '\n' << 1 << " / " << ci << " = " << 1./ci << '\n'; // std::cout << 1.f/ci; // compile error // std::cout << 1/ci; // compile error }
输出:
(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)
[编辑] 另请参阅
两个复数或一个复杂的和一个标量的复合赋值 原文: compound assignment of two complex numbers or a complex and a scalar (公共成员函数) | |
一元运算符复数 原文: applies unary operators to complex numbers (函数模板) |