Skip to content

Commit 30efc1c

Browse files
committed
Add referencing real/imag to complex
1 parent 504aa7c commit 30efc1c

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

cp-algo/util/complex.hpp

+5-1
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,18 @@ namespace cp_algo {
2727
T abs() const {return std::sqrt(norm());}
2828
T real() const {return x;}
2929
T imag() const {return y;}
30+
T& real() {return x;}
31+
T& imag() {return y;}
3032
static complex polar(T r, T theta) {return {r * cos(theta), r * sin(theta)};}
3133
auto operator <=> (complex const& t) const = default;
3234
};
3335
template<typename T>
34-
complex<T> operator * (auto x, complex<T> y) {return y * x;}
36+
complex<T> operator * (auto x, complex<T> y) {return y *= x;}
3537
template<typename T> complex<T> conj(complex<T> x) {return x.conj();}
3638
template<typename T> T norm(complex<T> x) {return x.norm();}
3739
template<typename T> T abs(complex<T> x) {return x.abs();}
40+
template<typename T> T& real(complex<T> &x) {return x.real();}
41+
template<typename T> T& imag(complex<T> &x) {return x.imag();}
3842
template<typename T> T real(complex<T> x) {return x.real();}
3943
template<typename T> T imag(complex<T> x) {return x.imag();}
4044
template<typename T> complex<T> polar(T r, T theta) {return complex<T>::polar(r, theta);}

0 commit comments

Comments
 (0)