Skip to content

Commit

Permalink
Add referencing real/imag to complex
Browse files Browse the repository at this point in the history
  • Loading branch information
adamant-pwn committed Nov 21, 2024
1 parent 504aa7c commit 30efc1c
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion cp-algo/util/complex.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,18 @@ namespace cp_algo {
T abs() const {return std::sqrt(norm());}
T real() const {return x;}
T imag() const {return y;}
T& real() {return x;}
T& imag() {return y;}
static complex polar(T r, T theta) {return {r * cos(theta), r * sin(theta)};}
auto operator <=> (complex const& t) const = default;
};
template<typename T>
complex<T> operator * (auto x, complex<T> y) {return y * x;}
complex<T> operator * (auto x, complex<T> y) {return y *= x;}
template<typename T> complex<T> conj(complex<T> x) {return x.conj();}
template<typename T> T norm(complex<T> x) {return x.norm();}
template<typename T> T abs(complex<T> x) {return x.abs();}
template<typename T> T& real(complex<T> &x) {return x.real();}
template<typename T> T& imag(complex<T> &x) {return x.imag();}
template<typename T> T real(complex<T> x) {return x.real();}
template<typename T> T imag(complex<T> x) {return x.imag();}
template<typename T> complex<T> polar(T r, T theta) {return complex<T>::polar(r, theta);}
Expand Down

0 comments on commit 30efc1c

Please sign in to comment.