Specify standard library extensions that the code generator uses for math operations. When you generate code for a new model or with a new configuration set object, the code generator uses the ISO®/IEC 9899:1999 C (C99 (ISO)) library by default. For preexisting models and configuration set objects, the code generator uses the library specified by the Standard math library parameter.
If your compiler supports the ISO®/IEC 9899:1990 (C89/C90 (ANSI)) or ISO/IEC 14882:2003(C++03 (ISO)) math library extensions, you can change the standard math library setting. The C++03 (ISO) library is an option when you select C++ for the programming language.
The C99 library leverages the performance that a compiler offers over standard ANSI C. When using the C99 library, the code generator produces calls to ISO C functions when possible. For example, the generated code calls the function sqrtf()
, which operates on single-precision data, instead of sqrt()
.
To change the library setting, use the Configuration Parameters>Standard math library parameter. The command-line equivalent is TargetLangStandard
.
1. Open the example model rtwdemo_clibsup
.
2. Generate code.
### Starting build procedure for: rtwdemo_clibsup ### Successful completion of code generation for: rtwdemo_clibsup
3. Examine the code in the generated file rtwdemo_clibsup.c
. Note that the code calls the sqrt
function.
if (rtb_Abs2 < 0.0F) { rtb_Abs2 = -(real32_T)sqrt((real32_T)fabs(rtb_Abs2)); } else { rtb_Abs2 = (real32_T)sqrt(rtb_Abs2); }
1. Change the setting of Standard math library to C99 (ISO)
. Alternatively, at the command line, set TargetLangStandard
to C99 (ISO)
.
2. Regenerate the code.
### Starting build procedure for: rtwdemo_clibsup ### Successful completion of code generation for: rtwdemo_clibsup
3. Reexamine the code in the generated file rtwdemo_clibsup.c
. Now the generated code calls the function sqrtf
instead of sqrt
.
if (rtb_Abs2 < 0.0F) { rtb_Abs2 = -sqrtf(fabsf(rtb_Abs2)); } else { rtb_Abs2 = sqrtf(rtb_Abs2); }
Standard math library (Simulink Coder)
Configure a System Target File (Simulink Coder)
Configure STF-Related Code Generation Parameters (Simulink Coder)
Configure a Code Replacement Library (Simulink Coder)
Compare System Target File Support Across Products (Simulink Coder)
Replace Code Generated from Simulink Models (Simulink Coder)