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