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

Integer math vs floating point math

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



Joined: 17 Nov 2009
Posts: 50

View user's profile Send private message

Integer math vs floating point math
PostPosted: Thu Jan 07, 2010 6:48 pm     Reply with quote

Hi !

As I'm dealing with my very first bigger project, I'm up to make a decision: to choose integer math over floating point variables

Why I assume it is good:
- less rom and ram usage for math operations
- faster math operations
- good to use as I'm dealing with low range values ( temperature, many values)
- no need to convert for further action with int variables ( for example to change a number in menu system)

My main reason to think that it is a good idea is: to avoid full ROM in a finished program (if to choose different devise with less program memory later, because atm. it seems like to be a problem).

Is it worth doing ? Because so far nothing is certain... at the moment. Or just to do it using floating point variables and if full rom problem occur later... just to re - do whole thing.

I'm asking for Your help and advice because I have very little c language experience and do not much about embedded system design... because it is my first project. Your answer and advise could save a day of low result work for me. Very Happy


Thank you in advance !
SherpaDoug



Joined: 07 Sep 2003
Posts: 1640
Location: Cape Cod Mass USA

View user's profile Send private message

PostPosted: Thu Jan 07, 2010 8:33 pm     Reply with quote

I only use floats if I really absolutely have to. Integers give you control over rounding and precision. They generate faster and smaller code. It may take a little more thought at the beginning of the project, but it forces you to really understand the data you are working with, and that is usually good. That extra thought can avoid bugs that otherwise show up late in the project just before delivery.

My first really big PIC project was gear to precisely measure ship hulls to find warping and dents. I could measure any ship afloat with 24 bit integer millimeters with lots of room to spare.

Tell us more about the nature of the project and its data and we can tell you more.
_________________
The search for better is endless. Instead simply find very good and get the job done.
Ttelmah
Guest







PostPosted: Fri Jan 08, 2010 5:04 am     Reply with quote

Yes.
Remember also, that CCS contains the ability to automatically display a scaled integer 'as if' it is a decimal value, using the %LW printf format.
Most people here who have experience with PIC's, will treat FP, as something to avoid if possible.

Best Wishes
bkamen



Joined: 07 Jan 2004
Posts: 1615
Location: Central Illinois, USA

View user's profile Send private message

PostPosted: Sat Jan 09, 2010 11:31 am     Reply with quote

And PIC's aren't the only MPU's without FP capability.

On ANY integer only MPU, one always wants to consider FP Math.

Some MPU's are fast enough so that maybe it's no big deal.. depending on the application. But that's always the catch. Carefully consider what's being done and see if FP is really needed.

I use FP on PICs when I know speed isn't an issue.

-Ben
_________________
Dazed and confused? I don't think so. Just "plain lost" will do. :D
SherpaDoug



Joined: 07 Sep 2003
Posts: 1640
Location: Cape Cod Mass USA

View user's profile Send private message

PostPosted: Sat Jan 09, 2010 9:34 pm     Reply with quote

It is not just a speed issue. With floating point it is often difficult to tell just when rounding errors will occur. With fixed point the rounding errors are very predictable, and if the integers are properly scaled the system resolution is better than from any equal data length floating point math.
_________________
The search for better is endless. Instead simply find very good and get the job done.
Jeff King



Joined: 20 Oct 2003
Posts: 43
Location: Hillsdale, Michigan USA

View user's profile Send private message Send e-mail Visit poster's website

PostPosted: Sat Jan 09, 2010 11:18 pm     Reply with quote

Any suggestions on integer based math libs? I.e. sin cos, etc etc.?
Ttelmah
Guest







PostPosted: Sun Jan 10, 2010 5:40 am     Reply with quote

'Integer arithmetic', implies 'no decimals', implies no possible results for sin/cos etc.....

Only with _scaled_ integers, do results for things like sin/cos exist.

For most applications, if you are only using (say) 2 digits), and coding for speed, then the fastest solution, is a lookup table. Just code your own. There have been several posted examples here for some specific applications.
For three digits, a 2 digit lookup, and linear interpolation is usually the simplest . There have been interpolation examples posted here as well.
You need to decide what scaling you want to use, and what accuracy you need, then people may be able to help.

Best Wishes
Jeff King



Joined: 20 Oct 2003
Posts: 43
Location: Hillsdale, Michigan USA

View user's profile Send private message Send e-mail Visit poster's website

PostPosted: Sun Jan 10, 2010 12:35 pm     Reply with quote

Ok, thanks.

About 7 places to the right of the decimal point Range of -180 to +180. GPS data calculating distances. Already using the Haversine forumla. Greater speed would be a plus but biggest concern is getting rid of rounding errors and extending precision.

Just looking for some references to some code libraries/techniques if you might know any. Or some seed words for the search engines to get me started on google/here.

Thanks again.
languer



Joined: 09 Jan 2004
Posts: 144
Location: USA

View user's profile Send private message

PostPosted: Sun Jan 10, 2010 8:02 pm     Reply with quote

Don't know if you've seen this... CORDIC 32bit Functions

Have not personally used them, but have seen many GPS projects using CORDIC arithmetic.
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