title: Rounding errors giving incorrect tesults in DFT?
body: <p>I have been beating my head against the wall on this DFT. It should print out: 8,0,0,0,0,0,0,0 but instead I get 8 and then very very tiny numbers. Are these rounding errors? Is there anything I can do? My Radix2 FFT gives correct results, it seems silly a DFT could not also work.</p>
  
  <p>I started with complex numbers so I know there is a good bit missing, I tried to strip it down to illustrate the problem.</p>
  
  <pre><code>#include &lt;cstdlib&gt;
  #include &lt;math.h&gt;
  #include &lt;iostream&gt;
  #include &lt;complex&gt;
  #include &lt;cassert&gt;
  
  #define SIZE 8
  #define M_PI 3.14159265358979323846
  
  void fft(const double src[], double dst[], const unsigned int n) 
  {
      for(int i=0; i &lt; SIZE; i++)
      {
          const double ph = -(2*M_PI) / n;
          const int gid = i;
  
          double res = 0.0f;
          for (int k = 0; k &lt; n; k++) {
  
              double t = src[k];
  
              const double val = ph * k * gid;
              double cs = cos(val);
              double sn = sin(val);
  
              res += ((t * cs) - (t * sn));
              int a = 1;
          }
  
          dst[i] = res;
          std::cout &lt;&lt; dst[i] &lt;&lt; std::endl;
      }
  }
  
  int main(void)
  {
      double array1[SIZE];
      double array2[SIZE];
  
      for(int i=0; i &lt; SIZE; i++){
          array1[i] = 1;
          array2[i] = 0;
      }
  
      fft(array1, array2, SIZE);
  
      return 666;
  }
  </code></pre>