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

Pwr() or Pow() functions don't functioning

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



Joined: 16 May 2006
Posts: 65
Location: Ankara/Turkey

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

Pwr() or Pow() functions don't functioning
PostPosted: Fri Mar 16, 2007 7:55 am     Reply with quote

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
Ttelmah
Guest







PostPosted: Fri Mar 16, 2007 8:28 am     Reply with quote

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
KaraMuraT



Joined: 16 May 2006
Posts: 65
Location: Ankara/Turkey

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

PostPosted: Fri Mar 16, 2007 8:40 am     Reply with quote

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
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