00001 #ifndef __J2K__JCOMPLEX_HH__
00002 #define __J2K__JCOMPLEX_HH__
00003
00004
00005
00006
00007
00008
00009
00010 // This part is derived from the Complex STL template for double type. //
00011
00012
00013
00014
00015 typedef double CplxNumber;
00016
00017 class JComplex {
00018 public:
00019
00020
00021
00022
00023 inline JComplex()
00024 : Real( 0 ), Imag( 0 ) { }
00025
00026 inline JComplex( const CplxNumber& Re )
00027 : Real( Re ), Imag( 0 ) { }
00028
00029 inline JComplex( const CplxNumber& Re, const CplxNumber& Im )
00030 : Real( Re ), Imag( Im ) { }
00031
00032 inline JComplex( const JComplex& c )
00033 : Real( c.Real ), Imag( c.Imag ) { }
00034
00035 inline virtual ~JComplex() { }
00036
00037
00038
00039
00040 CplxNumber Real(const CplxNumber& x) {
00041 return (Real = x);
00042 }
00043
00044 CplxNumber Imag(const CplxNumber& y) {
00045 return (Imag = y);
00046 }
00047
00048 CplxNumber Real() const {
00049 return (Real);
00050 }
00051
00052 CplxNumber Imag() const {
00053 return (Imag);
00054 }
00055
00056
00057 JComplex& operator=( const CplxNumber& x ) {
00058 Real = x;
00059 Imag = 0;
00060 return (*this);
00061 }
00062
00063 JComplex& operator=( const JComplex& c ) {
00064 Real = c.Real;
00065 Imag = c.Imag;
00066 return (*this);
00067 }
00068
00069 JComplex& operator+=(const CplxNumber& x ) {
00070 Real = Real + x;
00071 return (*this);
00072 }
00073
00074 JComplex& operator+=( JComplex& x, const JComplex& y ) {
00075 x.Real = x.Real + y.Real;
00076 x.Imag = y.Imag + y.Imag;
00077 return (x);
00078 }
00079
00080 JComplex& operator-=(const CplxNumber& x) {
00081 Real = Real - x;
00082 return (*this);
00083 }
00084
00085 JComplex& operator-=( JComplex& x, const JComplex& y ) {
00086 x.Real = x.Real - y.Real;
00087 x.Imag = y.Imag - y.Imag;
00088 return (x);
00089 }
00090
00091 JComplex& operator*=(const CplxNumber& x) {
00092 Real = Real * x;
00093 Imag = Imag * x;
00094 return (*this);
00095 }
00096
00097 JComplex& operator/=(const CplxNumber& x) {
00098 Real = Real / x;
00099 Imag = Imag / x;
00100 return (*this);
00101 }
00102
00103 protected:
00104 CplxNumber Real;
00105 CplxNumber Imag;
00106
00107 public:
00108
00109 static BOOL Compare( const JComplex& l, const JComplex& r ) {
00110 return ( (l.Real == r.Real) && (l.Imag == r.Imag) );
00111 }
00112
00113 inline friend BOOL operator==( const JComplex& l, const JComplex& r ) {
00114 return Compare( l, r );
00115 }
00116
00117 inline friend BOOL operator!=( const Number& l, const Number& r ) {
00118 return !Compare( l, r );
00119 }
00120
00121
00122
00123 JComplex& operator*=( JComplex& x, const JComplex& y ) {
00124
00125
00126
00127
00128 CplxNumber Temp_Re = (x.Real * y.Real) - (x.Imag * y.Imag);
00129 CplxNumber Temp_Im = (x.Imag * y.Real) + (x.Real * y.Imag);
00130
00131 x.Real = Temp_Re;
00132 x.Imag = Temp_Im;
00133
00134 return (x);
00135 }
00136
00137 JComplex& operator/=( JComplex& x, const JComplex& y ) {
00138
00139
00140
00141
00142
00143
00144
00145 CplxNumber Temp_delta = (y.Real * y.Real) + (y.Imag * y.Imag);
00146
00147 CplxNumber Temp_Re = (x.Real * y.Real) + (x.Imag * y.Imag);
00148 CplxNumber Temp_Im = (x.Imag * y.Real) - (x.Real * y.Imag);
00149
00150 x.Real = Temp_Re / Temp_delta;
00151 x.Imag = Temp_Im / Temp_delta;
00152
00153 return (x);
00154 }
00155
00156 static CplxNumber _Infv(CplxNumber) {
00157 return ( _Inf._D );
00158 }
00159
00160 static bool _Isinf(CplxNumber x) {
00161 double temp = (double)x;
00162 return (_Dtest(&temp) == _INFCODE);
00163 }
00164
00165 static bool _Isnan(CplxNumber x) {
00166 double temp = (double)x;
00167 return (_Dtest(&temp) == _NANCODE);
00168 }
00169
00170 static CplxNumber _Nanv(CplxNumber) {
00171 return (_Nan._D);
00172 }
00173
00174
00175
00176
00177
00178
00179
00180
00181
00182
00183
00184
00185
00186
00187
00188
00189
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199
00200
00201
00202
00203
00204
00205
00206
00207
00208
00209
00210
00211
00212
00213
00214
00215
00216
00217
00218
00219
00220
00221
00222
00223
00224
00225
00226
00227
00228
00229
00230
00231
00232
00233
00234
00235
00236
00237
00238
00239
00240
00241
00242
00243
00244
00245
00246
00247
00248 #endif