Chris@19: Chris@19: Chris@19: Complex numbers - FFTW 3.3.4 Chris@19: Chris@19: Chris@19: Chris@19: Chris@19: Chris@19: Chris@19: Chris@19: Chris@19: Chris@19: Chris@19: Chris@19: Chris@19: Chris@19:
Chris@19: Chris@19:

Chris@19: Next: , Chris@19: Previous: Data Types and Files, Chris@19: Up: Data Types and Files Chris@19:


Chris@19:
Chris@19: Chris@19:

4.1.1 Complex numbers

Chris@19: Chris@19:

The default FFTW interface uses double precision for all Chris@19: floating-point numbers, and defines a fftw_complex type to hold Chris@19: complex numbers as: Chris@19: Chris@19:

     typedef double fftw_complex[2];
Chris@19: 
Chris@19:

Chris@19: Here, the [0] element holds the real part and the [1] Chris@19: element holds the imaginary part. Chris@19: Chris@19:

Alternatively, if you have a C compiler (such as gcc) that Chris@19: supports the C99 revision of the ANSI C standard, you can use C's new Chris@19: native complex type (which is binary-compatible with the typedef above). Chris@19: In particular, if you #include <complex.h> before Chris@19: <fftw3.h>, then fftw_complex is defined to be the native Chris@19: complex type and you can manipulate it with ordinary arithmetic Chris@19: (e.g. x = y * (3+4*I), where x and y are Chris@19: fftw_complex and I is the standard symbol for the Chris@19: imaginary unit); Chris@19: Chris@19: Chris@19:

C++ has its own complex<T> template class, defined in the Chris@19: standard <complex> header file. Reportedly, the C++ standards Chris@19: committee has recently agreed to mandate that the storage format used Chris@19: for this type be binary-compatible with the C99 type, i.e. an array Chris@19: T[2] with consecutive real [0] and imaginary [1] Chris@19: parts. (See report Chris@19: http://www.open-std.org/jtc1/sc22/WG21/docs/papers/2002/n1388.pdf WG21/N1388.) Although not part of the official standard as of this Chris@19: writing, the proposal stated that: “This solution has been tested with Chris@19: all current major implementations of the standard library and shown to Chris@19: be working.” To the extent that this is true, if you have a variable Chris@19: complex<double> *x, you can pass it directly to FFTW via Chris@19: reinterpret_cast<fftw_complex*>(x). Chris@19: Chris@19: Chris@19: Chris@19: Chris@19: