Cannot perform an implicit cast between these two classes. - Fixed numbers

91 ビュー (過去 30 日間)
Jonas
Jonas 2021 年 2 月 3 日
回答済み: Srija Kethiri 2022 年 12 月 12 日
Hi all
I have a simple Simulink Function, which accepts two uint32 inputs:
I use this function for stateflow transitions. Typically, I would call it as follows:
after_ms(temp_store_wait,500)
where temp_store_wait is a local uint32 variable, and 500 is just a static input.
However, the compiler complains that:
The reason for this, I believe, is that it regards the static number 500 as a double, and I provide it to a function which only accepts uint32 as second argument. To solve this, I call the function as follows:
after_ms(temp_store_wait,uint32(500))
Although this solves the error, it is really cumbersome and clutters the code. In my opinion, it is totally not necessary since a simple number should not implicitly be double as data type, but should back-propagate its data type, similarly as we can do with a simple Constant block in Simulink.
Can I teach the compiler to back-propagate data types for constant values, such that I don't explicitly need to provide the data type?
Many thanks,
Jonas

採用された回答

Srija Kethiri
Srija Kethiri 2022 年 12 月 12 日
Hi Jonas,
I understand that you want to change the default data type of the compiler to uint32.
Simulink does not support changing the default data type of the compiler currently.
By default, MATLAB stores all numeric values as double-precision floating point. You cannot change the default type and precision.
You can refer to this document to know about the default data type and numeric types of MATLAB:
Hope this helps!

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeComplex Logic についてさらに検索

製品


リリース

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by