K
kilgore
Hi all,
I have encountered a perplexing expression evaluation. In the code
below, the output of the 'ref' printf statement is
3.501 and the output of the 'comp' printf statement is 0.034. I do not
understand where the factor of 100 is coming from. Any help
appreciated.
Thanks!
#include <stdio.h>
typedef unsigned short word;
int main ( int argc, char ** argv)
{
float s; /* span value */
float z; /* zero value */
float u;
float d1;
float out1;
float out2;
word gain;
word bc;
u = 2765;
bc = 4096;
s = 20;
z = -10;
gain = 1;
printf("u = %f\n",u);
printf("s = %f\n",s);
printf("z = %f\n",z);
printf("s = %f\n",s);
d1 = (float) bc * s + z; // why is this NOT the same as the middle
term in the 'out1' expression below?
printf("d1 = %f\n",d1);
out1 = (u/(float)bc * s + z)/(float) gain;
out2 = (u/d1)/gain;
printf(" ref: %2.3f out1 = %2.3f\n",(u / (float)bc * s + z) /
(float)gain, out1);
printf(" comp: %2.3f out2 = %2.3f\n",(u/d1)/(float) gain, out2);
}
The output is:
u = 2765.000000
s = 20.000000
z = -10.000000
s = 20.000000
d1 = 81910.000000
ref: 3.501 out1 = 3.501
comp: 0.034 out2 = 0.034
I have encountered a perplexing expression evaluation. In the code
below, the output of the 'ref' printf statement is
3.501 and the output of the 'comp' printf statement is 0.034. I do not
understand where the factor of 100 is coming from. Any help
appreciated.
Thanks!
#include <stdio.h>
typedef unsigned short word;
int main ( int argc, char ** argv)
{
float s; /* span value */
float z; /* zero value */
float u;
float d1;
float out1;
float out2;
word gain;
word bc;
u = 2765;
bc = 4096;
s = 20;
z = -10;
gain = 1;
printf("u = %f\n",u);
printf("s = %f\n",s);
printf("z = %f\n",z);
printf("s = %f\n",s);
d1 = (float) bc * s + z; // why is this NOT the same as the middle
term in the 'out1' expression below?
printf("d1 = %f\n",d1);
out1 = (u/(float)bc * s + z)/(float) gain;
out2 = (u/d1)/gain;
printf(" ref: %2.3f out1 = %2.3f\n",(u / (float)bc * s + z) /
(float)gain, out1);
printf(" comp: %2.3f out2 = %2.3f\n",(u/d1)/(float) gain, out2);
}
The output is:
u = 2765.000000
s = 20.000000
z = -10.000000
s = 20.000000
d1 = 81910.000000
ref: 3.501 out1 = 3.501
comp: 0.034 out2 = 0.034