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

10 views (last 30 days)
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.

Answers (1)

Kshittiz
Kshittiz on 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 Comment
Tejas
Tejas on 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!

Sign in to comment.

Categories

Find more on AUTOSAR Blockset in Help Center and File Exchange

Products


Release

R2020b

Community Treasure Hunt

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

Start Hunting!