Configure Standard Math Library for Target System
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 theStandard math libraryparameter.
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 functionsqrtf()
, which operates on single-precision data, instead ofsqrt()
.
To change the library setting, use theConfiguration Parameters>Standard math libraryparameter. The command-line equivalent isTargetLangStandard
.
Generate and Inspect ANSI C Code
1. Open the example modelrtwdemo_clibsup
.
2. Generate code.
### Starting build procedure for model: rtwdemo_clibsup ### Successful completion of code generation for model: rtwdemo_clibsup
3. Examine the code in the generated filertwdemo_clibsup.c
. Note that the code calls thesqrt
function.
if (rtb_Abs2 < 0.0F) { rtb_Abs2 = -(real32_T)sqrt((real32_T)fabs(rtb_Abs2)); } else { rtb_Abs2 = (real32_T)sqrt(rtb_Abs2); }
Generate and Inspect ISO C Code
1. Change the setting ofStandard math librarytoC99 (ISO)
. Alternatively, at the command line, setTargetLangStandard
toC99 (ISO)
.
2. Regenerate the code.
### Starting build procedure for model: rtwdemo_clibsup ### Successful completion of code generation for model: rtwdemo_clibsup
3. Rexamine the code in the generated filertwdemo_clibsup.c
. Now the generated code calls the functionsqrtf
instead ofsqrt
.
if (rtb_Abs2 < 0.0F) { rtb_Abs2 = -sqrtf(fabsf(rtb_Abs2)); } else { rtb_Abs2 = sqrtf(rtb_Abs2); }