How can I remove calls to floorf() and fmodf() in generated code?
11 views (last 30 days)
Show older comments
MathWorks Support Team
on 19 Jun 2019
Edited: MathWorks Support Team
on 29 Feb 2024
In my model, I'm trying to convert a signal from 'Single' to a fixed point type - unsigned fixed point 16 bit with 3 decimal places, using the Data Type Conversion block. When I proceed to generate code from the model, I observe the following line of code corresponding to the above block:
tmp_0 = (int16_T)fmodf(floorf(rtu_TraCtlInMedium->TraSpeed.TMRatio / 0.01F),65536.0F);
I think these calls made to "fmodf" and "floorf" and unnecessary and sub-optimal. How do I remove these from the generated code?
Accepted Answer
MathWorks Support Team
on 18 Jan 2024
Edited: MathWorks Support Team
on 29 Feb 2024
By checking the "Remove code from floating-point to integer conversions that wraps out-of-range values" property, you should be able to remove calls to "fmodf()" and "floorf()". To locate this property, launch Configuration Parameters and navigate to the Code Generation tab and expand the dropdown. Under the dropdown, select Optimization and on the main window, expand Advanced Parameters. Under that, you should find the property.
Please run the below command in the MATLAB R2018b command window to get the release specific documentation with more information regarding this property:
web(fullfile(docroot, 'rtw/ref/remove-code-from-floating-point-to-integer-conversions-that-wraps-out-of-range-values.html'))
Please note however that by changing this property, you may change the behavior of the generated code - the code may reduce in size and become faster, but this could potentially produce results that do not match simulation in the case of out-of-range values. Therefore, I'd suggest testing this behavior out after changing the property.
Please follow the below link to search for the required information regarding the current release:
0 Comments
More Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!