Force single precision floating-point in generated c code

9 ビュー (過去 30 日間)
Matteo
Matteo 2017 年 5 月 25 日
コメント済み: Aymen Omrane 2020 年 12 月 9 日
I am using the Embedded Coder to generate C code for a 32bit target which supports only single precision floats. In the model I obviously only use "single" signals and the generated code looks fine except three auto-generated files containing "rtGetInf" and "rtGetNaN" functions which still use "real_T". Is there any possibility to force "single" for the autogenerated functions?
  1 件のコメント
Richard Lobo
Richard Lobo 2017 年 8 月 2 日
Facing the same issue. Were you able to find a solution?

サインインしてコメントする。

回答 (2 件)

Andy Bartlett
Andy Bartlett 2018 年 2 月 9 日
Hi,
There is a Single Precision Converter tool that ships with Fixed-Point Designer that will automatically convert a subsystem or model to use single precision types. Watch this video.
In addition, Model Advisor has a check Identify questionable operations for strict single-precision design that will identify portions of a model or subsystem that are making undesired use of double precision floating point.
If you'd rather manage this manually, then one of the most important things is to set the Embedded Coder parameter
Standard math library TargetLangStandard
Make sure it is NOT using the library from the super old C90 standard from back in 1989. Back then the standard library functions only supported double precision. In the standard from 1999, C99, single precision floating point versions of library functions were added. Please be sure to set TargetLangStandard to C99 to be able to utilize strict singles C library functions. The Single Precision Converter tool shown in the video will automatically handle this setting.
Regards Andy Bartlett
  1 件のコメント
Aymen Omrane
Aymen Omrane 2020 年 12 月 9 日
Thanks for your answer. It worked for me

サインインしてコメントする。


Naini Dawar
Naini Dawar 2017 年 10 月 16 日
You can try to change the under-specified data type from double to single. Model Configuration Parameters >> Optimization >> Simulation and Code Generation Default for under-specified data type: Single

カテゴリ

Help Center および File ExchangeSimulink Coder についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by