complex<long double>
明示的に特殊化されたこのテンプレート クラスは、順序付けされたオブジェクトのペア (いずれも long double
型) を格納するオブジェクトを記述します。最初のオブジェクトが複素数の実数部、2 番目のオブジェクトが虚数部を表します。
構文
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
関連項目
フィードバック
https://aka.ms/ContentUserFeedback」を参照してください。
以下は間もなく提供いたします。2024 年を通じて、コンテンツのフィードバック メカニズムとして GitHub の issue を段階的に廃止し、新しいフィードバック システムに置き換えます。 詳細については、「フィードバックの送信と表示