How we are getting overflow when single(-2) is stored in uint32?

single (-2) to uint32

5 件のコメント

What are you doing?
This is what I get —
v = single(-2)
v = single -2
vu32 = uint32(v)
vu32 = uint32 0
vi32 = int32(v)
vi32 = int32 -2
.
Nithinraj
Nithinraj 2023 年 5 月 20 日
I was getting an integer overflow error in uint32 block,input to this block is a single data type.I was confused on how the overflow is happening there.
Dyuman Joshi
Dyuman Joshi 2023 年 5 月 20 日
The "u" in the uint32 stands for unsigned, which means that this data-type supports only positive integers, along with 0.
If you want to convert a negative floating point integer to an integer data type, use signed integer classes, As @Star Strider has showed above (int8, int16, int32, int64)
Star Strider
Star Strider 2023 年 5 月 20 日
@Nithinraj — You need to mention that you are using Simulilnk.
Nithinraj
Nithinraj 2023 年 5 月 20 日
I was getting the above error in uint32 block in simulink.

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

 採用された回答

Kshittiz
Kshittiz 2023 年 5 月 23 日

0 投票

Hi,
I understand that you are getting overflow when single(-2) is stored in uint32 block in Simulink.
In Simulink, an overflow error occurs when the value being assigned or stored in a block exceeds the maximum representable value for the specified data type. In your case, you're trying to store the value -2 in a uint32 block, which represents an unsigned 32-bit integer.
The uint32 data type can only store non-negative integers ranging from 0 to 4294967295. Since -2 is a negative value, it cannot be represented by the uint32 data type, resulting in an overflow error.
Thanks!

その他の回答 (0 件)

タグ

質問済み:

2023 年 5 月 20 日

回答済み:

2023 年 5 月 23 日

Community Treasure Hunt

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

Start Hunting!

Translated by