C++ <complex> - operator== Function
The C++ <complex> operator== function is used to compare two complex numbers or a complex and a scalar. Scalar arguments are treated as complex numbers with the real part equal to the argument and the imaginary part set to zero. It returns true if values are equal, else returns false.
Syntax
bool operator== (const complex<T>& lhs, const complex<T>& rhs); bool operator== (const complex<T>& lhs, const T& val); bool operator== (const T& val, const complex<T>& rhs);
Parameters
lhs |
Specify left-hand side complex value. |
rhs |
Specify right-hand side complex value. |
val |
Specify scalar value. |
Return Value
Returns true if values are equal, else returns false.
Example:
The example below shows the usage of operator== function.
#include <iostream> #include <complex> using namespace std; int main (){ complex<int> z1 (3,4); complex<int> z2 (4,3); complex<int> z3 (3,4); cout<<boolalpha; //comparing z1 with 5 cout<<"z1 == 5 returns: "<<(z1 == 5)<<"\n"; //comparing z1 with z2 cout<<"z1 == z2 returns: "<<(z1 == z2)<<"\n"; //comparing z1 with z3 cout<<"z1 == z3 returns: "<<(z1 == z3)<<"\n"; return 0; }
The output of the above code will be:
z1 == 5 returns: false z1 == z2 returns: false z1 == z3 returns: true
❮ C++ <complex> Library