How can I remove calls to floorf() and fmodf() in generated code?
9 次查看(过去 30 天)
显示 更早的评论
MathWorks Support Team
2019-6-19
编辑: MathWorks Support Team
2024-2-29
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?
采纳的回答
MathWorks Support Team
2024-1-18
编辑:MathWorks Support Team
2024-2-29
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 个评论
更多回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!