![](templates/subSilver/images/CCSLogo.jpg) |
![CCS C Software and Maintenance Offers](templates/subSilver/images/forumAd6.jpg) |
View previous topic :: View next topic |
Author |
Message |
ale.fdezsuarez
Joined: 02 Dec 2020 Posts: 3
|
String check and array assignment as efficiently as possible |
Posted: Wed Dec 02, 2020 5:38 am |
|
|
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. |
|
![](templates/subSilver/images/spacer.gif) |
temtronic
Joined: 01 Jul 2010 Posts: 9171 Location: Greensville,Ontario
|
|
Posted: Wed Dec 02, 2020 6:12 am |
|
|
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 |
|
![](templates/subSilver/images/spacer.gif) |
ale.fdezsuarez
Joined: 02 Dec 2020 Posts: 3
|
|
Posted: Wed Dec 02, 2020 6:21 am |
|
|
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? |
|
![](templates/subSilver/images/spacer.gif) |
temtronic
Joined: 01 Jul 2010 Posts: 9171 Location: Greensville,Ontario
|
|
Posted: Wed Dec 02, 2020 7:56 am |
|
|
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 |
|
![](templates/subSilver/images/spacer.gif) |
ale.fdezsuarez
Joined: 02 Dec 2020 Posts: 3
|
|
Posted: Wed Dec 02, 2020 8:26 am |
|
|
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](images/smiles/icon_biggrin.gif) |
|
![](templates/subSilver/images/spacer.gif) |
Ttelmah
Joined: 11 Mar 2010 Posts: 19363
|
|
Posted: Wed Dec 02, 2020 8:46 am |
|
|
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. |
|
![](templates/subSilver/images/spacer.gif) |
|
|
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
|