# Confusion between real-world and floating-point values

1 Ansicht (letzte 30 Tage)
Life is Wonderful am 4 Aug. 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.
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 !!
##### 0 Kommentare-2 ältere Kommentare anzeigen-2 ältere Kommentare ausblenden

Melden Sie sich an, um zu kommentieren.

### Akzeptierte Antwort

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
##### 1 Kommentar-1 ältere Kommentare anzeigen-1 ältere Kommentare ausblenden
Life is Wonderful am 4 Aug. 2022
Ahaah ,Thanks makes perfect sense.

Melden Sie sich an, um zu kommentieren.

### Kategorien

Mehr zu Fixed-Point Designer finden Sie in Help Center und File Exchange

R2022a

### Community Treasure Hunt

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

Start Hunting!

Translated by