Namespaces
Variants

operator+,-,*,/ (std::complex)

From cppreference.net
(Anmerkung: Der bereitgestellte HTML-Code enthält keinen übersetzbaren Text, da alle Tags leer sind oder nur Klassenattribute enthalten. Gemäß den Anforderungen wurden HTML-Tags und Attribute nicht übersetzt.)
(1)
template < class T >

std:: complex < T > operator + ( const std:: complex < T > & lhs,

const std:: complex < T > & rhs ) ;
(bis C++20)
template < class T >

constexpr std:: complex < T > operator + ( const std:: complex < T > & lhs,

const std:: complex < T > & rhs ) ;
(seit C++20)
(2)
template < class T >

std:: complex < T > operator + ( const std:: complex < T > & lhs,

const T & rhs ) ;
(bis C++20)
template < class T >

constexpr std:: complex < T > operator + ( const std:: complex < T > & lhs,

const T & rhs ) ;
(seit C++20)
(3)
template < class T >

std:: complex < T > operator + ( const T & lhs,

const std:: complex < T > & rhs ) ;
(bis C++20)
template < class T >

constexpr std:: complex < T > operator + ( const T & lhs,

const std:: complex < T > & rhs ) ;
(seit C++20)
(4)
template < class T >

std:: complex < T > operator - ( const std:: complex < T > & lhs,

const std:: complex < T > & rhs ) ;
(bis C++20)
template < class T >

constexpr std:: complex < T > operator - ( const std:: complex < T > & lhs,

const std:: complex < T > & rhs ) ;
(seit C++20)
(5)
template < class T >

std:: complex < T > operator - ( const std:: complex < T > & lhs,

const T & rhs ) ;
(bis C++20)
template < class T >

constexpr std:: complex < T > operator - ( const std:: complex < T > & lhs,

const T & rhs ) ;
(seit C++20)
(6)
template < class T >

std:: complex < T > operator - ( const T & lhs,

const std:: complex < T > & rhs ) ;
(bis C++20)
template < class T >

constexpr std:: complex < T > operator - ( const T & lhs,

const std:: complex < T > & rhs ) ;
(seit C++20)
(7)
template < class T >

std:: complex < T > operator * ( const std:: complex < T > & lhs,

const std:: complex < T > & rhs ) ;
(bis C++20)
template < class T >

constexpr std:: complex < T > operator * ( const std:: complex < T > & lhs,

const std:: complex < T > & rhs ) ;
(seit C++20)
(8)
template < class T >

std:: complex < T > operator * ( const std:: complex < T > & lhs,

const T & rhs ) ;
(bis C++20)
template < class T >

constexpr std:: complex < T > operator * ( const std:: complex < T > & lhs,

const T & rhs ) ;
(seit C++20)
(9)
template < class T >

std:: complex < T > operator * ( const T & lhs,

const std:: complex < T > & rhs ) ;
(bis C++20)
template < class T >

constexpr std:: complex < T > operator * ( const T & lhs,

const std:: complex < T > & rhs ) ;
(seit C++20)
(10)
template < class T >

std:: complex < T > operator / ( const std:: complex < T > & lhs,

const std:: complex < T > & rhs ) ;
(bis C++20)
template < class T >

constexpr std:: complex < T > operator / ( const std:: complex < T > & lhs,

const std:: complex < T > & rhs ) ;
(seit C++20)
(11)
template < class T >

std:: complex < T > operator / ( const std:: complex < T > & lhs,

const T & rhs ) ;
(bis C++20)
template < class T >

constexpr std:: complex < T > operator / ( const std:: complex < T > & lhs,

const T & rhs ) ;
(seit C++20)
(12)
template < class T >

std:: complex < T > operator / ( const T & lhs,

const std:: complex < T > & rhs ) ;
(bis C++20)
template < class T >

constexpr std:: complex < T > operator / ( const T & lhs,

const std:: complex < T > & rhs ) ;
(seit C++20)

Implementiert die binären Operatoren für komplexe Arithmetik und für gemischte komplexe/Skalar-Arithmetik. Skalar-Argumente werden als komplexe Zahlen behandelt, bei denen der Realteil gleich dem Argument ist und der Imaginärteil auf null gesetzt wird.

1-3) Gibt die Summe ihrer Argumente zurück.
4-6) Gibt das Ergebnis der Subtraktion von rhs von lhs zurück.
7-9) Multipliziert seine Argumente.
10-12) Teilt lhs durch rhs .

Inhaltsverzeichnis

Parameter

lhs, rhs - die Argumente: entweder beide komplexe Zahlen oder eine komplexe Zahl und ein Skalar des passenden Typs ( float , double , long double )

Rückgabewert

1-3) std:: complex < T > ( lhs ) + = rhs
4-6) std:: complex < T > ( lhs ) - = rhs
7-9) std:: complex < T > ( lhs ) * = rhs
10-12) std:: complex < T > ( lhs ) / = rhs

Hinweise

Da Template-Argument-Deduktion implizite Konvertierungen nicht berücksichtigt, können diese Operatoren nicht für gemischte Integer-/Komplexarithmetik verwendet werden. In allen Fällen muss der Skalar denselben Typ wie der zugrundeliegende Typ der komplexen Zahl haben.

Das GCC-Flag "-fcx-limited-range" (enthalten in "-ffast-math") ändert das Verhalten von komplexen Multiplikations-/Divisionsoperationen, indem Überprüfungen auf Gleitkomma-Grenzfälle entfernt werden. Dies beeinflusst die Schleifenvektorisierung.

Beispiel

#include <complex>
#include <iostream>
int main()
{
    std::complex<double> c2(2.0, 0.0);
    std::complex<double> ci(0.0, 1.0);
    std::cout << ci << " + " << c2 << " = " << ci + c2 << '\n'
              << ci << " * " << ci << " = " << ci * ci << '\n'
              << ci << " + " << c2 << " / " << ci << " = " << ci + c2 / ci << '\n'
              << 1  << " / " << ci << " = " << 1.0 / ci << '\n';
//    std::cout << 1.0f / ci; // compile error
//    std::cout << 1 / ci; // compile error
}

Ausgabe:

(0,1) + (2,0) = (2,1)
(0,1) * (0,1) = (-1,0)
(0,1) + (2,0) / (0,1) = (0,-1)
1 / (0,1) = (0,-1)

Siehe auch

zusammengesetzte Zuweisung zweier komplexer Zahlen oder einer komplexen Zahl und eines Skalars
(öffentliche Elementfunktion)
wendet unäre Operatoren auf komplexe Zahlen an
(Funktions-Template)