Udostępnij za pośrednictwem


complex<long double>

Ten jawnie wyspecjalizowany szablon klasy opisuje obiekt, który przechowuje uporządkowaną parę obiektów, zarówno typu long double, jak i pierwszy reprezentujący rzeczywistą część liczby zespolonej i drugą reprezentującą część wyimaginowaną.

Składnia

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

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

// rest same as class template complex
};

Parametry

_RealVal
Wartość typu long double dla rzeczywistej części tworzonej liczby zespolonej.

_ImagVal
Wartość typu long double dla wyimaginowanej części tworzonej liczby zespolonej.

complexNum
Liczba zespolona typu lub typu doublefloat , którego rzeczywiste i wyimaginowane części są używane do inicjowania złożonej liczby konstruowanych typów long double .

Wartość zwracana

Liczba zespolonej typu long double.

Uwagi

Jawna specjalizacja szablonu complex klasy do złożonej klasy typu long double różni się od szablonu klasy tylko w konstruktorach, które definiuje. Konwersja z long double na float może być niejawna, ale konwersja z double na long double musi być explicit. Użycie reguł inicjowania explicit z konwersją typu przy użyciu składni przypisania.

Aby uzyskać więcej informacji na temat szablonu complex klasy i jej składowych, zobacz complex Class (Klasa złożona).

Specyficzne dla firmy Microsoft: long double typy i double mają tę samą reprezentację, ale są różnymi typami. Aby uzyskać więcej informacji, zobacz Wbudowane typy.

Przykład

// complex_comp_ld.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<long double> 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 float
    complex<float> c2float( 1.0 , 3.0 );
    complex<long double> c2longdouble ( c2float );
    cout << "Implicit conversion from type float to type long double,"
        << "\n gives c2longdouble = " << c2longdouble << endl;

    // The third constructor initializes values of the real &
    // imaginary parts using those of a complex number
    // of type double
    complex<double> c3double( 3.0 , 4.0 );
    complex<long double> c3longdouble( c3double );
    cout << "Implicit conversion from type long double to type float,"
        << "\n 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:\n arg( c3 ) = "
        << argc3 << " radians, which is " << argc3 * 180 / pi
        << " degrees." << endl;
}
Specifying initial real & imaginary parts,
as type float gives c1 = (4,5)
Implicit conversion from type float to type long double,
gives c2longdouble = (1,3)
Implicit conversion from type long double to type float,
gives c3longdouble = (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.

Wymagania

Nagłówek: <złożony>

Przestrzeń nazw: std

Zobacz też

complex, klasa
Bezpieczeństwo wątku w standardowej bibliotece C++