diff options
author | xleroy <xleroy@fca1b0fc-160b-0410-b1d3-a4f43f01ea2e> | 2006-09-08 15:43:41 +0000 |
---|---|---|
committer | xleroy <xleroy@fca1b0fc-160b-0410-b1d3-a4f43f01ea2e> | 2006-09-08 15:43:41 +0000 |
commit | a5b33dcab2e6218e9e17f36a26520fd1dabc58bb (patch) | |
tree | 93f6b4595b7ba079ed3517b7bc07e50c3049adcf /test/c/fft.c | |
parent | 43b4d97a655e52e3962c0d14bda39dacb24af901 (diff) |
MAJ des tests C
git-svn-id: https://yquem.inria.fr/compcert/svn/compcert/trunk@86 fca1b0fc-160b-0410-b1d3-a4f43f01ea2e
Diffstat (limited to 'test/c/fft.c')
-rw-r--r-- | test/c/fft.c | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/test/c/fft.c b/test/c/fft.c index 9edf427..1ab7b15 100644 --- a/test/c/fft.c +++ b/test/c/fft.c @@ -4,6 +4,8 @@ */ #include <math.h> +#include <stdlib.h> +#include <stdio.h> #ifndef PI #define PI 3.14159265358979323846 @@ -139,4 +141,51 @@ int dfft(double x[], double y[], int np) return(n); } +/* Test harness */ +double * xr, * xi; + +int main(int argc, char ** argv) +{ + int n, np, npm, n2, i, j; + double enp, t, y, z, zr, zi, zm, a; + double * pxr, * pxi; + + if (argc >= 2) n = atoi(argv[1]); else n = 12; + np = 1 << n; + enp = np; + npm = np / 2 - 1; + t = PI / enp; + xr = calloc(np, sizeof(double)); + xi = calloc(np, sizeof(double)); + pxr = xr; + pxi = xi; + *pxr = (enp - 1.0) * 0.5; + *pxi = 0.0; + n2 = np / 2; + *(pxr+n2) = -0.5; + *(pxi+n2) = 0.0; + for (i = 1; i <= npm; i++) { + j = np - i; + *(pxr+i) = -0.5; + *(pxr+j) = -0.5; + z = t * (double)i; + y = -0.5*(cos(z)/sin(z)); + *(pxi+i) = y; + *(pxi+j) = -y; + } + dfft(xr,xi,np); + zr = 0.0; + zi = 0.0; + npm = np-1; + for (i = 0; i <= npm; i++ ) { + a = fabs(pxr[i] - i); + if (zr < a) zr = a; + a = fabs(pxi[i]); + if (zi < a) zi = a; + } + zm = zr; + if (zr < zi) zm = zi; + printf("%d points, error %g\n", np, zm); + return 0; +} |