How can I remove calls to floorf() and fmodf() in generated code?
9 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
MathWorks Support Team
le 19 Juin 2019
Modifié(e) : MathWorks Support Team
le 29 Fév 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?
Réponse acceptée
MathWorks Support Team
le 18 Jan 2024
Modifié(e) : MathWorks Support Team
le 29 Fév 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 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Simulink Coder dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!