用于舍入和溢出模式的 fimath
仅在使用 fi 对象进行运算之前设置的舍入方法和溢出操作会影响这些运算的结果。一旦在 MATLAB® 中创建了一个 fi 对象,更改其舍入或溢出设置就不会影响其值。例如,假设有 fi 对象 a 和 b:
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 =
-1b = fi(1,T)
b =
0.9922由于您使用 fimath 对象 F(其 OverflowAction 设置为 Wrap)创建 a,因此 a 的值绕回到 -1。相反,因为您使用 OverflowAction 的 Saturate 默认值创建 b,其值饱和处理为 0.9922。
现在,将 fimath 对象 F 赋给 b:
b.fimath = F
b =
0.9922由于赋值运算及对应的溢出及饱和发生在创建 b 时,因此当为其赋予新 fimath 对象 F 时,其值不会更改。
注意
没有局部 fimath 且从浮点值创建的 fi 对象始终使用 RoundingMethod 为 Nearest 和 OverflowAction 为 Saturate 的设置进行构造。要构造具有不同 RoundingMethod 和 OverflowAction 属性的 fi 对象,请在 fi 构造函数中指定所需的 RoundingMethod 和 OverflowAction 属性。
有关 fimath 对象及其属性的详细信息,请参阅 fimath Object Properties