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

Function like log() or exp() are (usually) found in the math library (libm.a), which even host-based compilers do not link against by default.

Just look up the appropriate lib version for the platform, and add to the project.

I would think twice before using using expensive (code space, runtime) emulation code. Mind you, these (POSIX / ISO-C) functions are double. The float namesakes end in f ( expf(), logf(), etc.)

Wil1
Associate II

Do you know where can i find this libm.a and how to ad it to the smt32cubeide linker?

RMcCa
Senior II

Use linear interpolation. The stepsize will determine how closely the linear interpolation is to the real thing. I use Octave (mathlab) to generate comma seperated lists that i cut & paste into a C array​.

This (libm.a) is the POSIX name of the library, in a POSIX environment.

With your Cortex M toolchain, it is most probably different.

Most gcc-based IDEs use to come with several versions, for M0, M3, M4, soft, softFP and hardFP - ABI.

The name use to reflect the version/target. Check the manuals/help. I hope CubeIDE has one.

Some toolchains choose the proper lib if you select floatingpoint support during setup (project wizard).

I'm no CubeIDE user.