主要内容

用于舍入和溢出模式的 fimath

仅在使用 fi 对象进行运算之前设置的舍入方法和溢出操作会影响这些运算的结果。一旦在 MATLAB® 中创建了一个 fi 对象,更改其舍入或溢出设置就不会影响其值。例如,假设有 fi 对象 ab

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

由于您使用 fimath 对象 F(其 OverflowAction 设置为 Wrap)创建 a,因此 a 的值绕回到 -1。相反,因为您使用 OverflowActionSaturate 默认值创建 b,其值饱和处理为 0.9922。

现在,将 fimath 对象 F 赋给 b

b.fimath = F
b = 

    0.9922

由于赋值运算及对应的溢出及饱和发生在创建 b 时,因此当为其赋予新 fimath 对象 F 时,其值不会更改。

注意

没有局部 fimath 且从浮点值创建的 fi 对象始终使用 RoundingMethodNearestOverflowActionSaturate 的设置进行构造。要构造具有不同 RoundingMethodOverflowAction 属性的 fi 对象,请在 fi 构造函数中指定所需的 RoundingMethodOverflowAction 属性。

有关 fimath 对象及其属性的详细信息,请参阅 fimath Object Properties