melexis / mlx90640-library

MLX90640 library functions
Apache License 2.0
242 stars 192 forks source link

pow(double, double) stack usage very high #36

Open adibacco opened 5 years ago

adibacco commented 5 years ago

I have noticed that in a lot of functions, for example: ExtractAlphaParameters math library pow function is used. Nothing wrong but for a small system like STM32L072, RAM is precious and the pow function is very slow and uses a lot of stack. I would replace all pow(2, x) with something like this (1 << x) that is way more efficient. Doing this change I fixed a number of stack overflows. At least it would be fine to replace the pow(2, x) with a define POW2(x), then someone could set: #define POW2(x) pow(2, (double) X) while someone else like me: #define POW2(x) ((double) (1 << x)) I saw in the code that there are calculations involving big numbers like pow(2, 34) then it is better to deinfe POW2 like this: #define POW2(x) ((double) ((long long)1 << x))

Atakancelik1 commented 5 years ago

Which software should I use?