complex<double>
描述一个对象,该对象存储两个都为 double
类型的有序对象对,该有序对中的第一个对象表示复数的实部,第二个对象表示复数虚部。
语法
template <>
class complex<double> {
public:
constexpr complex(
double RealVal = 0,
double ImagVal = 0);
constexpr complex(const complex<double>& complexNum);
constexpr explicit complex(const complex<long double>& complexNum);
// rest same as class template complex
};
参数
RealVal
正在构造的复数实部的 double
类型值。
ImagVal
正在构造的复数虚部的 double
类型值。
complexNum
类型为 float
或 long double
的复数,其实部和虚部用于初始化正在构造的 double
类型的复数。
返回值
double
类型的复数。
注解
类模板 complex 显式专用化为 double
类型的 complex 类仅与它所定义构造函数中的类模板不同。 从 float
到 double
类型的转换可以是隐式的,但从 long double
到 double
的转换必须是 explicit
。 使用 explicit
转换可取消在最初使用赋值语法进行类型转换。
有关 complex
类模板的详细信息,请参阅 complex 类。 有关 complex
类模板的成员列表,请参阅。
示例
// complex_comp_dbl.cpp
// compile with: /EHsc
#include <complex>
#include <iostream>
int main( )
{
using namespace std;
double pi = 3.14159265359;
// The first constructor specifies real & imaginary parts
complex <double> c1 ( 4.0 , 5.0 );
cout << "Specifying initial real & imaginary parts,\n"
<< "as type double gives c1 = " << c1 << endl;
// The second constructor initializes values of the real &
// imaginary parts using those of complex number of type float
complex <float> c2float ( 4.0 , 5.0 );
complex <double> c2double ( c2float );
cout << "Implicit conversion from type float to type double,"
<< endl << "gives c2double = " << c2double << endl;
// The third constructor initializes values of the real &
// imaginary parts using those of a complex number
// of type long double
complex <long double> c3longdouble ( 4.0 , 5.0 );
complex <double> c3double ( c3longdouble );
cout << "Explicit conversion from type float to type double,"
<< endl << "gives c3longdouble = " << c3longdouble << endl;
// The modulus and argument of a complex number can be recovered
double absc3 = abs ( c3longdouble );
double argc3 = arg ( c3longdouble );
cout << "The modulus of c3 is recovered from c3 using: abs ( c3 ) = "
<< absc3 << endl;
cout << "Argument of c3 is recovered from c3 using:" << endl
<< "arg ( c3 ) = " << argc3 << " radians, which is "
<< argc3 * 180 / pi << " degrees." << endl;
}
/* Output:
Specifying initial real & imaginary parts,
as type double gives c1 = (4,5)
Implicit conversion from type float to type double,
gives c2double = (4,5)
Explicit conversion from type float to type double,
gives c3longdouble = (4,5)
The modulus of c3 is recovered from c3 using: abs ( c3 ) = 6.40312
Argument of c3 is recovered from c3 using:
arg ( c3 ) = 0.896055 radians, which is 51.3402 degrees.
*/
要求
标头:<complex>
命名空间: std