这个显式专用化的类模板描述了一个对象,该对象存储两个都为 long double
类型的有序对象对,第一个对象表示复数的实部,第二个对象表示复数的虚部。
语法
template <>
class complex<long double> {
public:
constexpr complex(
long double _RealVal = 0,
long double _ImagVal = 0);
complex(
constexpr complex<long double>& complexNum);
// rest same as class template complex
};
参数
_RealVal
正在构造的复数实部的 long double
类型值。
_ImagVal
正在构造的复数虚部的 long double
类型值。
complexNum
类型为 double
或 float
的复数,其实部和虚部用于初始化正在构造的 long double
类型的复数。
返回值
long double
类型的复数。
备注
类模板 complex
显式专用化为 long double
类型的 complex 类仅与它所定义构造函数中的类模板不同。 从 long double
到 float
类型的转换可以是隐式的,但从 double
到 long double
的转换必须是 explicit
。 使用 explicit
转换可取消在最初使用赋值语法进行类型转换。
有关 complex
类模板及其成员的详细信息,请参阅 complex 类。
特定于 Microsoft:long double
和 double
类型具有相同的表示形式,但为不同类型。 有关详细信息,请参阅内置类型。
示例
// complex_comp_ld.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<long double> c1( 4.0 , 5.0 );
cout << "Specifying initial real & imaginary parts,\n"
<< " as type float 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( 1.0 , 3.0 );
complex<long double> c2longdouble ( c2float );
cout << "Implicit conversion from type float to type long double,"
<< "\n gives c2longdouble = " << c2longdouble << endl;
// The third constructor initializes values of the real &
// imaginary parts using those of a complex number
// of type double
complex<double> c3double( 3.0 , 4.0 );
complex<long double> c3longdouble( c3double );
cout << "Implicit conversion from type long double to type float,"
<< "\n 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:\n arg( c3 ) = "
<< argc3 << " radians, which is " << argc3 * 180 / pi
<< " degrees." << endl;
}
Specifying initial real & imaginary parts,
as type float gives c1 = (4,5)
Implicit conversion from type float to type long double,
gives c2longdouble = (1,3)
Implicit conversion from type long double to type float,
gives c3longdouble = (3,4)
The modulus of c3 is recovered from c3 using: abs( c3 ) = 5
Argument of c3 is recovered from c3 using:
arg( c3 ) = 0.927295 radians, which is 53.1301 degrees.
要求
标头:<complex>
命名空间: std