From a53b33587e820b65e9c4463adef238a9304fd5e7 Mon Sep 17 00:00:00 2001 From: Ahmet Inan Date: Mon, 17 Apr 2023 10:36:04 +0200 Subject: [PATCH] added some more operators --- complex.hh | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/complex.hh b/complex.hh index 50905f8..6127144 100644 --- a/complex.hh +++ b/complex.hh @@ -53,6 +53,18 @@ public: } }; +template +static constexpr bool operator == (Complex a, Complex b) +{ + return a.real() == b.real() && a.imag() == b.imag(); +} + +template +static constexpr bool operator != (Complex a, Complex b) +{ + return a.real() != b.real() || a.imag() != b.imag(); +} + template static constexpr Complex operator + (Complex a, Complex b) { @@ -95,6 +107,13 @@ static constexpr Complex operator * (Complex a, Complex b) return Complex(a.real() * b.real() - a.imag() * b.imag(), a.real() * b.imag() + a.imag() * b.real()); } +template +static constexpr Complex operator / (T a, Complex b) +{ + return Complex((a * b.real()) / (b.real() * b.real() + b.imag() * b.imag()), + - (a * b.imag()) / (b.real() * b.real() + b.imag() * b.imag())); +} + template static constexpr Complex operator / (Complex a, Complex b) {