00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #ifndef FXCOMPLEXD_H
00022 #define FXCOMPLEXD_H
00023
00024
00025 namespace FX {
00026
00027
00029 class FXAPI FXComplexd {
00030 public:
00031 FXdouble re;
00032 FXdouble im;
00033 public:
00034
00036 FXComplexd(){ }
00037
00039 FXComplexd(FXdouble r):re(r),im(0.0){ }
00040
00042 FXComplexd(FXdouble r,FXdouble i):re(r),im(i){ }
00043
00045 FXComplexd(const FXComplexd& c):re(c.re),im(c.im){ }
00046
00048 FXComplexd& set(FXdouble r){ re=r; im=0.0; return *this; }
00049
00051 FXComplexd& set(FXdouble r,FXdouble i){ re=r; im=i; return *this;}
00052
00054 FXComplexd& set(const FXComplexd& c){ re=c.re; im=c.im; return *this;}
00055
00057 FXbool operator!() const { return (re==0.0) && (im==0.0); }
00058
00060 FXdouble modulus2() const { return re*re+im*im; }
00061
00063 FXdouble modulus() const { return sqrt(modulus2()); }
00064
00066 FXdouble argument() const { return atan2(im,re); }
00067
00069 FXdouble& operator[](FXint i){ return (&re)[i]; }
00070
00072 const FXdouble& operator[](FXint i) const { return (&re)[i]; }
00073
00075 FXComplexd operator+() const { return *this; }
00076 FXComplexd operator-() const { return FXComplexd(-re,-im); }
00077
00079 FXComplexd& operator=(const FXdouble r){ return set(r); }
00080
00082 FXComplexd& operator=(const FXComplexd& c){ return set(c); }
00083
00085 FXComplexd& operator+=(FXdouble r){ re+=r; return *this; }
00086 FXComplexd& operator-=(FXdouble r){ re-=r; return *this; }
00087 FXComplexd& operator*=(FXdouble r){ re*=r; im*=r; return *this; }
00088 FXComplexd& operator/=(FXdouble r){ re/=r; im/=r; return *this; }
00089
00091 FXComplexd& operator+=(const FXComplexd& c){ return set(re+c.re,im+c.im); }
00092 FXComplexd& operator-=(const FXComplexd& c){ return set(re-c.re,im-c.im); }
00093 FXComplexd& operator*=(const FXComplexd& c){ return set(re*c.re-im*c.im,re*c.im+im*c.re); }
00094 FXComplexd& operator/=(const FXComplexd& c){ FXdouble m=c.modulus2(); return set((re*c.re+im*c.im)/m,(im*c.re-re*c.im)/m); }
00095
00097 ~FXComplexd(){}
00098 };
00099
00100
00102 inline FXComplexd conjugate(const FXComplexd& c){ return FXComplexd(c.re,-c.im); }
00103
00105 inline FXComplexd polar(FXdouble mod,FXdouble arg){ return FXComplexd(cos(arg)*mod,sin(arg)*mod); }
00106
00108 inline FXComplexd exponent(const FXComplexd& c){ return polar(exp(c.re),c.im); }
00109
00111 inline FXComplexd logarithm(const FXComplexd& c){ return FXComplexd(log(c.modulus()),c.argument()); }
00112
00113
00115 inline FXbool operator==(const FXComplexd& c,FXdouble r){ return c.re==r && c.im==0.0; }
00116 inline FXbool operator!=(const FXComplexd& c,FXdouble r){ return c.re!=r || c.im!=0.0; }
00117
00119 inline FXbool operator==(FXdouble r,const FXComplexd& c){ return r==c.re && c.im==0.0; }
00120 inline FXbool operator!=(FXdouble r,const FXComplexd& c){ return r!=c.re || c.im!=0.0; }
00121
00123 inline FXbool operator==(const FXComplexd& a,const FXComplexd& b){ return a.re==b.re && a.im==b.im; }
00124 inline FXbool operator!=(const FXComplexd& a,const FXComplexd& b){ return a.re!=b.re || a.im!=b.im; }
00125
00127 inline FXComplexd operator+(const FXComplexd& a,FXdouble b){ return FXComplexd(a.re+b,a.im); }
00128 inline FXComplexd operator-(const FXComplexd& a,FXdouble b){ return FXComplexd(a.re-b,a.im); }
00129 inline FXComplexd operator*(const FXComplexd& a,FXdouble b){ return FXComplexd(a.re*b,a.im*b); }
00130 inline FXComplexd operator/(const FXComplexd& a,FXdouble b){ return FXComplexd(a.re/b,a.im/b); }
00131
00133 inline FXComplexd operator+(FXdouble a,const FXComplexd& b){ return FXComplexd(a+b.re,b.im); }
00134 inline FXComplexd operator-(FXdouble a,const FXComplexd& b){ return FXComplexd(a-b.re,-b.im); }
00135 inline FXComplexd operator*(FXdouble a,const FXComplexd& b){ return FXComplexd(a*b.re,a*b.im); }
00136 inline FXComplexd operator/(FXdouble a,const FXComplexd& b){ FXdouble m=b.modulus2(); return FXComplexd((a*b.re)/m,(-a*b.im)/m); }
00137
00139 inline FXComplexd operator+(const FXComplexd& a,const FXComplexd& b){ return FXComplexd(a.re+b.re,a.im+b.im); }
00140 inline FXComplexd operator-(const FXComplexd& a,const FXComplexd& b){ return FXComplexd(a.re-b.re,a.im-b.im); }
00141 inline FXComplexd operator*(const FXComplexd& a,const FXComplexd& b){ return FXComplexd(a.re*b.re-a.im*b.im,a.re*b.im+a.im*b.re); }
00142 inline FXComplexd operator/(const FXComplexd& a,const FXComplexd& b){ FXdouble m=b.modulus2(); return FXComplexd((a.re*b.re+a.im*b.im)/m,(a.im*b.re-a.re*b.im)/m); }
00143
00145 extern FXAPI FXStream& operator<<(FXStream& store,const FXComplexd& c);
00146
00148 extern FXAPI FXStream& operator>>(FXStream& store,FXComplexd& c);
00149
00150 }
00151
00152 #endif