diff options
author | Søren Sandmann Pedersen <ssp@redhat.com> | 2011-08-01 20:08:14 -0400 |
---|---|---|
committer | Søren Sandmann Pedersen <ssp@redhat.com> | 2011-08-01 20:08:14 -0400 |
commit | 6073c155a3caf6feac4b19851777b53c70185e3f (patch) | |
tree | 7556bd4133e478985aedfe41204998ceef723b71 | |
parent | 7a71a49b5a5787bc13e75be1b6074a207aacd860 (diff) |
Move complex numbers to their own header
-rw-r--r-- | complex.h | 67 | ||||
-rw-r--r-- | fft.h | 62 |
2 files changed, 68 insertions, 61 deletions
diff --git a/complex.h b/complex.h new file mode 100644 index 0000000..0dcde9c --- /dev/null +++ b/complex.h @@ -0,0 +1,67 @@ +#ifndef COMPLEX_H + +#include <math.h> + +typedef struct +{ + double re; + double im; +} complex_t; + +static inline complex_t +complex_mul (complex_t a, complex_t b) +{ + complex_t r; + + r.re = a.re * b.re - a.im * b.im; + r.im = a.re * b.im + a.im * b.re; + + return r; +} + +static inline complex_t +complex_add (complex_t a, complex_t b) +{ + complex_t r; + + r.re = a.re + b.re; + r.im = a.im + b.im; + + return r; +} + +static inline complex_t +complex_sub (complex_t a, complex_t b) +{ + complex_t r; + + r.re = a.re - b.re; + r.im = a.im - b.im; + + return r; +} + +static inline double +complex_mag (complex_t a) +{ + return sqrt (a.re * a.re + a.im * a.im); +} + +static inline double +complex_arg (complex_t a) +{ + return fmod (atan2 (a.im, a.re) + 2 * M_PI, 2 * M_PI); +} + +static inline complex_t +complex_from_mag_arg (double mag, double arg) +{ + complex_t r; + + r.re = mag * cos (arg); + r.im = mag * sin (arg); + + return r; +} + +#endif @@ -1,4 +1,5 @@ #include <math.h> +#include "complex.h" #ifndef FALSE #define FALSE (0) @@ -8,67 +9,6 @@ #define TRUE (1) #endif -typedef struct -{ - double re; - double im; -} complex_t; - -static inline complex_t -complex_mul (complex_t a, complex_t b) -{ - complex_t r; - - r.re = a.re * b.re - a.im * b.im; - r.im = a.re * b.im + a.im * b.re; - - return r; -} - -static inline complex_t -complex_add (complex_t a, complex_t b) -{ - complex_t r; - - r.re = a.re + b.re; - r.im = a.im + b.im; - - return r; -} - -static inline complex_t -complex_sub (complex_t a, complex_t b) -{ - complex_t r; - - r.re = a.re - b.re; - r.im = a.im - b.im; - - return r; -} - -static inline double -complex_mag (complex_t a) -{ - return sqrt (a.re * a.re + a.im * a.im); -} -static inline double -complex_arg (complex_t a) -{ - return fmod (atan2 (a.im, a.re) + 2 * M_PI, 2 * M_PI); -} - -static inline complex_t -complex_from_mag_arg (double mag, double arg) -{ - complex_t r; - - r.re = mag * cos (arg); - r.im = mag * sin (arg); - - return r; -} - static inline double rad_to_degree (double theta) { |