다음을 통해 공유


complex<double>

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

구문

template <>
class complex<double> {
public:
    constexpr complex(
    double RealVal = 0,
    double ImagVal = 0);

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

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

매개 변수

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

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

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

Return Value

double 형식의 복소수입니다.

설명

복합 형식 double 클래스에 대한 클래스 템플릿 복합체의 명시적 특수화는 클래스 템플릿이 정의하는 생성자에서만 클래스 템플릿과 다릅니다. 변환 floatdouble 을 암시적으로 사용할 수 있지만 long doubledouble 변환할 수 있어야 explicit합니다. 할당 구문을 사용하여 형식 변환을 사용하여 시작에 대한 규칙을 사용합니다 explicit .

클래스 템플릿 complex에 대한 자세한 내용은 복합 클래스를 참조 하세요. 클래스 템플릿 complex의 멤버 목록은 다음을 참조하세요.

예시

// complex_comp_dbl.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 <double> c1 ( 4.0 , 5.0 );
   cout << "Specifying initial real & imaginary parts,\n"
        << "as type double 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 ( 4.0 , 5.0 );
   complex <double> c2double ( c2float );
   cout << "Implicit conversion from type float to type double,"
        << endl << "gives c2double = " << c2double << 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 ( 4.0 , 5.0 );
   complex <double> c3double ( c3longdouble );
   cout << "Explicit conversion from type float to type double,"
        << endl << "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:" << endl
        << "arg ( c3 ) = " << argc3 << " radians, which is "
        << argc3 * 180 / pi << " degrees." << endl;
}
/* Output:
Specifying initial real & imaginary parts,
as type double gives c1 = (4,5)
Implicit conversion from type float to type double,
gives c2double = (4,5)
Explicit conversion from type float to type double,
gives c3longdouble = (4,5)
The modulus of c3 is recovered from c3 using: abs ( c3 ) = 6.40312
Argument of c3 is recovered from c3 using:
arg ( c3 ) = 0.896055 radians, which is 51.3402 degrees.
*/

요구 사항

헤더: <복합>

네임스페이스: std

참고 항목

complex 클래스
C++ 표준 라이브러리의 스레드 보안