fimath for Rounding and Overflow Modes
Only rounding methods and overflow actions set prior to an operation withfi
对象affect the outcome of those operations. Once you create afi
object in MATLAB®, changing its rounding or overflow settings does not affect its value. For example, consider thefi
对象a
andb
:
p = fipref('NumberDisplay','RealWorldValue',...'NumericTypeDisplay','none','FimathDisplay','none'); T = numerictype('WordLength',8,“FractionLength”,7); F = fimath('RoundingMethod','Floor','OverflowAction','Wrap'); a = fi(1,T,F)
a = -1
b = fi(1,T)
b = 0.9922
Because you createa
with afimath
objectF
that hasOverflowAction
set toWrap
, the value ofa
wraps to -1. Conversely, because you createb
with the defaultOverflowAction
value ofSaturate
, its value saturates to 0.9922.
Now, assign thefimath
objectF
tob
:
b.fimath = F
b = 0.9922
Because the assignment operation and corresponding overflow and saturation happened when you createdb
, its value does not change when you assign it the newfimath
objectF
.
Note
fi
对象with no local fimath and created from a floating-point value always get constructed with aRoundingMethod
ofNearest
and anOverflowAction
ofSaturate
. To constructfi
对象with differentRoundingMethod
andOverflowAction
properties, specify the desiredRoundingMethod
andOverflowAction
properties in thefi
constructor.
For more information about thefimath
object and its properties, seefimath Object Properties