Примечание.
Для доступа к этой странице требуется авторизация. Вы можете попробовать войти или изменить каталоги.
Для доступа к этой странице требуется авторизация. Вы можете попробовать изменить каталоги.
Описывает объект, который хранит упорядоченную пару объектов типа double; первый представляет вещественную часть комплексного числа, а второй — мнимую.
Syntax
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
};
Parameters
RealVal
Значение типа double для реальной части создаваемого сложного числа.
ImagVal
Значение типа double для мнимой части конструируемого комплексного числа.
complexNum
Комплексное число типов или типов floatlong double , реальные и мнимые части которых используются для инициализации сложного числа создаваемых типов double .
Return Value
Комплексное число типа double.
Remarks
Явная специализация сложного шаблона класса к сложному классу типа double отличается от шаблона класса только в конструкторах, которые он определяет. Преобразование из floatdouble в long double неявное значение допускается, но для преобразования double из нее требуетсяexplicit. Использование правила запуска с преобразованием типов с помощью синтаксиса explicit назначения.
Дополнительные сведения о шаблоне complex класса и его членах см. в разделе complex "Класс".
Example
// 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.
*/
Requirements
Header: <complex>
Namespace:std
See also
complex Класс
Потокобезопасность в стандартной библиотеке C++