Why does generated code use the double version of math functions when the data are single precision floats?
古いコメントを表示
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);
採用された回答
その他の回答 (1 件)
Andy Bartlett
2026 年 1 月 15 日
0 投票
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.
カテゴリ
ヘルプ センター および File Exchange で Texas Instruments C2000 Processors についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!