Why MatLab dont use the globalfimath properties
조회 수: 1 (최근 30일)
이전 댓글 표시
I set the globalfimath properties with this code:
resetglobalfimath;
Fm = fimath(...
'ProductMode', 'SpecifyPrecision', ...
'MaxProductWordLength', WordLength, ...
'ProductWordLength', WordLength, ...
'ProductFractionLength', FractionalLength, ...
'SumMode', 'SpecifyPrecision', ...
'MaxSumWordLength', WordLength,...
'SumWordLength', WordLength, ...
'SumFractionLength', FractionalLength, ...
'OverflowAction', 'Wrap', ...
'RoundingMethod', 'Floor');
globalfimath(Fm)
and i get the right properties returned...for example:
>>fimath
ans =
RoundingMethod: Floor
OverflowAction: Wrap
ProductMode: SpecifyPrecision
ProductWordLength: 64
ProductFractionLength: 53
SumMode: SpecifyPrecision
SumWordLength: 64
SumFractionLength: 53
CastBeforeSum: true
if i now try to use the fi() constructor it seems he always create a local fi-object. for example i get this:
>> A = fi(pi)
A =
3.1416
DataTypeMode: Fixed-point: binary point scaling
Signedness: Signed
WordLength: 16
FractionLength: 13
What can i do to get the same word- and franctionlength for every fi-object?
댓글 수: 0
답변 (1개)
Jessica Clayton
2020년 12월 2일
I understand that you are trying to use globalfimath to set the word length and fraction length to have the same values for every fi object. fimath controls the rules for performing arithmetic operations on fi object, however it does not control the word length or fraction length of the fi object. You can check that the fimath properties you defined were applied at construction of the fi object by using A.fimath and confirming that the output is the same as the specified globalfimath.
WordLength = 64;
FractionalLength = 53;
resetglobalfimath;
Fm = fimath(...
'ProductMode', 'SpecifyPrecision', ...
'MaxProductWordLength', WordLength, ...
'ProductWordLength', WordLength, ...
'ProductFractionLength', FractionalLength, ...
'SumMode', 'SpecifyPrecision', ...
'MaxSumWordLength', WordLength,...
'SumWordLength', WordLength, ...
'SumFractionLength', FractionalLength, ...
'OverflowAction', 'Wrap', ...
'RoundingMethod', 'Floor');
globalfimath(Fm);
A = fi(pi);
A.fimath
ans =
RoundingMethod: Floor
OverflowAction: Wrap
ProductMode: SpecifyPrecision
ProductWordLength: 64
ProductFractionLength: 53
SumMode: SpecifyPrecision
SumWordLength: 64
SumFractionLength: 53
CastBeforeSum: true
ans =
RoundingMethod: Floor
OverflowAction: Wrap
ProductMode: SpecifyPrecision
ProductWordLength: 64
ProductFractionLength: 53
SumMode: SpecifyPrecision
SumWordLength: 64
SumFractionLength: 53
CastBeforeSum: true
One way to assign the same word length and fraction length to every fi object is to use the “cast like” functionality as documented here. For example,
a = pi;
p = fi([],1,64,53);
b = cast(a,'like',p)
b.fimath
b =
3.1416
DataTypeMode: Fixed-point: binary point scaling
Signedness: Signed
WordLength: 64
FractionLength: 53
ans =
RoundingMethod: Floor
OverflowAction: Wrap
ProductMode: SpecifyPrecision
ProductWordLength: 64
ProductFractionLength: 53
SumMode: SpecifyPrecision
SumWordLength: 64
SumFractionLength: 53
CastBeforeSum: true
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Create Fixed-Point Objects in MATLAB에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!