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

String check and array assignment as efficiently as possible

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



Joined: 02 Dec 2020
Posts: 3

View user's profile Send private message

String check and array assignment as efficiently as possible
PostPosted: Wed Dec 02, 2020 5:38 am     Reply with quote

Hello, everybody. I would like to know if anyone could help me to try an assignment and a slight check of a string that is of this type:
Code:
A=[a1,a2,a3,a4]/[b1,b2,b3,b4]

Where ai, bi are floating type numbers that can be accurate to 0.000, for example:
Code:
A=[0.5,-0.215,5.54,7.552]/[-0.001,0.554,0.584,0.541]

The way to introduce the data to the PIC16F886 in this case would be using the serial port with the directive #use232

After that as a result what I intend to achieve is
Code:
float array_a[4] , array_b[4];
array_a[0] = a1;
array_a[1] = a2;
array_a[2] = a3;
array_a[3] = a4;
array_b[0] = b1;
array_b[1] = b2;
array_b[2] = b3;
array_b[3] = b4;


I know how to do it using <strings.h> and functions like strcmp and atof but they would take up more than half the memory of the PIC. I'm looking for something that is much more efficient.

Thank you very much for your help.
temtronic



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

View user's profile Send private message

PostPosted: Wed Dec 02, 2020 6:12 am     Reply with quote

hmm..
I don't understand what 'A' is supposed to be, so please explain, as it's been 5 decades since I was in school... show what result should be with your example numbers, that would help me.

The BIG issue is the floating point numbers !!
PICs don't handle them very well. It takes a LOT of codespace and TIME to use FP.
Instead convert the FP into scaled integers first, THEN do the 'math'.

Jay
ale.fdezsuarez



Joined: 02 Dec 2020
Posts: 3

View user's profile Send private message

PostPosted: Wed Dec 02, 2020 6:21 am     Reply with quote

temtronic wrote:
hmm..
I don't understand what 'A' is supposed to be, so please explain, as it's been 5 decades since I was in school... show what result should be with your example numbers ,that'd help me.

the BIG issue is the floating point numbers !!
PICs don't handle them very well. It takes a LOT of codespace and TIME to use FP.
Instead convert the FP into scaled integers first , THEN do the 'math'.

Jay


Thanks for your help Jay.

A is just a letter to identify that what follows is an expression of that time.

The only thing I want to achieve is to extract the numbers that are within the expression. How can I do this by working with integers if the number is really floating?
temtronic



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

View user's profile Send private message

PostPosted: Wed Dec 02, 2020 7:56 am     Reply with quote

quick reply...

use the 'search' function of this forum and insert 'scaled integers', you'll find 'hits' of examples. For more information, simply Google 'scaled integers'.

Jay
ale.fdezsuarez



Joined: 02 Dec 2020
Posts: 3

View user's profile Send private message

PostPosted: Wed Dec 02, 2020 8:26 am     Reply with quote

temtronic wrote:
quick reply...

use the 'search' function of this forum and insert 'scaled integers', you'll find 'hits' of examples. For more information, simply Google 'scaled integers'.

Jay


Thank you so much for all! Very Happy
Ttelmah



Joined: 11 Mar 2010
Posts: 19544

View user's profile Send private message

PostPosted: Wed Dec 02, 2020 8:46 am     Reply with quote

A huge amount would depend on the range, and 'scale' of these numbers?.
If these are coming from something that formats them in a nice predictable
format, so (for example), something like:

100.04, 274.45, 2200.34....

So, perhaps always with one, two, three decimal places, then the way to work
is in integer 'tenths' 'hundredths', or 'thousandths'. Store these in an int32
and you can deal with values when working in 'thousandths' up to over 2
million. With 10 digit precision, versus about 6 for floating point numbers.
Smaller and faster code as well.
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