How can I remove calls to floorf() and fmodf() in generated code?
10 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
MathWorks Support Team
am 19 Jun. 2019
Bearbeitet: MathWorks Support Team
am 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?
Akzeptierte Antwort
MathWorks Support Team
am 18 Jan. 2024
Bearbeitet: MathWorks Support Team
am 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 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Simulink Coder finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!