473,387 Members | 1,585 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

expression eval question


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

Jan 24 '07 #1
2 2012
kilgore wrote:
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?
// comments have been made standard C, but they're not a good idea for
posting code on any system where line breaks may be inserted without
your knowledge. This is why.
printf("d1 = %f\n",d1);
out1 = (u/(float)bc * s + z)/(float) gain;
out2 = (u/d1)/gain;
a/b * c + d is not a/(b * c + d). :)
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);
}
Jan 24 '07 #2
>a/b * c + d is not a/(b * c + d). :)

OF COURSE -- DOH! I'm embarrassed for a) having posted this, and b)
for not having seen this...
perhaps more coffee will help.

Thanks!

On Jan 24, 10:01 am, "Harald van Dijk" <true...@gmail.comwrote:
kilgore wrote:
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?// comments have been made standardC, but they're not a good idea for
posting code on any system where line breaks may be inserted without
your knowledge. This is why.
printf("d1 = %f\n",d1);
out1 = (u/(float)bc * s + z)/(float) gain;
out2 = (u/d1)/gain;a/b * c + d is not a/(b * c + d). :)
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);
}
Jan 24 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Christos TZOTZIOY Georgiou | last post by:
Hi all, this post contains at the end a handy module that I've used quite often when I wanted to analyse the occasional complex expression and how it was to be evaluated. The function...
1
by: Penguin | last post by:
For some odd reason, I am trying to do some complex time calculations that I want to let the user define. So I set up a table with EventID EventType EventExpression 1 ...
4
by: Wilson | last post by:
Hello, How can i eval a string expression like String abc = ??"dt.Rows.Columns.ToString() + dt.Rows.Columns.ToString()" Thanks Wilson
8
by: fredo | last post by:
This question was asked in comp.lang.javascript with no result. In IE5.x and IE6, I want to display an image when the user rolls over a text link. The image does indeed display, but only on the...
4
by: =?Utf-8?B?RXJpY2E=?= | last post by:
I am trying to dynamically create a javascript link. But, I get the following error: BC32017: Comma, ')', or a valid expression continuation expected. Here is the line I try creating the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.