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 support@ccsinfo.com

is there any way???

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







is there any way???
PostPosted: Tue Mar 22, 2005 8:45 am     Reply with quote

i want using some number floating point
but in the end of the my routine i want convert this(floating) code to integer but i cant find any way please write for me a few line code
thanx to every body...


const int R=384;
int Rx //Rx is variable reading from port
float z,t
main(void){
read by y from RA1;
z=y/x;
if(z<1){t=1-z;x=x+x*t;} //add(or subtruct) tolerance to R(esistance)
if(z>1){t=z-1;x=x-x*t;}
Ttelmah
Guest







PostPosted: Tue Mar 22, 2005 10:55 am     Reply with quote

In C, this is semi automatic, but can also be forced with a 'cast'.
If you have:

float val;
int ival;

Then you can say:
ival=val*10.213;

and ival, will receive the integer part of the float sum 'val' times 10.213.

Hence as I say 'semi automatic'.

However you can also 'force' the conversion at particular points. So for instance:

ival = ((int)(val*10.213))/5;

Will take the float number 'val', use floating point arithmetic to multiply this by 10.213, then convert the result to integer (This is the '(int)' statement), then divide the integer by 5, using integer arithmetic.
This bracketted numeric type, is called a 'cast', and is particularly useful to override the defaults, where otherwise a number might overflow. If (for instance), you calculate:

int8 ival2,ival;
ival=(ival*128)/ival2;

Then the multiplication will be done using 8bit arithmetic since all the numbers concerned are 8bit values. However:

ival=(ival*128L)/ival2;

Will force the arithmetic to use 16bit, since '128' is now declared as a 'long'. Similarly:

ival=((int16)ival*128)/ival2;

Will do the same, since ival, will now be converted to a 16bit type, before the sum.

Best Wishes
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