共用方式為


complex<float>

描述儲存已排序的物件兩種 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
    型別 float 的值所建構的複數的實數部分的。

  • _ImagVal
    型別 float 的值所建構的複數的虛數部分。

  • _ComplexNum
    型別 double 複數實數及虛數用來初始化型別建構的 float 複數的或型別 long double 。

傳回值

型別 float複數。

備註

樣板類別複雜的明確特製化對型別 float 複雜類別的與它所定義的範本只有類別有建構函式。 從 float 轉換為 double 允許是隱含的,不過,到 long double 要求從 float 的較不安全的轉換是 explicit。 使用指派語法,使用 explicit 排除與型別轉換的初始。

如需範本類別 complex,請參閱 complex 類別。 如需範本類別 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;
}
  

需求

Header: <複雜>

命名空間: std

請參閱

參考

complex 類別

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

其他資源

<complex> 成員

複雜的成員