In article <(E-Mail Removed)>,

<(E-Mail Removed)> wrote:

>I have a simple (16-bit) embedded platform and I have to make the following calculations.

>

>unsigned int

>func(unsigned int adc, unsigned int pwr, unsigned int pt, double exp) {

> return (unsigned int)(pow((double)adc, exp) *

> (double)pwr / pow((double)pt, exp));

>}

>

>I noticed this calculation takes too much time, most probably for pow() function call

>and double conversion.

>

>I'm finding a way to simplify/optimize this function. Consider that adc and pt

>parameters are in the range 0..1023, exp is in the range 1.00-3.00, and pwr can be

>50-10000.
Are you not worried about overflow?

Your embedded processor almost certainly does not have a floating-point

unit. This explains why your code is so slow.

I see all values are guaranteed to be integer values.

If you're not worried about overflow in the intermediate expressions,

or you can simplify your expression to reduce the risk, then consider

writing your own "ipow()" function.

--

-Ed Falk,

(E-Mail Removed)
http://thespamdiaries.blogspot.com/