CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

ccs int32 calculation

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
lgeorge123



Joined: 05 Dec 2004
Posts: 31

View user's profile Send private message

ccs int32 calculation
PostPosted: Wed Mar 18, 2009 7:30 am     Reply with quote

I have a prgram to calculate some variables.
Code:
int16 cal_x_min,cal_x_max,cal_y_min,cal_y_max,x_coord,y_coord;
int32 x_coord320,y_coord240
cal_x_min=0x0123;
cal_x_max=0x0034;
cal_y_min=0x0567;
cal_y_max=0x0456;
x_coord=cal_x_min-0x0007;
y_coord=cal_y_min-0x0001;
x_coord320 = (x_coord * 320) / (cal_x_min - cal_x_max);
 y_coord240 = ((y_coord *240) - 240) / (cal_y_min - cal_y_max);

using the above calculation the result is wrong (x_coord320 and y_coord240) , can somebody give me some suggestions ????
Wayne_



Joined: 10 Oct 2007
Posts: 681

View user's profile Send private message

PostPosted: Wed Mar 18, 2009 8:07 am     Reply with quote

Need to cast your 16 bit vars to 32 bits to force the compiler to use 32 bit maths in the equation

Code:

x_coord320 = ((int32)x_coord * 320) / (cal_x_min - cal_x_max);
y_coord240 = (((int32)y_coord *240) - 240) / (cal_y_min - cal_y_max);
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group