\File{complex\-gcc.h},{00:02},{Dec 28 1997}
\L{\LB{\C{}\/* \$Id: complex\-gcc.h,v 1.9 1997\/12\/28 05:02:54 bert Exp \$}}
\L{\LB{ *}}
\L{\LB{ * making complex numbers work with GCC}}
\L{\LB{ *\/\CE{}}}
\L{\LB{}}
\L{\LB{\K{\#ifndef} \_COMPLEX\_GCC\_H}}
\L{\LB{\K{\#define} \_COMPLEX\_GCC\_H}}
\L{\LB{}}
\L{\LB{\K{\#include} \<math.h\>}}
\L{\LB{}}
\L{\LB{\C{}\/* (1) TYPE DECLARATIONS}}
\L{\LB{ * Declare a \"complex\" type that supports +,\-,*,\/ and a matching \"real\" type.}}
\L{\LB{ * Define Re(z) and Im(z) that return real and imaginary parts of z.}}
\L{\LB{ * Also define LFMT to be whatever prefix printf requires before e\/f\/g when}}
\L{\LB{ * using the real type.}}
\L{\LB{ *}}
\L{\LB{ * Unfortunately, gcc won\'t let us say things like \"\_\_complex\_\_ FFTW\_REAL\";}}
\L{\LB{ * we must use a base type.}}
\L{\LB{ *\/\CE{}}}
\L{\LB{}}
\L{\LB{\C{}\/* GNU C (gcc) supports complex numbers; any numeric type TYPE}}
\L{\LB{ * (including integers!) may be prefixed by \_\_complex\_\_, in which case}}
\L{\LB{ * a pair of TYPEs is used using standard arithmetic rules for complex}}
\L{\LB{ * numbers.  We could use either float, double, or long double here.}}
\L{\LB{ *\/\CE{}}}
\L{\LB{}}
\L{\LB{\K{typedef}   \K{double}                  \K{real};}}
\L{\LB{\K{typedef}   \K{\_\_complex\_\_} \K{double}      \K{complex};}}
\L{\LB{\K{\#define} LFMT}}
\L{\LB{\K{\#define} Re(z)    (\K{\_\_real\_\_} (z))}}
\L{\LB{\K{\#define} Im(z)    (\K{\_\_imag\_\_} (z))}}
\L{\LB{\K{\#define} conj(z)  (\~(z))}}
\L{\LB{\K{\#define} I        (1i)}}
\L{\LB{}}
\L{\LB{\C{}\/* (2) PROTOTYPES for complex\-gcc.c *\/\CE{}}}
\L{\LB{}}
\L{\LB{\C{}\/* Normally, most helper \"functions\" for complex numbers will be defined as}}
\L{\LB{ * macros.  However, for debugging or profiling it is sometimes desirable to}}
\L{\LB{ * use real function calls instead.}}
\L{\LB{ *\/\CE{}}}
\L{\LB{\K{complex} \_Cexp(\K{complex});}}
\L{\LB{\K{real}    \_Cabs(\K{complex});}}
\L{\LB{\K{real}    \_Csqabs(\K{complex});}}
\L{\LB{\K{real}    \_Carg(\K{complex});}}
\L{\LB{\K{complex} \_Csqrt(\K{complex});}}
\L{\LB{}}
\L{\LB{\C{}\/* (3) MACROS ETC *\/\CE{}}}
\L{\LB{}}
\L{\LB{\K{\#ifdef} COMPLEX\_NO\_MACROS}}
\L{\LB{}}
\L{\LB{\C{}\/* Use functions only... *\/\CE{}}}
\L{\LB{\K{\#define} Cexp(z)       \_Cexp(z)}}
\L{\LB{\K{\#define} Cabs(z)       \_Cabs(z)}}
\L{\LB{\K{\#define} Csqabs(z)     \_Csqabs(z)}}
\L{\LB{\K{\#define} Carg(z)       \_Carg(z)}}
\L{\LB{\K{\#define} Csqrt(z)      \_Csqrt(z)}}
\L{\LB{}}
\L{\LB{\K{\#else} \C{}\/* not COMPLEX\_NO\_MACROS *\/\CE{}}}
\L{\LB{}}
\L{\LB{\C{}\/* Macros are OK... *\/\CE{}}}
\L{\LB{\C{}\/* exponential of a complex number *\/\CE{}}}
\L{\LB{\K{\#define} Cexp(z)       (exp(Re(z)) * (cos(Im(z)) + 1i*sin(Im(z))))}}
\L{\LB{\C{}\/* (real) absolute value of a complex number *\/\CE{}}}
\L{\LB{\K{\#define} Cabs(z)       (sqrt( (Re(z)*Re(z)) + (Im(z)*Im(z)) ))}}
\L{\LB{\C{}\/* square of (real) absolute value of a complex number *\/\CE{}}}
\L{\LB{\K{\#define} Csqabs(z)     (      (Re(z)*Re(z)) + (Im(z)*Im(z))  )}}
\L{\LB{\C{}\/* argument (ie, \"angle\") of a complex number *\/\CE{}}}
\L{\LB{\K{\#define} Carg(z)       (atan2(Im(z), Re(z)))}}
\L{\LB{\C{}\/* calling a rarely used function from complex.c isn\'t prohibited *\/\CE{}}}
\L{\LB{\K{\#define} Csqrt(z)      \_Csqrt(z)}}
\L{\LB{}}
\L{\LB{\K{\#endif} \C{}\/* COMPLEX\_NO\_MACROS *\/\CE{}}}
\L{\LB{}}
\L{\LB{\K{\#endif} \C{}\/* \_COMPLEX\_GCC\_H *\/\CE{}}}
