00001 #ifndef __FComplex_H__
00002 #define __FComplex_H__
00003
00004
00023 #include <stdio.h>
00024 #include <math.h>
00025
00026 class FComplex
00027 {
00028 public:
00029
00030 float a;
00031 float b;
00032
00033 public:
00034
00035 FComplex(){ a=0.0; b=0.0; }
00036 FComplex(float real, float img=0.0){ a=real; b=img; }
00037 FComplex(float root, float theta, int sign){ a=root*cos(sign*theta); b=root*sin(sign*theta); }
00038 FComplex(const FComplex& x){ a=x.a; b=x.b; }
00039 FComplex& operator=(const FComplex& x){ a=x.a; b=x.b; return *this; }
00040
00041 ~FComplex(){}
00042
00043 inline float getReal(){return a;}
00044 inline float getImg(){return b;}
00045
00046 double getRoot(){ return sqrt( a*a + b*b ); }
00047 double getAbs(){ return sqrt( a*a + b*b ); }
00048 double getArg();
00049
00050 inline FComplex conjugate(){ return FComplex(a, -b); }
00051
00052
00053
00054
00055
00056 FComplex sqr(){ FComplex x(a*a-b*b, 2.0*a*b); *this=x; }
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066 void operator+=(float value){ a += value; }
00067 void operator-=(float value){ a -= value; }
00068 void operator*=(float value){ a *= value; b *= value; }
00069 void operator/=(float value){ a /= value; b /= value; }
00070
00071
00072 void operator+=(const FComplex& v){ a += v.a; b += v.b; }
00073 void operator-=(const FComplex& v){ a -= v.a; b -= v.b; }
00074 void operator*=(const FComplex& v){ FComplex x(a*v.a-b*v.b, a*v.b + b*v.a); *this=x; }
00075 void operator/=(const FComplex& v){ FComplex x(a*v.a+b*v.b, a*v.b - b*v.a); x/=(v.a*v.a+v.b*v.b); *this=x; }
00076
00077
00078 friend FComplex operator+(const FComplex& v, float a);
00079 friend FComplex operator+(float a, const FComplex& v);
00080 friend FComplex operator-(const FComplex& v, float a);
00081 friend FComplex operator-(float a, const FComplex& v);
00082 friend FComplex operator*( const FComplex& v, float a);
00083 friend FComplex operator*(float a,const FComplex& v);
00084 friend FComplex operator/(const FComplex& v, float a);
00085
00086 friend FComplex operator+(const FComplex& v1, const FComplex& v2);
00087 friend FComplex operator-(const FComplex& v1, const FComplex& v2);
00088 friend FComplex operator*(const FComplex& v1, const FComplex& v2);
00089 friend FComplex operator/(const FComplex& v1, const FComplex& v2);
00090
00091 void output(){printf("(%f, i*%f)", a, b);}
00092 void output(FILE* file){fprintf(file, "(%f, i*%f)", a, b);}
00093 };
00094
00095 #endif
00096
00097