Confusion between real-world and floating-point values

1 次查看(过去 30 天)
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

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Fixed-Point Designer 的更多信息

产品


版本

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by