花了一上午写的复数模板,支持的功能还是很多的2333
template<class T>
class complex
{
private:
T r,i;
public:
complex(const T& x=0,const T& y=0):r(x),i(y){}
T& real()const{return r;}
T& imag()const{return i;}
static T abs(const complex& x){return sqrt(x.r*x.r+x.i*x.i);}
static T arg(const complex& x){return atan2(x.i,x.r);}
static complex polar(const T& _r,const T& Theta){return complex(_r*cos(Theta),_r*sin(Theta));}
complex conj()const{return complex(r,-i);}
complex operator+=(const T& b){r+=b;return *this;}
complex operator+=(const complex& b){r+=b.r;i+=b.i;return *this;}
template<class U>
complex operator+(const U& b)const
{
complex c=*this;
c+=b;
return c;
}
friend complex operator+(const T& a,const complex& b){return b+a;}
complex operator-=(const T& b){r-=b;return *this;}
complex operator-=(const complex& b){r-=b.r;i-=b.i;return *this;}
template<class U>
complex operator-(const U& b)const
{
complex c=*this;
c-=b;
return c;
}
friend complex operator-(const T& a,const complex& b){return complex(a)-b;}
complex operator*=(const T& b){r*=b,i*=b;return *this;}
complex operator*=(const complex& b){complex c=*this;r=b.r*c.r-b.i*c.i;i=b.r*c.i+b.i*c.r;return *this;}
template<class U>
complex operator*(const U& b)const
{
complex c=*this;
c*=b;
return c;
}
friend complex operator*(const T& a,const complex& b){return b*a;}
complex operator/=(const T& b){r/=b,i/=b;return *this;}
complex operator/=(const complex& b){complex c=b.conj();*this/=(b*c).r;*this*=c;return *this;}
template<class U>
complex operator/(const U& b)const
{
complex c=*this;
c/=b;
return c;
}
friend complex operator/(const T& a,const complex& b){return complex(a)/b;}
};