%% 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(R)/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(R)/IEC 9899:1990 (C89/C90 (ANSI)), ISO/IEC 14882:2003(C++03 (ISO) or
% ISO/IEC 14882:2011(C++11 (ISO)) math library extensions, you can change
% the standard math library setting. The C++03 (ISO) or C++11 (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|.
%% Generate and Inspect ANSI C Code
%
% 1. Open the example model |rtwdemo_clibsup|.
%
model='rtwdemo_clibsup';
open_system(model);
%%
% 2. Generate code.
%
rtwbuild(model)
%%
% 3. Examine the code in the generated file |rtwdemo_clibsup.c|. Note that
% the code calls the |sqrt| function.
%
cfile = fullfile('rtwdemo_clibsup_grt_rtw', 'rtwdemo_clibsup.c');
rtwdemodbtype(cfile, ...
'if (rtb_Abs2 < 0.0F) {', ...
'/* End of Sqrt: ''<Root>/get_hypot1'' */', ...
1, 0);
rmdir('rtwdemo_clibsup_grt_rtw', 's');
rmdir('slprj', 's');
delete('rtwdemo_clibsup.slxc');

%% Generate and Inspect ISO C Code
%
% 1. Change the setting of *Standard math library* to |C99 (ISO)|.
% Alternatively, at the command line, set |TargetLangStandard| to |C99 (ISO)|.
%
set_param(model,'TargetLangStandard','C99 (ISO)');
%%
% 2. Regenerate the code.
%
rtwbuild(model)
%%
% 3. Reexamine the code in the generated file |rtwdemo_clibsup.c|. Now the
% generated code calls the function |sqrtf| instead of |sqrt|.
%
cfile = fullfile('rtwdemo_clibsup_grt_rtw', 'rtwdemo_clibsup.c');
rtwdemodbtype(cfile, ...
'if (rtb_Abs2 < 0.0F) {', ...
'/* End of Sqrt: ''<Root>/get_hypot1'' */', ...
1, 0);
%% Related Information
% * <docid:rtw_ref.bt7bn_r-1 Standard math library>
% * <docid:rtw_ug.f1116557 Configure a System Target File>
% * <docid:rtw_ug.bvlzdj_ Configure STF-Related Code Generation Parameters>
% * <docid:rtw_ug.brc7bjo-1 Configure a Code Replacement Library>
% * <docid:rtw_ug.bvly8wy Compare System Target File Support>
% * <docid:rtw_ug.buiywoq Replace Code Generated from Simulink Models>
%
%%
bdclose(model);
rtwdemoclean;

%%
% Copyright 2012 The MathWorks, Inc.