共用方式為


complex<long double>

這個明確特製化的類別範本描述一個物件,該物件會儲存一組已排序的物件,兩者都是 型 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
型別或floatdouble別的複數,其實數和虛數部分用來初始化所建構之型long double別的複數。

傳回值

long double 類型的複數。

備註

將類別範本 complex 明確特製化為型 long double 別複雜類別,只與類別範本在所定義的建構函式中不同。 從 轉換成 long double 是隱含的,但從 double long double 轉換成 必須是 explicitfloat 使用 explicit 指派語法排除初始與型別轉換。

如需類別範本 complex 及其成員的詳細資訊,請參閱 複雜類別

Microsoft特定long doubledouble 型別具有相同的表示法,但是不同的型別。 如需詳細資訊,請參閱 內建類型

範例

// 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.

需求

標頭: <複雜>

命名空間:std

另請參閱

complex 類別
C++ 標準程式庫中的執行緒安全