# ARM Power/Exponential Function

I'm trying to code an exponential function for use on a PWM signal.

My question is, does anyone know how to do a power function on an ARM cortex-M (STM32F4 in this case, which has an FPU) microcontroller. Or would a taylor series approximation do the trick better.

I know this is question is very much programming related but as its related to microcontrollers I thought it would be ok to post here(?), plus it seems questions on stackoverflow get lost very quickly.

• A cursory google search of arm_power_f32 reveals that it performs a sum-of-squares over a floating point array and is therefore not a power function. – MikeJ-UK Jun 7 '13 at 11:21
• thanks, well that rules out that, I'll remove it from the question then. I though having power in the name and being in the maths header, it would be logically be a power function but names can be deceiving – richendes Jun 7 '13 at 11:27
• Plus in my head I for some reason translated sums of squares to product of squares which would be similar to a power function ie, 2x2 is one square so 2x(2x2) is a product of the 2x2 square. – richendes Jun 7 '13 at 11:33

The standard lib function for power on float data type is float powf(float, float). It appears to be well supported on my gcc-based STM32F4 setup. Given the performance of this MCU and its hardware FPU support for float, this function probably has excellent performance (it is likely using some taylor series or similar optimised numerical approximation). A look-up table approach might be faster if you can narrow your application to a specific set of power, but since such an implementation would be more complicated and less flexible, I would keep it as a possible optimisation if/when you determine that powf is too slow for your needs.