View previous topic :: View next topic |
Author |
Message |
goyoko Guest
|
Calculus |
Posted: Fri Dec 13, 2002 7:24 am |
|
|
Hello...
I have a question about calc.
I wish put in the main program a potencial function y=a*x^b but when I use math.h library with the pow() function the memory code or ROM memory it's used untill 89\%. How can I do the same but useless too memory.
Greating
CPB.
___________________________
This message was ported from CCS's old forum
Original Post ID: 10024 |
|
|
Sherpa Doug Guest
|
Re: Calculus |
Posted: Fri Dec 13, 2002 7:43 am |
|
|
:=Hello...
:=
:=I have a question about calc.
:=I wish put in the main program a potencial function y=a*x^b but when I use math.h library with the pow() function the memory code or ROM memory it's used untill 89\%. How can I do the same but useless too memory.
:=
:=Greating
:=CPB.
What types of numbers are you using? Could b be an integer? If so just use a loop. If b is not an integer could it be one of several fixed values? Maybe a switch case structure to solve for each of those values?
___________________________
This message was ported from CCS's old forum
Original Post ID: 10025 |
|
|
goyoko Guest
|
Re: Calculus |
Posted: Fri Dec 13, 2002 7:49 am |
|
|
:=:=Hello...
:=:=
:=:=I have a question about calc.
:=:=I wish put in the main program a potencial function y=a*x^b but when I use math.h library with the pow() function the memory code or ROM memory it's used untill 89\%. How can I do the same but useless too memory.
:=:=
:=:=Greating
:=:=CPB.
:=
:=What types of numbers are you using? Could b be an integer? If so just use a loop. If b is not an integer could it be one of several fixed values? Maybe a switch case structure to solve for each of those values?
:=
Hi.. Values are float. I'm covert a int16 variable to float variable to display in LCD.
___________________________
This message was ported from CCS's old forum
Original Post ID: 10026 |
|
|
R.J.Hamlett Guest
|
Re: Calculus |
Posted: Fri Dec 13, 2002 9:02 am |
|
|
:=Hello...
:=
:=I have a question about calc.
:=I wish put in the main program a potencial function y=a*x^b but when I use math.h library with the pow() function the memory code or ROM memory it's used untill 89\%. How can I do the same but useless too memory.
:=
:=Greating
:=CPB.
Seriously, float arithmetic, is a very heavy user of ROM space. This effect is less of a problem with larger chips (for instance on the 18F252, I solve a fairly complex set of arithmetic, involving power, log, sin etc., and still have a reasonable amount of space. The space used also declines on these chips, where the more efficient memory access code, and the presence of the hardware multiplier help a lot.
One solution that works well if you have a limited input range, is to use scaled integers, instead of float values. With a bit of care, this can help a lot. I notice you mention (in your other post), using float with a printf. This can really cost in terms of RPM useage. Dealing with a similar problem, I converted the result of my arithmetic to an integer by multiplying by 100, then printed this to a string in memory (using sprintf), and manually added the decimal point. This used less than 3/4 the space of simply printing the float value.
Best Wishes
___________________________
This message was ported from CCS's old forum
Original Post ID: 10028 |
|
|
Sherpa Doug Guest
|
Re: Calculus |
Posted: Fri Dec 13, 2002 1:05 pm |
|
|
:=Hi.. Values are float. I'm covert a int16 variable to float variable to display in LCD.
I avoid floats at all costs. Scaled integers such as Mr Hamlett describes are the way to go with small chips. As others on this board have heard, I measure ships in integer millimeters and only convert to meters for output, which I do a string manipulation rather than numerical manipulation.
If your only reason for using a float is to print to a LCD, you can definately do better with ints.
___________________________
This message was ported from CCS's old forum
Original Post ID: 10039 |
|
|
Mircea
Joined: 12 Jan 2007 Posts: 7 Location: Europe
|
Re: Calculus |
Posted: Fri Apr 03, 2009 6:46 am |
|
|
Recent versions of CCS compiler offer %w format specifier.
Code: | printf(LCD_putc, "%4.1w", myIntVal); |
So we can use (in many situations) integer type instead of float.
Please find %w format specifier into the documentation. |
|
|
ckielstra
Joined: 18 Mar 2004 Posts: 3680 Location: The Netherlands
|
|
Posted: Fri Apr 03, 2009 8:07 am |
|
|
Thanks for making the effort to answer a question on this forum.
But do you really think the original poster is still waiting after 6,5 years ... ??? |
|
|
John P
Joined: 17 Sep 2003 Posts: 331
|
|
Posted: Fri Apr 03, 2009 11:22 am |
|
|
If he's making a PIC do floating point math--he might be. |
|
|
Mircea
Joined: 12 Jan 2007 Posts: 7 Location: Europe
|
|
Posted: Wed Apr 08, 2009 7:02 am |
|
|
ckielstra wrote: | Thanks for making the effort to answer a question on this forum.
But do you really think the original poster is still waiting after 6,5 years ... ??? |
Mieux plus tard que jamais.
The %w format specifier is recent. |
|
|
|