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.
Beschreibt ein Objekt, das ein geordnetes Paar von Objekten speichert, die beide den Typ float haben, wobei das erste Objekt dem reellen Teil einer komplexen Zahl und das zweite Objekt dem imaginären Teil entspricht.
Syntax
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
};
Parameters
_RealVal
Der Wert des Typs float für den tatsächlichen Teil der komplexen Zahl, die erstellt wird.
_ImagVal
Der Wert des Typs float für den imaginären Teil der komplexen Zahl, die erstellt wird.
complexNum
Die komplexe Anzahl von Typ oder double Typ long double , deren reale und imaginäre Teile verwendet werden, um eine komplexe Anzahl von Typ float zu initialisieren, die erstellt wird.
Return Value
Eine komplexe Zahl des Typs float.
Remarks
Die explizite Spezialisierung der Klassenvorlage auf eine komplexe Klasse des Typs float unterscheidet sich von der Klassenvorlage nur in den definierten Konstruktoren. Die Konvertierung von float zu " double in" darf implizit sein, aber die weniger sichere Konvertierung von float zu long double " ist erforderlich explicit. 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 complex "Klasse".
Example
// 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.
*/
Requirements
Header: <complex>
Namespace:std
See also
complex-Klasse
Threadsicherheit in der C++-Standardbibliothek