Hinweis
Für den Zugriff auf diese Seite ist eine Autorisierung erforderlich. Sie können versuchen, sich anzumelden oder das Verzeichnis zu wechseln.
Für den Zugriff auf diese Seite ist eine Autorisierung erforderlich. Sie können versuchen, das Verzeichnis zu wechseln.
Diese explizit spezialisierte Klassenvorlage beschreibt ein Objekt, das ein sortiertes Paar von Objekten speichert, beide vom Typ long double
, der erste, der den tatsächlichen Teil einer komplexen Zahl darstellt und die zweite, die den imaginären Teil darstellt.
Syntax
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
};
Parameter
_RealVal
Der Wert des Typs long double
für den tatsächlichen Teil der komplexen Zahl, die erstellt wird.
_ImagVal
Der Wert des Typs long double
für den imaginären Teil der komplexen Zahl, die erstellt wird.
complexNum
Die komplexe Anzahl von Typ oder double
Typ float
, deren reale und imaginäre Teile verwendet werden, um eine komplexe Anzahl von Typ long double
zu initialisieren, die erstellt wird.
Rückgabewert
Eine komplexe Zahl des Typs long double
.
Hinweise
Die explizite Spezialisierung der Klassenvorlage complex
auf eine komplexe Klasse vom Typ long double
unterscheidet sich von der Klassenvorlage nur in den von ihr definierten Konstruktoren. Die Konvertierung von "inlong double
" darf implizit sein, die Konvertierung von "in long double
double
" ist jedoch erforderlichexplicit
float
. Die Verwendung von Regeln für die Initiierung mit Typkonvertierung mithilfe der Zuordnungssyntax explicit
.
Weitere Informationen zur Klassenvorlage complex
und den dazugehörigen Elementen finden Sie unter "Komplexe Klasse".
Microsoft-spezifisch: Die long double
typen double
weisen die gleiche Darstellung auf, sind jedoch unterschiedliche Typen. Weitere Informationen finden Sie unter integrierten Typen.
Beispiel
// 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.
Anforderungen
Kopfzeile: <komplex>
Namespace: std
Siehe auch
complex-Klasse
Threadsicherheit in der C++-Standardbibliothek