00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #ifndef FXCOMPLEXD_H
00024 #define FXCOMPLEXD_H
00025
00026
00027 namespace FX {
00028
00029
00030
00031 class FXAPI FXComplexd {
00032 public:
00033 FXdouble re;
00034 FXdouble im;
00035 public:
00036
00037
00038 FXComplexd(){ }
00039
00040
00041 FXComplexd(FXdouble r):re(r),im(0.0){ }
00042
00043
00044 FXComplexd(FXdouble r,FXdouble i):re(r),im(i){ }
00045
00046
00047 FXComplexd(const FXComplexd& c):re(c.re),im(c.im){ }
00048
00049
00050 FXComplexd& set(FXdouble r){ re=r; im=0.0; return *this; }
00051
00052
00053 FXComplexd& set(FXdouble r,FXdouble i){ re=r; im=i; return *this;}
00054
00055
00056 FXComplexd& set(const FXComplexd& c){ re=c.re; im=c.im; return *this;}
00057
00058
00059 operator FXbool() const { return (re!=0.0) || (im!=0.0); }
00060
00061
00062 FXbool operator!() const { return (re==0.0) && (im==0.0); }
00063
00064
00065 FXdouble modulus2() const { return re*re+im*im; }
00066
00067
00068 FXdouble modulus() const { return sqrt(modulus2()); }
00069
00070
00071 FXdouble argument() const { return atan2(im,re); }
00072
00073
00074 FXdouble& operator[](FXint i){ return (&re)[i]; }
00075
00076
00077 const FXdouble& operator[](FXint i) const { return (&re)[i]; }
00078
00079
00080 FXComplexd operator+() const { return *this; }
00081 FXComplexd operator-() const { return FXComplexd(-re,-im); }
00082
00083
00084 FXComplexd& operator=(const FXdouble r){ return set(r); }
00085
00086
00087 FXComplexd& operator=(const FXComplexd& c){ return set(c); }
00088
00089
00090 FXComplexd& operator+=(FXdouble r){ re+=r; return *this; }
00091 FXComplexd& operator-=(FXdouble r){ re-=r; return *this; }
00092 FXComplexd& operator*=(FXdouble r){ re*=r; im*=r; return *this; }
00093 FXComplexd& operator/=(FXdouble r){ re/=r; im/=r; return *this; }
00094
00095
00096 FXComplexd& operator+=(const FXComplexd& c){ return set(re+c.re,im+c.im); }
00097 FXComplexd& operator-=(const FXComplexd& c){ return set(re-c.re,im-c.im); }
00098 FXComplexd& operator*=(const FXComplexd& c){ return set(re*c.re-im*c.im,re*c.im+im*c.re); }
00099 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); }
00100
00101
00102 FXbool operator==(const FXComplexd& c) const { return re==c.re && im==c.im; }
00103 FXbool operator!=(const FXComplexd& c) const { return re!=c.re || im!=c.im; }
00104
00105
00106 friend inline FXComplexd conjugate(const FXComplexd& c);
00107
00108
00109 friend inline FXComplexd polar(FXdouble mod,FXdouble arg);
00110
00111
00112 friend inline FXComplexd exponent(const FXComplexd& c);
00113
00114
00115 friend inline FXComplexd logarithm(const FXComplexd& c);
00116
00117
00118 friend inline FXbool operator==(const FXComplexd& c,FXdouble r);
00119 friend inline FXbool operator!=(const FXComplexd& c,FXdouble r);
00120
00121
00122 friend inline FXbool operator==(FXdouble r,const FXComplexd& c);
00123 friend inline FXbool operator!=(FXdouble r,const FXComplexd& c);
00124
00125
00126 friend inline FXComplexd operator+(const FXComplexd& a,const FXComplexd& b);
00127 friend inline FXComplexd operator-(const FXComplexd& a,const FXComplexd& b);
00128 friend inline FXComplexd operator*(const FXComplexd& a,const FXComplexd& b);
00129 friend inline FXComplexd operator/(const FXComplexd& a,const FXComplexd& b);
00130
00131
00132 friend inline FXComplexd operator+(const FXComplexd& a,FXdouble b);
00133 friend inline FXComplexd operator-(const FXComplexd& a,FXdouble b);
00134 friend inline FXComplexd operator*(const FXComplexd& a,FXdouble b);
00135 friend inline FXComplexd operator/(const FXComplexd& a,FXdouble b);
00136
00137
00138 friend inline FXComplexd operator+(FXdouble a,const FXComplexd& b);
00139 friend inline FXComplexd operator-(FXdouble a,const FXComplexd& b);
00140 friend inline FXComplexd operator*(FXdouble a,const FXComplexd& b);
00141 friend inline FXComplexd operator/(FXdouble a,const FXComplexd& b);
00142
00143
00144 friend FXAPI FXStream& operator<<(FXStream& store,const FXComplexd& c);
00145
00146
00147 friend FXAPI FXStream& operator>>(FXStream& store,FXComplexd& c);
00148 };
00149
00150
00151
00152 inline FXComplexd conjugate(const FXComplexd& c){ return FXComplexd(c.re,-c.im); }
00153 inline FXComplexd polar(FXdouble mod,FXdouble arg){ return FXComplexd(cos(arg)*mod,sin(arg)*mod); }
00154 inline FXComplexd exponent(const FXComplexd& c){ return polar(exp(c.re),c.im); }
00155 inline FXComplexd logarithm(const FXComplexd& c){ return FXComplexd(log(c.modulus()),c.argument()); }
00156
00157 inline FXbool operator==(const FXComplexd& c,FXdouble r){ return c.re==r && c.im==0.0; }
00158 inline FXbool operator!=(const FXComplexd& c,FXdouble r){ return c.re!=r || c.im!=0.0; }
00159
00160 inline FXbool operator==(FXdouble r,const FXComplexd& c){ return r==c.re && c.im==0.0; }
00161 inline FXbool operator!=(FXdouble r,const FXComplexd& c){ return r!=c.re || c.im!=0.0; }
00162
00163
00164 inline FXComplexd operator+(const FXComplexd& a,const FXComplexd& b){ return FXComplexd(a.re+b.re,a.im+b.im); }
00165 inline FXComplexd operator-(const FXComplexd& a,const FXComplexd& b){ return FXComplexd(a.re-b.re,a.im-b.im); }
00166 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); }
00167 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); }
00168
00169
00170 inline FXComplexd operator+(const FXComplexd& a,FXdouble b){ return FXComplexd(a.re+b,a.im); }
00171 inline FXComplexd operator-(const FXComplexd& a,FXdouble b){ return FXComplexd(a.re-b,a.im); }
00172 inline FXComplexd operator*(const FXComplexd& a,FXdouble b){ return FXComplexd(a.re*b,a.im*b); }
00173 inline FXComplexd operator/(const FXComplexd& a,FXdouble b){ return FXComplexd(a.re/b,a.im/b); }
00174
00175
00176 inline FXComplexd operator+(FXdouble a,const FXComplexd& b){ return FXComplexd(a+b.re,b.im); }
00177 inline FXComplexd operator-(FXdouble a,const FXComplexd& b){ return FXComplexd(a-b.re,b.im); }
00178 inline FXComplexd operator*(FXdouble a,const FXComplexd& b){ return FXComplexd(a*b.re,a*b.im); }
00179 inline FXComplexd operator/(FXdouble a,const FXComplexd& b){ FXdouble m=b.modulus2(); return FXComplexd((a*b.re)/m,(-a*b.im)/m); }
00180
00181 extern FXAPI FXStream& operator<<(FXStream& store,const FXComplexd& c);
00182 extern FXAPI FXStream& operator>>(FXStream& store,FXComplexd& c);
00183
00184 }
00185
00186 #endif