Effacer les filtres
Effacer les filtres

Confusion between real-world and floating-point values

1 vue (au cours des 30 derniers jours)
Life is Wonderful
Life is Wonderful le 4 Août 2022
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 !!

Réponse acceptée

Walter Roberson
Walter Roberson le 4 Août 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

Plus de réponses (0)

Produits


Version

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by