cancel
Showing results for 
Search instead for 
Did you mean: 

how can i calculate log (x) or exp(x)

Wil1
Associate II
 
13 REPLIES 13

https://www.quinapalus.com/efunc.html

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

how can you do it on smt32CubeIde? i tried it, that functions works with numbers ex: log(8) or log10f(1000) but when you have variable x= 100 and you do log(x) or logf(x) the compiler give an error

Piranha
Chief II

This is not a STM32 specific question, but a C language basics.

http://www.cplusplus.com/reference/cmath/log/

Sorry, but the phrase " ...do it on smt32CubeIde?" suggests there is something more basic missing.

> when you have variable x= 100 and you do log(x) or logf(x) the compiler give an error

Which compiler? What error? Show us a minimal example exhibiting the problem - a screenshot, perhaps.

JW

PS. And please change your user name to a normal nick.

Wil1
Associate II

0690X00000ArQmHQAV.png

Yes, it's library linking and it is C basics...

Newlib-nano library doesn't include some not so often used code by default.

https://stackoverflow.com/questions/5419366/why-do-i-have-to-explicitly-link-with-libm

And what exactly is not clear from that error message? Check if your linker script (*.ld file) has the correct FLASH size corresponding to the real MCU part. If it has, then... reduce the code size or/and change the MCU to one with a bigger flash. This is a clear example of the fact that HAL library and CubeMX generated code is not only full of bugs, but also a bloatware...

P.C. Useful tool to analyze code and data sizes: http://www.sikorskiy.net/prj/amap/

S.Ma
Principal

If the compiler doesn't provide math.lib or if the code size is important, use interpolation, create a look up table of precalculated points and linearly interpolate between them. It's usually what is done in 8 bit MCU when speed and codesize is optimized in exchange or a lower accuracy. Sometime the variables are integer (value_x1000) to go a notch further. Check on Q31 pseudo fixed point type.