Why doesn't num2fixpt function return my expected counterpart fixed point value?

조회 수: 2 (최근 30일)
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

채택된 답변

Jyotsna Talluri
Jyotsna Talluri 2020년 7월 7일
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) ;
Refer to the documentatin of numerictype and reinterpretcast
  댓글 수: 1
Javier Cuadros
Javier Cuadros 2020년 7월 7일
Thanks for your reply Jyotsna.
But then, I see that using
a = fi(0.39);
produces
a =
0.3900
Which is my floating point number but not into a fixed point notation, is it?
Thanks again,

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Dimensionality Reduction and Feature Extraction에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by