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

int from float value

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



Joined: 24 Mar 2004
Posts: 53
Location: Portugal

View user's profile Send private message Send e-mail MSN Messenger

int from float value
PostPosted: Wed Mar 30, 2005 4:52 pm     Reply with quote

Hello

please I have this problem:

Code:


float var_A, var_B;

//var_A and var_B is used some times during the program

var_A= 54,75;
var_B = 6,7532;
var_A = var_A*var_B;   // the real value is 369,7377
//Now I only need the entire part of the value 369.

how to make this?
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Mar 30, 2005 5:17 pm     Reply with quote

Look at the floor() function in the CCS Help file or the manual.
carlosma



Joined: 24 Mar 2004
Posts: 53
Location: Portugal

View user's profile Send private message Send e-mail MSN Messenger

PostPosted: Thu Mar 31, 2005 2:03 am     Reply with quote

I need another way to do this, because the program use 99% of the ROM and have no space for more math.c functions.

I use 16F877 and the program is big

Thanks Carlos
Ttelmah
Guest







PostPosted: Thu Mar 31, 2005 3:05 am     Reply with quote

Seriously, you can't have something for nothing. Any solution is going to involve code, and so you need to find a way of reducing your code size, or having more space (18F452...).
You might try using 'var_c' as an int16, then var_c=var_a*var_b, will do the multipliation using a float, and cut the result to an integer using the internal cast. However the size will be close to the same. Where this would save space, is if you then print the result, since printing a float, uses a lot more code space than printing an integer.

Best Wishes
valemike
Guest







PostPosted: Thu Mar 31, 2005 3:38 pm     Reply with quote

I've seen a lot of posts about people running out of space.

I've gone thru the following chips, from start to finish:

16F876 --> 18F252 --> 18F2620

18F448 --> 18F458

* The 16F chips will use more ROM than the equivalent code in its 18F counterpart.

* 18F chips are not much more expensive than its counterpart 16F chip.

* Pre 3.191 code that uses up 90% ROM in an 18F seems to get reduced down to 70+% using the newer PCH versions.

By all means, get a new chip and/or upgrade your compiler!
Mark



Joined: 07 Sep 2003
Posts: 2838
Location: Atlanta, GA

View user's profile Send private message Send e-mail

PostPosted: Thu Mar 31, 2005 5:08 pm     Reply with quote

This is where you need to examine the LST file. Look at the asm code and find ways to reduce it. If you are accessing arrays quite a bit, then you might look at using a pointer instead. Printf's can eat up a lot as well.
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Sun Apr 03, 2005 2:08 pm     Reply with quote

Do you really need floats? Floats require a lot of memory space, a workaround is to use a technique called 'scalled integers'. For example instead of performing the float multiplication 54,75 * 6,7532 you do the integer multiplication 547500 * 67532 and skip the four least significant digits.
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