Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   Related Pages  

FComplex.hpp

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;              // real
00031 float           b;              // imaginar
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 // math complex op
00054 // FComplex sqrt();
00055 // FComplex pow(double pow);
00056 FComplex sqr(){ FComplex x(a*a-b*b, 2.0*a*b); *this=x; }
00057 // FComplex exp();
00058 // FComplex log();
00059 // FComplex log(double base);
00060 
00061 // FComplex sin();
00062 // FComplex cos();
00063 // FComplex tan();
00064 
00065 // real operations
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 // complex operations
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 // friends
00078 friend FComplex operator+(const FComplex& v, float a);                  // v<op>a
00079 friend FComplex operator+(float a, const FComplex& v);                  // a<op>v
00080 friend FComplex operator-(const FComplex& v, float a);                  // v<op>a
00081 friend FComplex operator-(float a, const FComplex& v);                  // a<op>v
00082 friend FComplex operator*( const FComplex& v, float a);                 // v<op>a
00083 friend FComplex operator*(float a,const  FComplex& v);                  // a<op>v
00084 friend FComplex operator/(const  FComplex& v, float a);                 // v<op>a
00085 
00086 friend FComplex operator+(const FComplex& v1, const FComplex& v2);                      // v1<op>v2
00087 friend FComplex operator-(const FComplex& v1, const FComplex& v2);                      // v1<op>v2
00088 friend FComplex operator*(const FComplex& v1, const FComplex& v2);                      // v1<op>v2
00089 friend FComplex operator/(const FComplex& v1, const FComplex& v2);                      // v1<op>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  
SourceForge.net Logo
Restoreinpaint sourceforge project `C++/Java Image Processing, Restoration, Inpainting Project'.

Bernard De Cuyper: Open Project Leader: Concept, design and development.
Bernard De Cuyper & Eddy Fraiha 2002, 2003. Bernard De Cuyper 2004. Open and free, for friendly usage only.
Modifications on Belgium ground of this piece of artistic work, by governement institutions or companies, must be notified to Bernard De Cuyper.
bern_bdc@hotmail.com