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

8 Ansichten (letzte 30 Tage)
Tejas
Tejas am 21 Sep. 2023
Kommentiert: Tejas am 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.

Antworten (1)

Kshittiz
Kshittiz am 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 Kommentar
Tejas
Tejas am 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!

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu AUTOSAR Blockset finden Sie in Help Center und File Exchange

Produkte


Version

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by