Why doesn't num2fixpt function return my expected counterpart fixed point value?
16 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Javier Cuadros
il 2 Lug 2020
Commentato: Javier Cuadros
il 7 Lug 2020
Hello,
I am trying to convert from float/double to fixed point notation, for instance let's use the number x = 0.39 as input.
I would like to convert x into its unsigned 16 bits flxed-point counterpart, to do so in C++ I am accustomed to use the expression , this will make that the fixed point version of 0.39 is 25559.
However, I cannot get that result if I make use of num2fixpt function, I am using it in the following way
num2fixpt(0.39, ufix(16))
ans =
0
What am I doing wrong when using num2fixpt function?
Thanks in advance,
Regards
0 Commenti
Risposta accettata
Jyotsna Talluri
il 7 Lug 2020
num2fixpt function does not convert double/float to a fixed point notation, instead it converts value to a nearest value represented by fixed point data type.You can convert double value to fixed point data type using fi
a = fi(0.39);
T = numerictype(0, 16, 0);
c = reinterpretcast(a, T) ;
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Numeric Types in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!