Chris@42: Chris@42: Chris@42: Chris@42: Chris@42: Chris@42: FFTW 3.3.5: Complex numbers Chris@42: Chris@42: Chris@42: Chris@42: Chris@42: Chris@42: Chris@42: Chris@42: Chris@42: Chris@42: Chris@42: Chris@42: Chris@42: Chris@42: Chris@42: Chris@42: Chris@42: Chris@42: Chris@42: Chris@42: Chris@42:
Chris@42:

Chris@42: Next: , Previous: , Up: Data Types and Files   [Contents][Index]

Chris@42:
Chris@42:
Chris@42: Chris@42:

4.1.1 Complex numbers

Chris@42: Chris@42:

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

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

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

Chris@42:

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

Chris@42: Chris@42:

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

Chris@42: Chris@42: Chris@42: Chris@42: Chris@42: