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

calculations in ccs

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



Joined: 05 May 2011
Posts: 4

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

calculations in ccs
PostPosted: Sat Nov 05, 2011 9:44 pm     Reply with quote

Can anyone help me with guidelines on how to handle values beyond 256, since ccs returns incorrect answers, e.g. 250 +250 = -12. Is there a library I am suppose to include apart from math.h?
temtronic



Joined: 01 Jul 2010
Posts: 9170
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Sat Nov 05, 2011 9:53 pm     Reply with quote

While you have a project open, press F11, and the CCS onscreen HELP file will come up.Look on the left side, click on 'data definitions' and read the screen info.

I always have the HELP screens open...very,very handy reference to almost everything you need to know about CCS C !
Koketso



Joined: 05 May 2011
Posts: 4

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

PostPosted: Sat Nov 05, 2011 10:16 pm     Reply with quote

Tried unsigned long, still getting incorrect values but this time they are different from the ones obtained first. Do I need to do a conversion before I display on a LCD ?
temtronic



Joined: 01 Jul 2010
Posts: 9170
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Sat Nov 05, 2011 10:52 pm     Reply with quote

You'll have to show us your code...but yes, the format of the print function has to be coded for the type of data you want to show, again, look at the onscreen help file, lookup 'printf', it's all there or open up any of the examples CCS kindly supplies to see how it's done.
Ttelmah



Joined: 11 Mar 2010
Posts: 19359

View user's profile Send private message

PostPosted: Sun Nov 06, 2011 4:57 am     Reply with quote

This is not specific to CCS, though it is slightly 'tighter' in CCS, than in most modern languages.
Basically, in C, _you_ have to ensure that the maths type used, can support all possible values at all times, and then select the output format to suit that type.

Now on most C's on the PC (for example), the 'minimum' type used, is at least an int16, so problems are slightly less common, and on more strongly 'typed' languages, the compiler will complain if you try to print a value with a format that doesn't support it. It is both a power and a weakness of C, allowing you to mix types in a way that such languages don't allow, and (especially on little chips like the PIC), avoid using slower maths forms when not needed, but with these advantages, comes the cost of you needing to think at all times whether the types will support what you want to do.....

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