Gideon
unread,May 8, 2012, 12:27:30 PM5/8/12You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to
The following bit of code uses the complex data type to construct 5 complex numbers of the form
e^{i PI * j/4}
with j = 0, 1, 2, 3,4.
It then stores them in a double array, with the real components in 0-4, and the imaginary components in 5-9. When I compile and run the code with O2 flags, I get what I'd expect:
1 + i 0
0.707107 + i 0.707107
6.12303e-17 + i 1
-0.707107 + i 0.707107
-1 + i 1.22461e-16
But when I compile and run with O3 or Ofast flag, I get:
1 + i 0
0.707107 + i 0.707107
6.12323e-17 + i 1
-0.707107 + i 0.707107
-1 + i -0.00400571
It is this last entry that's troubling. I am using gcc 4.6.3, which I obtained through macports. I use the GSL library, but only to get the constant PI. What I'm trying to understand is:
1. Is this just the price I pay for further optimization, or is it a bug?
2. Can anyone suggest what optimization flag associated with O3 and Ofast that's causing this?
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<complex.h>
#include <gsl/gsl_math.h>
#define N 5
int main(int argc,char *argv[]){
double y[2*N];
double complex b;
int i;
for (i=0;i<N;i++){
b = cexp(_Complex_I * .25 * M_PI * i);
y[i] = creal(b);
y[i+N] = cimag(b);
printf(" y[%i] = %g + i %g \n",i, y[i], y[i+N]);
}
return 0;
}