Force single precision floating-point in generated c code

19 vues (au cours des 30 derniers jours)
Matteo
Matteo le 25 Mai 2017
Commenté : Aymen Omrane le 9 Déc 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?
  1 commentaire
Richard Lobo
Richard Lobo le 2 Août 2017
Facing the same issue. Were you able to find a solution?

Connectez-vous pour commenter.

Réponses (2)

Andy Bartlett
Andy Bartlett le 9 Fév 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 le 16 Oct 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

Catégories

En savoir plus sur Deployment, Integration, and Supported Hardware dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by