new set of cppcheck fixes
This commit is contained in:
@@ -27,18 +27,13 @@
|
||||
|
||||
unsigned int *generate_gauss_LUT(unsigned char Nbits,
|
||||
unsigned char L
|
||||
)
|
||||
{
|
||||
|
||||
) {
|
||||
unsigned int *LUT_ptr,i;
|
||||
|
||||
LUT_ptr = (unsigned int *)malloc((1<<(Nbits-1))*sizeof(int));
|
||||
assert(LUT_ptr);
|
||||
|
||||
|
||||
for (i=0; i<(1<<(Nbits-1)); i++) {
|
||||
LUT_ptr[i] = (unsigned int)((double)((unsigned int)(1<<31))*erf(i*L/(double)(1<<(Nbits-1))));
|
||||
|
||||
#ifdef LUTDEBUG
|
||||
printf("pos %d : LUT_ptr[%d]=%x (%f)\n",i,i,LUT_ptr[i],(double)(erf(i*L/(double)(1<<(Nbits-1)))));
|
||||
#endif //LUTDEBUG
|
||||
@@ -51,35 +46,24 @@ unsigned int *generate_gauss_LUT(unsigned char Nbits,
|
||||
|
||||
int gauss(unsigned int *gauss_LUT,
|
||||
unsigned char Nbits
|
||||
)
|
||||
{
|
||||
|
||||
) {
|
||||
unsigned int search_pos,step_size,u,tmp,tmpm1,tmpp1,s;
|
||||
|
||||
// Get a 32-bit uniform random-variable
|
||||
u = taus();
|
||||
|
||||
#ifdef DEBUG
|
||||
printf("u = %u\n",u);
|
||||
#endif //DEBUG
|
||||
|
||||
// if it is larger than 2^31 (here negative), save the sign and rescale down to 31-bits.
|
||||
|
||||
s = u & 0x80000000;
|
||||
u &= 0x7fffffff;
|
||||
|
||||
|
||||
#ifdef DEBUG
|
||||
printf("u = %x,s=%d\n",u,s);
|
||||
#endif //DEBUG
|
||||
|
||||
search_pos = (1<<(Nbits-2)); // starting position of the binary search
|
||||
step_size = search_pos;
|
||||
|
||||
do {
|
||||
|
||||
step_size >>= 1;
|
||||
|
||||
tmp = gauss_LUT[search_pos];
|
||||
tmpm1 = gauss_LUT[search_pos-1];
|
||||
tmpp1 = gauss_LUT[search_pos+1];
|
||||
@@ -96,12 +80,10 @@ int gauss(unsigned int *gauss_LUT,
|
||||
return s==0 ? search_pos : - search_pos;
|
||||
else
|
||||
search_pos += step_size;
|
||||
|
||||
} while (step_size > 0);
|
||||
|
||||
// If it gets here we're beyond the positive edge so return max
|
||||
return s==0 ? (1<<(Nbits-1))-1 : 1-((1<<(Nbits-1)));
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -109,9 +91,7 @@ int gauss(unsigned int *gauss_LUT,
|
||||
|
||||
#define Nhistbits 8
|
||||
|
||||
void main(int argc,char **argv)
|
||||
{
|
||||
|
||||
void main(int argc,char **argv) {
|
||||
unsigned int *gauss_LUT_ptr,i;
|
||||
unsigned int hist[(1<<Nhistbits)];
|
||||
int gvar,maxg=0,ming=9999999,maxnum=0,L,Ntrials,Nbits;
|
||||
@@ -125,7 +105,6 @@ void main(int argc,char **argv)
|
||||
Nbits = atoi(argv[1]);
|
||||
L = atoi(argv[2]);
|
||||
Ntrials = atoi(argv[3]);
|
||||
|
||||
set_taus_seed();
|
||||
// Generate Gaussian LUT 12-bit quantization over 5 standard deviations
|
||||
gauss_LUT_ptr = generate_gauss_LUT(Nbits,L);
|
||||
@@ -134,7 +113,6 @@ void main(int argc,char **argv)
|
||||
hist[i] = 0;
|
||||
|
||||
for (i=0; i<Ntrials; i++) {
|
||||
|
||||
gvar = gauss(gauss_LUT_ptr,Nbits);
|
||||
|
||||
if (gvar == ((1<<(Nbits-1))-1))
|
||||
@@ -151,10 +129,8 @@ void main(int argc,char **argv)
|
||||
|
||||
printf("Tail probability = %e(%x)\n",2*erfc((double)L*gauss_LUT_ptr[(1<<(Nbits-1))-1]/(unsigned int)(1<<31)),gauss_LUT_ptr[(1<<(Nbits-1))-1]);
|
||||
printf("max %d, min %d, mean %f, stddev %f, Pr(maxnum)=%e(%d)\n",maxg,ming,meang,sqrt(varg),(double)maxnum/Ntrials,maxnum);
|
||||
|
||||
// for (i=0;i<(1<<Nhistbits);i++)
|
||||
// printf("%d : %u\n",i,hist[i]);
|
||||
|
||||
free(gauss_LUT_ptr);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user