필터 지우기
필터 지우기

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

조회 수: 8 (최근 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 CenterFile Exchange에서 AUTOSAR Blockset에 대해 자세히 알아보기

제품


릴리스

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by