operator+,-,*,/ (std::complex)
| (1) | ||
|
template
<
class
T
>
std::
complex
<
T
>
operator
+
(
const
std::
complex
<
T
>
&
lhs,
|
(bis C++20) | |
|
template
<
class
T
>
constexpr
std::
complex
<
T
>
operator
+
(
const
std::
complex
<
T
>
&
lhs,
|
(seit C++20) | |
| (2) | ||
|
template
<
class
T
>
std::
complex
<
T
>
operator
+
(
const
std::
complex
<
T
>
&
lhs,
|
(bis C++20) | |
|
template
<
class
T
>
constexpr
std::
complex
<
T
>
operator
+
(
const
std::
complex
<
T
>
&
lhs,
|
(seit C++20) | |
| (3) | ||
|
template
<
class
T
>
std::
complex
<
T
>
operator
+
(
const
T
&
lhs,
|
(bis C++20) | |
|
template
<
class
T
>
constexpr
std::
complex
<
T
>
operator
+
(
const
T
&
lhs,
|
(seit C++20) | |
| (4) | ||
|
template
<
class
T
>
std::
complex
<
T
>
operator
-
(
const
std::
complex
<
T
>
&
lhs,
|
(bis C++20) | |
|
template
<
class
T
>
constexpr
std::
complex
<
T
>
operator
-
(
const
std::
complex
<
T
>
&
lhs,
|
(seit C++20) | |
| (5) | ||
|
template
<
class
T
>
std::
complex
<
T
>
operator
-
(
const
std::
complex
<
T
>
&
lhs,
|
(bis C++20) | |
|
template
<
class
T
>
constexpr
std::
complex
<
T
>
operator
-
(
const
std::
complex
<
T
>
&
lhs,
|
(seit C++20) | |
| (6) | ||
|
template
<
class
T
>
std::
complex
<
T
>
operator
-
(
const
T
&
lhs,
|
(bis C++20) | |
|
template
<
class
T
>
constexpr
std::
complex
<
T
>
operator
-
(
const
T
&
lhs,
|
(seit C++20) | |
| (7) | ||
|
template
<
class
T
>
std::
complex
<
T
>
operator
*
(
const
std::
complex
<
T
>
&
lhs,
|
(bis C++20) | |
|
template
<
class
T
>
constexpr
std::
complex
<
T
>
operator
*
(
const
std::
complex
<
T
>
&
lhs,
|
(seit C++20) | |
| (8) | ||
|
template
<
class
T
>
std::
complex
<
T
>
operator
*
(
const
std::
complex
<
T
>
&
lhs,
|
(bis C++20) | |
|
template
<
class
T
>
constexpr
std::
complex
<
T
>
operator
*
(
const
std::
complex
<
T
>
&
lhs,
|
(seit C++20) | |
| (9) | ||
|
template
<
class
T
>
std::
complex
<
T
>
operator
*
(
const
T
&
lhs,
|
(bis C++20) | |
|
template
<
class
T
>
constexpr
std::
complex
<
T
>
operator
*
(
const
T
&
lhs,
|
(seit C++20) | |
| (10) | ||
|
template
<
class
T
>
std::
complex
<
T
>
operator
/
(
const
std::
complex
<
T
>
&
lhs,
|
(bis C++20) | |
|
template
<
class
T
>
constexpr
std::
complex
<
T
>
operator
/
(
const
std::
complex
<
T
>
&
lhs,
|
(seit C++20) | |
| (11) | ||
|
template
<
class
T
>
std::
complex
<
T
>
operator
/
(
const
std::
complex
<
T
>
&
lhs,
|
(bis C++20) | |
|
template
<
class
T
>
constexpr
std::
complex
<
T
>
operator
/
(
const
std::
complex
<
T
>
&
lhs,
|
(seit C++20) | |
| (12) | ||
|
template
<
class
T
>
std::
complex
<
T
>
operator
/
(
const
T
&
lhs,
|
(bis C++20) | |
|
template
<
class
T
>
constexpr
std::
complex
<
T
>
operator
/
(
const
T
&
lhs,
|
(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.
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
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) |