P
pozzugno
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.
Any suggestion to avoid pow() function call?
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.
Any suggestion to avoid pow() function call?