![](templates/subSilver/images/CCSLogo.jpg) |
![CCS C Software and Maintenance Offers](templates/subSilver/images/forumAd6.jpg) |
View previous topic :: View next topic |
Author |
Message |
KaraMuraT
Joined: 16 May 2006 Posts: 65 Location: Ankara/Turkey
|
Pwr() or Pow() functions don't functioning |
Posted: Fri Mar 16, 2007 7:55 am |
|
|
If I use pow or pwr functions, it returns just 0. As you know it's a simple power function for pwr(x,y) = power x to y. But it does not work.
In fact, despite it's not working, consumes lots of ROM. My code was about %48 of 64K, after writing my own power function, it dropped to %41. It's about 4,5K ROM space.
Anyone realised that too?
Version 4.023 _________________ /// KMT
/// www.muratursavas.com |
|
![](templates/subSilver/images/spacer.gif) |
Ttelmah Guest
|
|
Posted: Fri Mar 16, 2007 8:28 am |
|
|
This is a problem with the math.h library in the V4 compilers.
V4, switches to 'proper' C syntax, with regard to pointer incrementing. Unfortunately this causes a problem with the math.h code.
This is now fixed, but there are three versons around.
The old math library, had a number of lines using pointers like:
*(&res) = n + 0x7F;
The correct replacement, is:
*((int8 *)&res) = n + 0x7F;
The replacement being shipped for a while (which doesn't work), had:
*((int8)&res) = n + 0x7F;
I think your version will have this form.
You need to either update your compiler, or manually edit all the pointer references in the math library to the fixed syntax.
Best Wishes |
|
![](templates/subSilver/images/spacer.gif) |
KaraMuraT
Joined: 16 May 2006 Posts: 65 Location: Ankara/Turkey
|
|
Posted: Fri Mar 16, 2007 8:40 am |
|
|
Thanks for the reply Ttelmah. I've manually corrected it.
But I have a suggestion about this power function. I think there should be an integer power function, not float, for simple purposes. If I couldn't realize that fact, I have to stay with 18F4620 rather than 18F4520 which is cheaper.
Also simple process will be much faster. Does not require any log() or exp() processes. Its simple like this:
Code: | unsigned int32 int_power(unsigned int16 base, unsigned int16 exponent)
{
unsigned int32 result = 1;
unsigned int16 pc;
for(pc=0;pc<exponent;pc++) result *= base;
return result;
}
|
_________________ /// KMT
/// www.muratursavas.com |
|
![](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
|