complex<float>
將告訴您儲存已排序的成對的物件這兩種類型的物件浮點數*,* 第一次表示複合的數字和第二個真實的部分表示假想的部分。
template<>
class complex<float> {
public:
complex(
float _RealVal = 0,
float _ImagVal = 0
);
complex(
const complex<float>& _ComplexNum
);
complex(
const complex<double>& _ComplexNum
);
complex(
const complex<long double>& _ComplexNum
);
// rest same as template class complex
};
參數
_RealVal
型別的值浮點數的複合的數字所建構的真實的部分。_ImagVal
型別的值浮點數所建構的複數假想的一部份。_ComplexNum
型別的複數雙精度浮點或型別的long double的實際和虛構的部分用來初始化型別的複數浮點數所建構。
傳回值
型別的複數浮點數。
備註
明確特製化樣板類別至複雜型別的類別複雜的浮點數差別只在其所定義的建構函式樣板類別。 從轉換浮點數到雙不可為隱含的但較不安全的轉換,從浮點數到long double都必須是明確。 使用明確規則出初始化時使用指派語法的型別轉換。
如需有關該樣板類別complex,請參閱complex Class。 為一系列的樣板類別成員complex,請參閱複雜的成員。
範例
// complex_comp_flt.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 <float> 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 double
complex <double> c2double ( 1.0 , 3.0 );
complex <float> c2float ( c2double );
cout << "Implicit conversion from type double to type float,"
<< "\n gives c2float = " << c2float << 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 ( 3.0 , 4.0 );
complex <float> c3float ( c3longdouble );
cout << "Explicit conversion from type long double to type float,"
<< "\n gives c3float = " << c3float << endl;
// The modulus and argument of a complex number can be recovered
double absc3 = abs ( c3float);
double argc3 = arg ( c3float);
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;
}
需求
標頭: <complex>
Namespace: 標準