Filter löschen
Filter löschen

Confusion between real-world and floating-point values

1 Ansicht (letzte 30 Tage)
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 !!

Akzeptierte Antwort

Walter Roberson
Walter Roberson am 4 Aug. 2022
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

Weitere Antworten (0)

Produkte


Version

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by