root / synthbench / euroben-ports / base / C / mod2f / check.c @ 0:839f52ef7657
History | View | Annotate | Download (1.9 kB)
1 |
#include <stdio.h> |
---|---|
2 |
#include <math.h> |
3 |
|
4 |
int check( double a[], double b[], int n, double err ) |
5 |
//----------------------------------------------------------------------
|
6 |
//--- 'check' checks the errors made in the transformation of a
|
7 |
// complex-to-complex FFT. 'check' is specific for the input
|
8 |
// of this program.
|
9 |
// The Real part is a full cycle of a cosine signal and the
|
10 |
// Imaginary part is 0.0 everywhere.
|
11 |
// The resulting transform should show values of N/2 for
|
12 |
// A[0] and A[N-1]. All other entries should be 0.0.
|
13 |
// This is checked below with a Floating-Point error
|
14 |
// margin of ERR = ( 10.0*N Log N )*EPS, with EPS the
|
15 |
// Floating-Point spacing of the machine tested.
|
16 |
//--- The Real part of A is stored in A[0], ..., A[N-1];
|
17 |
// The Imaginary part in B[0], ..., B[N-1].
|
18 |
//----------------------------------------------------------------------
|
19 |
{ |
20 |
int i, ok = 0; |
21 |
//----------------------------------------------------------------------
|
22 |
if ( a[0] > err ) { |
23 |
printf( "First Real element, n = %8d%8d %13.5g%13.5g\n", n, 0, |
24 |
a[0], err );
|
25 |
return( ok++ );
|
26 |
} |
27 |
else return ( ok ); |
28 |
for( i = 3; i < n - 1; i++ ) { |
29 |
if ( a[i-1] > err ) { |
30 |
printf( "Real element, n = %8d%8d %13.5g%13.5g\n", n, i-1, |
31 |
a[i-1], err );
|
32 |
return( ok++ );
|
33 |
} |
34 |
} |
35 |
if ( fabs( a[1] - (double)(n/2) ) > err ) { |
36 |
printf( "Second Real element, n = %8d%8d %13.5g%13.5g\n", n, 2, |
37 |
a[1], (double)(n/2) ); |
38 |
return( ok++ );
|
39 |
} |
40 |
else return ( ok ); |
41 |
if ( fabs( a[n-1] - (double)(n/2) ) > err ) { |
42 |
printf( "N-th Real element, n = %8d%8d %13.5g%13.5g\n", n, n,
|
43 |
a[n-1], (double)(n/2) ); |
44 |
return( ok++ );
|
45 |
} |
46 |
else return ( ok ); |
47 |
for( i = 0; i < n-1; i++ ) { |
48 |
if ( b[i] > err ) {
|
49 |
printf( "Imaginary element, n = %8d%8d %13.5g%13.5g\n", n, i,
|
50 |
b[i], err ); |
51 |
return( ok++ );
|
52 |
} |
53 |
} |
54 |
} |