1. ## complex numbers

I'm successfully using <complex.h> functionality, but I'm a little confused. I'm trying to keep everything in float instead of double and I was uncertain what "I" was, so just to be sure, I defined "If":

Code:
`complex float If;`
then,

Code:
`If=(float)I;`
After doing this and replacing all my I's with If's, nothing worked, all my answers were wrong. Why would that be?

Also, after switching from double to float, some things got incredibly slow, specifically:

Code:
`temp+=data[xx]*(cosf(phase[xx])+I*sinf(phase[xx]));`
This is really bogged down. I was using "cexpf" which was incredibly slow too, so I tried this just in case.

Any ideas?

2. Code:
`If=(float)I;`
umm... why?

> After doing this and replacing all my I's with If's, nothing worked, all my answers were wrong. Why would that be?

What were you trying to do?

> Also, after switching from double to float, some things got incredibly slow, specifically:

Code:
`temp+=data[xx]*(cosf(phase[xx])+I*sinf(phase[xx]));`
What was switched from double to float? What are all the other identifiers declared as?

3. I've not used C99 complex, but I would think it would have to be (complex float)I if anything. I'm pretty sure (float)I would end up being 0.

4. Duh! Thanks.

Anyone have thoughts on the slowness?

5. Yes. I think you're not using the right function for the types. So... what are the identifiers declared as?

6. Reading about complex.h I believe that I is just what it is in math, the imaginary number i. It says that it is actually a macro expanding to a const expression of type _Imaginary float and have a value of I.
To declare a complex number with float values you, lets say z, you declare float complex z.
Isn't this right? Haven't use it, just read the manual for complex.h.
So the If is a float complex number. The I is the imaginary number i (or j). So the
Code:
`If = (float)I`
makes no sense to me. The casting also makes no sense.

Now, I don't know what you changed here:
Code:
`temp+=data[xx]*(cosf(phase[xx])+I*sinf(phase[xx]));`
Do you actually mean If instead of I? If that is the case then correctly nothing works.

But if my understanding is correct, then:
1) temp should be declared as float complex
2) I should be as it is

Try actually declaring temp as double complex and then as float complex. Then check the size with sizeof(). If it is different then you know now that float complex is what you want, a complex number with float variables.

7. Yeah, I made a mistake and should have said:

Code:
`If=(complex float)I;`
I don't think this is necessary, but I just wanted to make sure I wasn't expanding to double.

The line of code was a different thought. It could be "I" or "If". Using "If" is probably not necessary. Either way, it's a bottleneck in my code and I'm trying to figure out why.

I'm actually using FFTW in my program, so my complex values are of type fftwf_complex:

Code:
```fftwf_complex *data, temp,*answer;
float *phase;

... //Big loop
temp+=data[xx]*(cosf(phase[xx])+I*sinf(phase[xx]));

...