added some more operators

This commit is contained in:
Ahmet Inan 2023-04-17 10:36:04 +02:00
commit a53b33587e

View file

@ -53,6 +53,18 @@ public:
} }
}; };
template <typename T>
static constexpr bool operator == (Complex<T> a, Complex<T> b)
{
return a.real() == b.real() && a.imag() == b.imag();
}
template <typename T>
static constexpr bool operator != (Complex<T> a, Complex<T> b)
{
return a.real() != b.real() || a.imag() != b.imag();
}
template <typename T> template <typename T>
static constexpr Complex<T> operator + (Complex<T> a, Complex<T> b) static constexpr Complex<T> operator + (Complex<T> a, Complex<T> b)
{ {
@ -95,6 +107,13 @@ static constexpr Complex<T> operator * (Complex<T> a, Complex<T> b)
return Complex<T>(a.real() * b.real() - a.imag() * b.imag(), a.real() * b.imag() + a.imag() * b.real()); return Complex<T>(a.real() * b.real() - a.imag() * b.imag(), a.real() * b.imag() + a.imag() * b.real());
} }
template <typename T>
static constexpr Complex<T> operator / (T a, Complex<T> b)
{
return Complex<T>((a * b.real()) / (b.real() * b.real() + b.imag() * b.imag()),
- (a * b.imag()) / (b.real() * b.real() + b.imag() * b.imag()));
}
template <typename T> template <typename T>
static constexpr Complex<T> operator / (Complex<T> a, Complex<T> b) static constexpr Complex<T> operator / (Complex<T> a, Complex<T> b)
{ {