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!