getting different output when using FFTW3 Library than using Rosetta FFT I have the following array containing sine waveform that I want to compute FFT:
{ 0.0, 0.114124, 0.370557, 0.0, -0.576201, -0.370557, 0.0, 0.0 };

When using FFTW3 Library and running those 2 functions:
plan_forward = fftw_plan_dft_r2c_1d ( N, in, out, FFTW_ESTIMATE );
fftw_execute ( plan_forward );

I get the following output:
-0.462077
0.918921 
-0.946758
0.233480
0.050790
0.000000
0.000000
0.000000

When using Rosetta implementation to FFT I get the following output:
-0.462077
0.918921
-0.946758
0.233480
0.050790
0.233480
-0.946758
0.918921

As you can see, some of the output is simillar between the 2s and some are different, I can't figure out why.
Here is my full code:
#include &lt;stdlib.h&gt;
#include &lt;stdio.h&gt;
#include &lt;time.h&gt;
#include &lt;fftw3.h&gt;
#include &lt;iostream&gt;
#include &lt;cmath&gt;
#include &lt;fstream&gt;
#include &lt;complex&gt;
#include &lt;iostream&gt;
#include &lt;valarray&gt;
using namespace std;

const double PI = 3.141592653589793238460;
 
typedef std::complex&lt;double&gt; Complex;
typedef std::valarray&lt;Complex&gt; CArray;
 
// Cooley–Tukey FFT (in-place, divide-and-conquer)
// Higher memory requirements and redundancy although more intuitive
void fft(CArray&amp; x)
{
    const size_t N = x.size();
    if (N &lt;= 1) return;
 
    // divide
    CArray even = x[std::slice(0, N/2, 2)];
    CArray  odd = x[std::slice(1, N/2, 2)];
 
    // conquer
    fft(even);
    fft(odd);
 
    // combine
    for (size_t k = 0; k &lt; N/2; ++k)
    {
        Complex t = std::polar(1.0, -2 * PI * k / N) * odd[k];
        x[k    ] = even[k] + t;
        x[k+N/2] = even[k] - t;
    }
}

int main(void)
{
    int i;
    double y;
    int N=8;
    double Fs=30000;//sampling frequency
    double  T=1/Fs;//sample time 
    double f=5000;//frequency
    double *in;
    fftw_complex *out;
    double t[N-1];//time vector 
    fftw_plan plan_forward;

    in = (double*) fftw_malloc(sizeof(double) * N);
    out = (fftw_complex*) fftw_malloc(sizeof(fftw_complex) * N);
    for (int i=0; i&lt; N;i++)
    {
        t[i]=i*T;
        in[i] =0.7 *sin(2*M_PI*f*t[i]);// generate sine waveform
        double multiplier = 0.5 * (1 - cos(2*M_PI*i/(N-1)));//Hanning Window
        in[i] = multiplier * in[i];
    }

    Complex test[] = { 0.0, 0.114124, 0.370557, 0.0, -0.576201, -0.370557, 0.0, 0.0 };
    //const Complex test[] = (Complex*)malloc(sizeof(Complex) * N);
    //CArray data(test, 8);


    printf ( &quot;\n&quot; );
    printf ( &quot;  Input Data:\n&quot; );
    printf ( &quot;\n&quot; );

    for ( i = 0; i &lt; N; i++ )
    {
        printf ( &quot;  %4d  %12f\n&quot;, i, in[i] );
        test[i].real(in[i]);
    }
    CArray data(test, 8);

    fft(data);
    plan_forward = fftw_plan_dft_r2c_1d ( N, in, out, FFTW_ESTIMATE );
    fftw_execute ( plan_forward );

    printf ( &quot;  output Data from FFTW3 Library:             output Data from my FFT implementation\n&quot; );
    for ( i = 0; i &lt; N; i++ )
    {
        printf ( &quot;  %4d  %12f           %12f\n&quot;, i, *out[i], data[i].real());
    }
    return 0;
}
If the input is real valued than the output of the FFT is conjugate symmetric (Hermitian Symmetry). That means that the data in the second half of the output is redundant and the FFTW implementations takes advantage of that fact and only returns a complex vector of length $N/2+1$, i.e. 5 in your case. The Rosetta implementation just runs a standard complex FFT.
I suggest reading the documentation: http://www.fftw.org/fftw3_doc/One_002dDimensional-DFTs-of-Real-Data.html
Please note that your output is complex but you are only printing the real part.