forked from daniestevez/libfec
-
Notifications
You must be signed in to change notification settings - Fork 3
/
sqtest.c
42 lines (33 loc) · 883 Bytes
/
sqtest.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
/* Verify correctness of the sum-of-square routines */
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
/* These values should trigger leading/trailing array fragment handling */
#define NSAMP 200002
#define OFFSET 1
long long sumsq_wq(signed short *in,int cnt);
long long sumsq_wq_ref(signed short *in,int cnt);
int main(){
int i;
long long result,rresult;
signed short samples[NSAMP];
srandom(time(NULL));
for(i=0;i<NSAMP;i++)
samples[i] = random() & 0xffff;
rresult = sumsq_wq(&samples[OFFSET],NSAMP-OFFSET);
result = sumsq_wq(&samples[OFFSET],NSAMP-OFFSET);
if(result == rresult){
printf("OK\n");
} else {
printf("sum mismatch: %lld != %lld\n",result,rresult);
}
exit(0);
}
long long sumsq_wq_ref(signed short *in,int cnt){
long long sum = 0;
int i;
for(i=0;i<cnt;i++){
sum += (long)in[i] * in[i];
}
return sum;
}