#ifndef _Threads_complex_h_ #define _Threads_complex_h_ #include template class Complex_ { public: T Re(void) const { return re; } void SetRe(T value ) { re = value; } T Im(void) const { return im; } void SetIm(T value ) { im = value; } explicit Complex_ (void) : re(0), im(0) {} explicit Complex_ (T re) : re(re), im(0) {} Complex_ (T re, T im) : re(re), im(im) {} Complex_ operator + (const Complex_ & other) const { return Complex_(re + other.re, im + other.im ); } Complex_ operator - (const Complex_ & other) const { return Complex_(re - other.re, im - other.im ); } Complex_ operator * (const Complex_ & other) const { return Complex_(re * other.re - im * other.im, re * other.im + im * other.re ); } T Abs2() const { return re*re+im*im; } private: T re; T im; }; typedef Complex_ Complex; String ToString(const Complex & c); template Complex_ operator + (const Complex_ & a, U b) { return Complex_(a.Re() + b, a.Im() ); } template Complex_ operator + (U b, const Complex_ & a) { return Complex_(a.Re() + b, a.Im() ); } template Complex_ operator - (const Complex_ & a, U b) { return Complex_(a.Re() - b, a.Im() ); } template Complex_ operator - (U b, const Complex_ & a) { return Complex_(a.Re() - b, a.Im() ); } template Complex_ operator * (const Complex_ & a, U b) { return Complex_(a.Re() * b, a.Im() * b ); } template Complex_ operator * (U b, const Complex_ & a) { return Complex_(a.Re() * b, a.Im() * b ); } #endif