C complex number usage
Bruce Labitt
bruce.labitt at verizon.net
Sun Jan 6 12:25:58 EST 2008
Hopefully a simple question. I'm trying to write a C program that uses
complex numbers. (I'm a "C" illiterate. Just wrote my second
program...) Reading the header file complex.h hasn't helped too much.
Can someone give me a hint on how to "fix" this? Most of the references
on C are *ancient* (like me) and don't cover the C99 complex number
stuff. Please ignore my awful coding style.
#include <math.h>
#include <time.h>
#include <complex>
#include <fftw3.h>
double gaussrand();
int N; /* length of FFT */
int ii; /* index */
N = 1024;
double _Complex g[N];
double mymean, mystdev;
double _Complex I;
// assign mymean and mystdev here...
// Create array of complex random numbers
for (ii=0; ii<N; ii++)
{
g[ii] = mymean*(1+I) + mystdev*gaussrand() + I * mystdev *
gaussrand();
}
// End complex random number generation
The compiler barfs on the g[ii] assignment...
41 C:\Dev-Cpp\myproj\main_tb_fftw.cpp cannot convert `double
__complex__[((unsigned int)((int)N))]' to `double (*)[2]' in assignment
Hopefully someone can point me in the write direction. TIA.
More information about the gnhlug-discuss
mailing list