Confusion between real-world and floating-point values

1 回表示 (過去 30 日間)
Life is Wonderful
Life is Wonderful 2022 年 8 月 4 日
コメント済み: Life is Wonderful 2022 年 8 月 4 日
Hello there,
I'm converting floating to real-world data values with the code snippet below.
I notice that after scaling, floating point values are no longer fractional, implying that data loss has occurred.
Thank you in advance
fi(linspace(-5,5,10),true,32,28)
ans =
-5.0000 -3.8889 -2.7778 -1.6667 -0.5556 0.5556 1.6667 2.7778 3.8889 5.0000 DataTypeMode: Fixed-point: binary point scaling Signedness: Signed WordLength: 32 FractionLength: 28
storedInteger(fi(linspace(-5,5,10),true,32,28))
ans = 1×10
-1342177280 -1043915662 -745654044 -447392427 -149130809 149130809 447392427 745654044 1043915662 1342177280
storedInteger(fi(linspace(-5,5,10),true,32,28)) / 2 ^28
ans = 1×10
-5 -4 -3 -2 -1 1 2 3 4 5
I'm expecting fractional length, but I'm wondering where it's gone. Thanks !!

採用された回答

Walter Roberson
Walter Roberson 2022 年 8 月 4 日
You forgot to take into account that an integer data type operated on with a double precision number, returns the integer data type
fi(linspace(-5,5,10),true,32,28)
ans =
-5.0000 -3.8889 -2.7778 -1.6667 -0.5556 0.5556 1.6667 2.7778 3.8889 5.0000 DataTypeMode: Fixed-point: binary point scaling Signedness: Signed WordLength: 32 FractionLength: 28
SI = storedInteger(fi(linspace(-5,5,10),true,32,28))
SI = 1×10
-1342177280 -1043915662 -745654044 -447392427 -149130809 149130809 447392427 745654044 1043915662 1342177280
class(SI)
ans = 'int32'
SI / 2^28
ans = 1×10
-5 -4 -3 -2 -1 1 2 3 4 5
double(SI) / 2^28
ans = 1×10
-5.0000 -3.8889 -2.7778 -1.6667 -0.5556 0.5556 1.6667 2.7778 3.8889 5.0000
  1 件のコメント
Life is Wonderful
Life is Wonderful 2022 年 8 月 4 日
Ahaah ,Thanks makes perfect sense.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeFixed-Point Designer についてさらに検索

製品


リリース

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by