다음을 통해 공유


complex<float>

둘 다 형식이 float인 개체의 정렬된 쌍을 저장하는 개체를 설명합니다. 첫 번째 개체는 복소수의 실수 부분을 나타내고 두 번째 개체는 허수 부분을 나타냅니다.

구문

template <>
class complex<float> {
public:
    constexpr complex(
    float _RealVal = 0,
    float _ImagVal = 0);

constexpr complex(
    const complex<float>& complexNum);

constexpr complex(
    const complex<double>& complexNum);

constexpr complex(
    const complex<long double>& complexNum);
// rest same as class template complex
};

매개 변수

_RealVal
생성되는 복소수의 실제 부분에 대한 형식 float 값입니다.

_ImagVal
생성되고 있는 복소수의 허수 부분에 대한 float 형식의 값입니다.

complexNum
생성되는 형식 doublelong double 의 복소수를 초기화하는 데 실제 및 허수 부분을 사용하는 형식 또는 형식 float 의 복소수입니다.

Return Value

float 형식의 복소수입니다.

설명

복합 형식 float 클래스에 대한 클래스 템플릿 복합체의 명시적 특수화는 클래스 템플릿이 정의하는 생성자에서만 클래스 템플릿과 다릅니다. 변환 float 은 암시적일 수 있지만 덜 안전한 변환 floatlong double 은 다음과 여야 합니다explicit.double 할당 구문을 사용하여 형식 변환을 사용하여 시작에 대한 규칙을 사용합니다 explicit .

클래스 템플릿 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,"
        << endl << "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,"
        << endl << "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:"
        << endl << "arg ( c3 ) = "
        << argc3 << " radians, which is " << argc3 * 180 / pi
        << " degrees." << endl;
}
/* Output:
Specifying initial real & imaginary parts,
as type float gives c1 = (4,5)
Implicit conversion from type double to type float,
gives c2float = (1,3)
Explicit conversion from type long double to type float,
gives c3float = (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++ 표준 라이브러리의 스레드 보안