00001 #ifndef __J2K__JComplex_CPP__
00002 #define __J2K__JComplex_CPP__
00003
00004 #include <j2k/Fred/Math/Complex.hpp>
00005
00006
00007
00008
00009 inline void JComplex::operator*=(const CplxDouble r) {
00010 Real = Real * r;
00011 Imag = Imag * r;
00012 }
00013
00014 inline void JComplex::operator/=(const CplxDouble r) {
00015 Real = Real / r;
00016 Imag = Imag / r;
00017 }
00018
00019
00020
00021
00022 JComplex& operator*=( JComplex& x, const JComplex& y ) {
00023
00024
00025
00026
00027 CplxNumber Temp_Re = (x.Real * y.Real) - (x.Imag * y.Imag);
00028 CplxNumber Temp_Im = (x.Imag * y.Real) + (x.Real * y.Imag);
00029
00030 x.Real = Temp_Re;
00031 x.Imag = Temp_Im;
00032
00033 return (x);
00034 }
00035
00036 JComplex& operator/=( JComplex& x, const JComplex& y ) {
00037
00038
00039
00040
00041
00042
00043
00044 CplxNumber Temp_delta = (y.Real * y.Real) + (y.Imag * y.Imag);
00045 CplxNumber Temp_Re = (x.Real * y.Real) + (x.Imag * y.Imag);
00046 CplxNumber Temp_Im = (x.Imag * y.Real) - (x.Real * y.Imag);
00047
00048 x.Real = Temp_Re / Temp_delta;
00049 x.Imag = Temp_Im / Temp_delta;
00050
00051 return (x);
00052 }
00053
00054 static void JComplex::operator*=(const JComplex& c) {
00055
00056 const CplxDouble tmpReal = (Real * c.Real) - (Imag * c.Imag);
00057 Imag = (Real * c.Imag) + (Imag * c.Real);
00058 Real = tmpReal;
00059 }
00060
00061 JComplex operator*(const JComplex& left, const JComplex& right) {
00062 return JComplex (
00063 (left.Real * right.Real) - (left.Imag * right.Imag),
00064 (left.Real * right.Imag) + (left.Imag * right.Real)
00065 );
00066 }
00067
00068 void JComplex::operator/=(const JComplex& c) {
00069 const CplxDouble Tmp1 = c.Real / c.Imag;
00070 const CplxDouble Tmp2 = c.Imag + (Tmp1 * c.Real);
00071
00072
00073 const CplxDouble TmpReal = (Real * Tmp1 + Imag) / Tmp2;
00074 Imag = (Imag * Tmp1 - Real) / Tmp2;
00075 Real = TmpReal;
00076 }
00077
00078 JComplex operator/(const JComplex& left, const JComplex& right) {
00079 const CplxDouble Tmp1 = right.Real / right.Imag;
00080 const CplxDouble Tmp2 = right.Imag + (Tmp1 * right.Real);
00081
00082 return JComplex(
00083 ( (left.Real * Tmp1 + left.Imag) / Tmp2 ),
00084 ( (left.Imag * Tmp1 - left.Real) / Tmp2 )
00085 );
00086 }
00087
00088
00089
00090
00091 CplxNumber Real(const CplxNumber& x) {
00092 return (Real = x);
00093 }
00094
00095 CplxNumber Imag(const CplxNumber& y) {
00096 return (Imag = y);
00097 }
00098
00099 CplxNumber Real() const {
00100 return (Real);
00101 }
00102
00103 CplxNumber Imag() const {
00104 return (Imag);
00105 }
00106
00107
00108 JComplex& operator=( const CplxNumber& x ) {
00109 Real = x;
00110 Imag = 0;
00111 return (*this);
00112 }
00113
00114 JComplex& operator=( const JComplex& c ) {
00115 Real = c.Real;
00116 Imag = c.Imag;
00117 return (*this);
00118 }
00119
00120 JComplex& operator+=(const CplxNumber& x ) {
00121 Real = Real + x;
00122 return (*this);
00123 }
00124
00125 JComplex& operator+=( JComplex& x, const JComplex& y ) {
00126 x.Real = x.Real + y.Real;
00127 x.Imag = y.Imag + y.Imag;
00128 return (x);
00129 }
00130
00131 JComplex& operator-=(const CplxNumber& x) {
00132 Real = Real - x;
00133 return (*this);
00134 }
00135
00136 JComplex& operator-=( JComplex& x, const JComplex& y ) {
00137 x.Real = x.Real - y.Real;
00138 x.Imag = y.Imag - y.Imag;
00139 return (x);
00140 }
00141
00142 JComplex& operator*=(const CplxNumber& x) {
00143 Real = Real * x;
00144 Imag = Imag * x;
00145 return (*this);
00146 }
00147
00148 JComplex& operator/=(const CplxNumber& x) {
00149 Real = Real / x;
00150 Imag = Imag / x;
00151 return (*this);
00152 }
00153
00154 protected:
00155 CplxNumber Real;
00156 CplxNumber Imag;
00157
00158 public:
00159
00160 static BOOL Compare( const JComplex& l, const JComplex& r ) {
00161 return ( (l.Real == r.Real) && (l.Imag == r.Imag) );
00162 }
00163
00164 inline friend BOOL operator==( const JComplex& l, const JComplex& r ) {
00165 return Compare( l, r );
00166 }
00167
00168 inline friend BOOL operator!=( const Number& l, const Number& r ) {
00169 return !Compare( l, r );
00170 }
00171
00172
00173
00174 JComplex& operator*=( JComplex& x, const JComplex& y ) {
00175
00176
00177
00178
00179 CplxNumber Temp_Re = (x.Real * y.Real) - (x.Imag * y.Imag);
00180 CplxNumber Temp_Im = (x.Imag * y.Real) + (x.Real * y.Imag);
00181
00182 x.Real = Temp_Re;
00183 x.Imag = Temp_Im;
00184
00185 return (x);
00186 }
00187
00188 JComplex& operator/=( JComplex& x, const JComplex& y ) {
00189
00190
00191
00192
00193
00194
00195
00196 CplxNumber Temp_delta = (y.Real * y.Real) + (y.Imag * y.Imag);
00197
00198 CplxNumber Temp_Re = (x.Real * y.Real) + (x.Imag * y.Imag);
00199 CplxNumber Temp_Im = (x.Imag * y.Real) - (x.Real * y.Imag);
00200
00201 x.Real = Temp_Re / Temp_delta;
00202 x.Imag = Temp_Im / Temp_delta;
00203
00204 return (x);
00205 }
00206
00207 static CplxNumber _Infv(CplxNumber) {
00208 return ( _Inf._D );
00209 }
00210
00211 static bool _Isinf(CplxNumber x) {
00212 double temp = (double)x;
00213 return (_Dtest(&temp) == _INFCODE);
00214 }
00215
00216 static bool _Isnan(CplxNumber x) {
00217 double temp = (double)x;
00218 return (_Dtest(&temp) == _NANCODE);
00219 }
00220
00221 static CplxNumber _Nanv(CplxNumber) {
00222 return (_Nan._D);
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
00249
00250
00251
00252
00253
00254
00255
00256
00257
00258
00259
00260
00261
00262
00263
00264
00265
00266
00267
00268
00269
00270
00271
00272
00273
00274
00275
00276
00277
00278
00279
00280
00281
00282
00283
00284
00285
00286
00287
00288
00289
00290
00291
00292
00293
00294
00295
00296
00297
00298
00299 #endif