Force single precision floating-point in generated c code

20 visualizaciones (últimos 30 días)
Matteo
Matteo el 25 de Mayo de 2017
Comentada: Aymen Omrane el 9 de Dic. de 2020
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?

Respuestas (2)

Andy Bartlett
Andy Bartlett el 9 de Feb. de 2018
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

Naini Dawar
Naini Dawar el 16 de Oct. de 2017
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

Categorías

Más información sobre Deployment, Integration, and Supported Hardware en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by