Force single precision floating-point in generated c code

14 views (last 30 days)
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?

Answers (2)

Andy Bartlett
Andy Bartlett on 9 Feb 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 on 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

Categories

Find more on Deployment, Integration, and Supported Hardware in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!