00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038 #if !defined(_SPANDSP_COMPLEX_H_)
00039 #define _SPANDSP_COMPLEX_H_
00040
00041
00042
00043
00044 typedef struct
00045 {
00046 float re;
00047 float im;
00048 } complexf_t;
00049
00050
00051
00052
00053 typedef struct
00054 {
00055 double re;
00056 double im;
00057 } complex_t;
00058
00059 #if defined(HAVE_LONG_DOUBLE)
00060
00061
00062
00063 typedef struct
00064 {
00065 long double re;
00066 long double im;
00067 } complexl_t;
00068 #endif
00069
00070
00071
00072
00073 typedef struct
00074 {
00075 int re;
00076 int im;
00077 } complexi_t;
00078
00079
00080
00081
00082 typedef struct
00083 {
00084 int16_t re;
00085 int16_t im;
00086 } complexi16_t;
00087
00088
00089
00090
00091 typedef struct
00092 {
00093 int32_t re;
00094 int32_t im;
00095 } complexi32_t;
00096
00097 #if defined(__cplusplus)
00098 extern "C"
00099 {
00100 #endif
00101
00102 static __inline__ complexf_t complex_setf(float re, float im)
00103 {
00104 complexf_t z;
00105
00106 z.re = re;
00107 z.im = im;
00108 return z;
00109 }
00110
00111
00112 static __inline__ complex_t complex_set(float re, float im)
00113 {
00114 complex_t z;
00115
00116 z.re = re;
00117 z.im = im;
00118 return z;
00119 }
00120
00121
00122 #if defined(HAVE_LONG_DOUBLE)
00123 static __inline__ complexl_t complex_setl(long double re, long double im)
00124 {
00125 complexl_t z;
00126
00127 z.re = re;
00128 z.im = im;
00129 return z;
00130 }
00131
00132 #endif
00133
00134 static __inline__ complexi_t complex_seti(int re, int im)
00135 {
00136 complexi_t z;
00137
00138 z.re = re;
00139 z.im = im;
00140 return z;
00141 }
00142
00143
00144 static __inline__ complexi16_t complex_seti16(int16_t re, int16_t im)
00145 {
00146 complexi16_t z;
00147
00148 z.re = re;
00149 z.im = im;
00150 return z;
00151 }
00152
00153
00154 static __inline__ complexi32_t complex_seti32(int32_t re, int32_t im)
00155 {
00156 complexi32_t z;
00157
00158 z.re = re;
00159 z.im = im;
00160 return z;
00161 }
00162
00163
00164 static __inline__ complexf_t complex_addf(const complexf_t *x, const complexf_t *y)
00165 {
00166 complexf_t z;
00167
00168 z.re = x->re + y->re;
00169 z.im = x->im + y->im;
00170 return z;
00171 }
00172
00173
00174 static __inline__ complex_t complex_add(const complex_t *x, const complex_t *y)
00175 {
00176 complex_t z;
00177
00178 z.re = x->re + y->re;
00179 z.im = x->im + y->im;
00180 return z;
00181 }
00182
00183
00184 #if defined(HAVE_LONG_DOUBLE)
00185 static __inline__ complexl_t complex_addl(const complexl_t *x, const complexl_t *y)
00186 {
00187 complexl_t z;
00188
00189 z.re = x->re + y->re;
00190 z.im = x->im + y->im;
00191 return z;
00192 }
00193
00194 #endif
00195
00196 static __inline__ complexi_t complex_addi(const complexi_t *x, const complexi_t *y)
00197 {
00198 complexi_t z;
00199
00200 z.re = x->re + y->re;
00201 z.im = x->im + y->im;
00202 return z;
00203 }
00204
00205
00206 static __inline__ complexi16_t complex_addi16(const complexi16_t *x, const complexi16_t *y)
00207 {
00208 complexi16_t z;
00209
00210 z.re = x->re + y->re;
00211 z.im = x->im + y->im;
00212 return z;
00213 }
00214
00215
00216 static __inline__ complexi32_t complex_addi32(const complexi32_t *x, const complexi32_t *y)
00217 {
00218 complexi32_t z;
00219
00220 z.re = x->re + y->re;
00221 z.im = x->im + y->im;
00222 return z;
00223 }
00224
00225
00226 static __inline__ complexf_t complex_subf(const complexf_t *x, const complexf_t *y)
00227 {
00228 complexf_t z;
00229
00230 z.re = x->re - y->re;
00231 z.im = x->im - y->im;
00232 return z;
00233 }
00234
00235
00236 static __inline__ complex_t complex_sub(const complex_t *x, const complex_t *y)
00237 {
00238 complex_t z;
00239
00240 z.re = x->re - y->re;
00241 z.im = x->im - y->im;
00242 return z;
00243 }
00244
00245
00246 #if defined(HAVE_LONG_DOUBLE)
00247 static __inline__ complexl_t complex_subl(const complexl_t *x, const complexl_t *y)
00248 {
00249 complexl_t z;
00250
00251 z.re = x->re - y->re;
00252 z.im = x->im - y->im;
00253 return z;
00254 }
00255
00256 #endif
00257
00258 static __inline__ complexi_t complex_subi(const complexi_t *x, const complexi_t *y)
00259 {
00260 complexi_t z;
00261
00262 z.re = x->re - y->re;
00263 z.im = x->im - y->im;
00264 return z;
00265 }
00266
00267
00268 static __inline__ complexi16_t complex_subi16(const complexi16_t *x, const complexi16_t *y)
00269 {
00270 complexi16_t z;
00271
00272 z.re = x->re - y->re;
00273 z.im = x->im - y->im;
00274 return z;
00275 }
00276
00277
00278 static __inline__ complexi32_t complex_subi32(const complexi32_t *x, const complexi32_t *y)
00279 {
00280 complexi32_t z;
00281
00282 z.re = x->re - y->re;
00283 z.im = x->im - y->im;
00284 return z;
00285 }
00286
00287
00288 static __inline__ complexf_t complex_mulf(const complexf_t *x, const complexf_t *y)
00289 {
00290 complexf_t z;
00291
00292 z.re = x->re*y->re - x->im*y->im;
00293 z.im = x->re*y->im + x->im*y->re;
00294 return z;
00295 }
00296
00297
00298 static __inline__ complex_t complex_mul(const complex_t *x, const complex_t *y)
00299 {
00300 complex_t z;
00301
00302 z.re = x->re*y->re - x->im*y->im;
00303 z.im = x->re*y->im + x->im*y->re;
00304 return z;
00305 }
00306
00307
00308 #if defined(HAVE_LONG_DOUBLE)
00309 static __inline__ complexl_t complex_mull(const complexl_t *x, const complexl_t *y)
00310 {
00311 complexl_t z;
00312
00313 z.re = x->re*y->re - x->im*y->im;
00314 z.im = x->re*y->im + x->im*y->re;
00315 return z;
00316 }
00317
00318 #endif
00319
00320 static __inline__ complexf_t complex_divf(const complexf_t *x, const complexf_t *y)
00321 {
00322 complexf_t z;
00323 float f;
00324
00325 f = y->re*y->re + y->im*y->im;
00326 z.re = ( x->re*y->re + x->im*y->im)/f;
00327 z.im = (-x->re*y->im + x->im*y->re)/f;
00328 return z;
00329 }
00330
00331
00332 static __inline__ complex_t complex_div(const complex_t *x, const complex_t *y)
00333 {
00334 complex_t z;
00335 double f;
00336
00337 f = y->re*y->re + y->im*y->im;
00338 z.re = ( x->re*y->re + x->im*y->im)/f;
00339 z.im = (-x->re*y->im + x->im*y->re)/f;
00340 return z;
00341 }
00342
00343
00344 #if defined(HAVE_LONG_DOUBLE)
00345 static __inline__ complexl_t complex_divl(const complexl_t *x, const complexl_t *y)
00346 {
00347 complexl_t z;
00348 long double f;
00349
00350 f = y->re*y->re + y->im*y->im;
00351 z.re = ( x->re*y->re + x->im*y->im)/f;
00352 z.im = (-x->re*y->im + x->im*y->re)/f;
00353 return z;
00354 }
00355
00356 #endif
00357
00358 static __inline__ complexf_t complex_conjf(const complexf_t *x)
00359 {
00360 complexf_t z;
00361
00362 z.re = x->re;
00363 z.im = -x->im;
00364 return z;
00365 }
00366
00367
00368 static __inline__ complex_t complex_conj(const complex_t *x)
00369 {
00370 complex_t z;
00371
00372 z.re = x->re;
00373 z.im = -x->im;
00374 return z;
00375 }
00376
00377
00378 #if defined(HAVE_LONG_DOUBLE)
00379 static __inline__ complexl_t complex_conjl(const complexl_t *x)
00380 {
00381 complexl_t z;
00382
00383 z.re = x->re;
00384 z.im = -x->im;
00385 return z;
00386 }
00387
00388 #endif
00389
00390 static __inline__ complexi_t complexi_conj(const complexi_t *x)
00391 {
00392 complexi_t z;
00393
00394 z.re = x->re;
00395 z.im = -x->im;
00396 return z;
00397 }
00398
00399
00400 static __inline__ float powerf(const complexf_t *x)
00401 {
00402 return x->re*x->re + x->im*x->im;
00403 }
00404
00405
00406 static __inline__ double power(const complex_t *x)
00407 {
00408 return x->re*x->re + x->im*x->im;
00409 }
00410
00411
00412 #if defined(HAVE_LONG_DOUBLE)
00413 static __inline__ long double powerl(const complexl_t *x)
00414 {
00415 return x->re*x->re + x->im*x->im;
00416 }
00417
00418 #endif
00419
00420 #if defined(__cplusplus)
00421 }
00422 #endif
00423
00424 #endif
00425