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

6 ビュー (過去 30 日間)
Tejas
Tejas 2023 年 9 月 21 日
コメント済み: Tejas 2023 年 9 月 27 日
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.

回答 (1 件)

Kshittiz
Kshittiz 2023 年 9 月 25 日
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 件のコメント
Tejas
Tejas 2023 年 9 月 27 日
I see.. so I don't have to worry about data type mismatch in this case.... it would compare it.
Thanks a lot!

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeAUTOSAR Blockset についてさらに検索

製品


リリース

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by