Why does generated code use the double version of math functions when the data are single precision floats?
Mostra commenti meno recenti
I am using Simulink with Embedded Coder. When I generate code from my model, the generated code contains output like the following:
out1 = (real32_T)sin(in1);
out2 = (real32_T)fabs(in2);
out3 = (real32_T)floor(in3);
out4 = (real32_T)log10(in4);
In each case, the generated code is using the version of the math function that takes and returns a double even though all of the "in" and "out" variables have a float data type.
Even though the results of this code would be computationally correct, this seems like a wasteful way to perform the calculation. Additionally, some of my hardware only supports single precision math. Is there a way to make this operation only use single precision types? For example, use the version of the math functions that take and return a "float" like below?
out1 = sinf(in1);
out2 = fabsf(in2);
out3 = floorf(in3);
out4 = log10f(in4);
Risposta accettata
Più risposte (1)
Andy Bartlett
il 15 Gen 2026
0 voti
The easiest way to get rid of all double precision floating-point in your Simulink model and its generated code is to use Single Precision Converter App.
This will make sure code generation is configured for C99 as described in the other answer.
It will also change the settings for signals, parameters, default data type propagation choice, etc. to use single instead of double.
Categorie
Scopri di più su Texas Instruments C2000 Processors in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!