On Mar 12, 9:16 am, suppamax <(E-Mail Removed)> wrote:

> Hi everybody!

>

> I'm writing a C program for a PIC18F microcontroller.

>

> I need to calculate a power function, in which both base and exponent

> are fixed point numbers (ex: 3.15^1.13).

>

> Using pow() function is too expensive...

>

> Is there another way to do that?
It doesn't seem obvious to me. I guess you would want a break down

like:

two_pow_fromIM ( y * two_log_toIM ( x ) );

The idea would be that two_log_toIM and two_pow_fromIM could be

implemented as a scaling (normalize to the range 1 <= x < 2) then

either a post or pre-shift along with a table look up if the

resolution was small enough (and possibly perform interpolations). To

_fromIM and _toIM reflect the fact you might like to convert it to a

temporarily higher resolution intermediate value, or range corrected

for the particular input values.

I am not aware of any really good approximations to log() or 2exp()

except for taylor series or rational function approximations, which

will end up doing no better than using pow() directly. This table

based stuff would obviously compromise accuracy/resolution.

--

Paul Hsieh

http://www.pobox.com/~qed/
http://bstring.sf.net/