Get max, min and precision of a fi

19 次查看(过去 30 天)
What is the easiest way to find the maximum or minimum value that a fi can take?
What is the easiest way to find the precision of a fi?

采纳的回答

Jan
Jan 2019-3-27
编辑:Jan 2019-3-28
a = fi(pi, true, 16, 12);
xi = intmax(a)
This is code taken from https://www.mathworks.com/help/fixedpoint/ref/intmax.html , which I found as first link by asking an internet search engine for "Matlab fi maximum value".
a = fi(pi, true, 16, 12);
xd = realmax(a)
  3 个评论
Jan
Jan 2019-3-28
I cannot test this, because I do not have the FI toolbox. But what about realmax?
Justin
Justin 2019-3-28
Yes, that looks good. found everything I need here:https://uk.mathworks.com/help/fixedpoint/data-type-operators-and-tools.html
upperbound and lowerbound (or range) and realmin get me what I want. Thanks for your help navigating the documentation!

请先登录,再进行评论。

更多回答(2 个)

Justin
Justin 2019-3-27
I have answered my own question by creating the following function:
function info = fiInfo(inFi)
if inFi.Signed
info.max = (2^(inFi.WordLength - 1) - 1) / 2^inFi.FractionLength;
info.min = -2^((inFi.WordLength - 1) - inFi.FractionLength);
info.precision = 2^-inFi.FractionLength;
else
info.max = (2^inFi.WordLength - 1) / 2^inFi.FractionLength;
info.min = 0;
info.precision = 2^-inFi.FractionLength;
end
end
resulting in
>> a = fi(pi, true, 16, 12);
>> fiInfo(a)
ans =
struct with fields:
max: 7.9998
min: -8
precision: 2.4414e-04
or
>> a = fi(pi, false, 16, 12);
>> fiInfo(a)
ans =
struct with fields:
max: 15.9998
min: 0
precision: 2.4414e-04
This seems to be a lot of faffing to get at some basic info. Surely there is a better way?

Harry
Harry 2021-7-30
编辑:Harry 2021-7-30
% A fixed-point object with no value, 18-bit word length, and 16-bit fraction length
a = fi([],1,18, 16)
a = [] DataTypeMode: Fixed-point: binary point scaling Signedness: Signed WordLength: 18 FractionLength: 16
% The easiest way to find the maximum or minimum value that a fi can represent is
range(a)
ans =
-2.0000 2.0000 DataTypeMode: Fixed-point: binary point scaling Signedness: Signed WordLength: 18 FractionLength: 16
% The easiest way to find the precision of a fi is
eps(a)
ans =
1.5259e-05 DataTypeMode: Fixed-point: binary point scaling Signedness: Signed WordLength: 18 FractionLength: 16

类别

Help CenterFile Exchange 中查找有关 Fixed-Point Designer 的更多信息

标签

产品


版本

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by