MATLAB: Is it possible to force single precision instead of double precision when generating code from simulink

code generationdata typesEmbedded Codersimulink

Hello!
I am facing an issue where my generated code from Simulink contains some typecasts to double. Especially when i use the ABS block. In the code there's always fabs and a typecast to double even when it's a variable of type single… I would expect something like a call of fabsf without a typecast.
My actual problem is, that my code is going to run on a 32-bit embedded target with a FPU. So i'm fine with single as a data type and the software is designed to use single precision. But i want to avoid double as a data type at any cost due to efficiency. Of course i could run some S&R scripts, but isn't there a way to avoid double in the first place??
(actually it's real32_t and real_t just for clarification…)

Best Answer

The Solution for me was to use my own Target Function Library. I just added some entries for fabsf and it's fine now.
I used this example.