Effacer les filtres
Effacer les filtres

Comparing Float value with integer value in Simulink/Autosar code generation

8 vues (au cours des 30 derniers jours)
Tejas
Tejas le 21 Sep 2023
Commenté : Tejas le 27 Sep 2023
I have Autosar generated part of code from MATLAB simulink here, If Sts is integer value then does this code compare with float value or not?
Like if Sts is 3 then does this execute by comparing values from different datatypes and give value ErrStg1 = 0.0F? if not then what should I change in simulink to compare values with float constant?
if ((TmpErrStg1 < 0.0F) || ((Sts < 1.9F) || (Sts > 2.1F)))
{
ErrStg1 = 0.0F;
}
Thank you in advance for any feedback.

Réponses (1)

Kshittiz
Kshittiz le 25 Sep 2023
Hi Tejas,
I understand that in the Autosar generated code, there is a variable named 'Sts' which is being compared with float values, and you want to know if the comparison will occur if ‘Sts’ is an integer.
Yes, even if Sts is an integer value (e.g., 3), then the comparison will still work. The integer 3 will be “implicitly” converted to a float for the comparison with the float constants.
Implicit type conversion is the automatic conversion of one data type to another by the compiler or interpreter. This happens when an operator or function expects operands of a certain type but receives operands of a different type. This helps in preventing errors and makes the code more flexible.
I hope this answers your query.
Thanks,
Kshittiz
  1 commentaire
Tejas
Tejas le 27 Sep 2023
I see.. so I don't have to worry about data type mismatch in this case.... it would compare it.
Thanks a lot!

Connectez-vous pour commenter.

Catégories

En savoir plus sur AUTOSAR Blockset dans Help Center et File Exchange

Produits


Version

R2020b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by