谷歌在这个问题上保持沉默。我目前在 Matlab 中仅在 16 位有符号定点上实现数值计算器。但是对 16 位定点的算术运算导致数据类型扩展为以下
>> a = int16(1.5 * 4)
a = 6
>> T = numerictype(1, 16, 2)
T = DataTypeMode: Fixed-point: binary point scaling
Signedness: Signed
WordLength: 16
FractionLength: 2
>> dis = reinterpretcast(a, T)
dis = 1.5000
DataTypeMode: Fixed-point: binary point scaling
Signedness: Signed
WordLength: 16
FractionLength: 2
>> c = dis * dis
c = 2.2500
DataTypeMode: Fixed-point: binary point scaling
Signedness: Signed
WordLength: 32
FractionLength: 4
我希望变量c
保持在 WordLength 16,FractionLength 2。是否可以在不扩展基础数据类型的情况下完成 16 位定点上的算术运算?我将承担任何上溢和下溢的风险。任何帮助都是极好的。
编辑:输入fimath
命令窗口会导致错误。为什么会出现这个错误?
>> F = fimath('OverflowAction','Wrap', 'RoundingMethod', 'Floor', ...
'ProductWordLength', 16, 'ProductFractionLength', 2);
No public field OverflowAction exists for class embedded.fimath.
Error in fimath (line 72)
this.(varargin{k}) = varargin{k+1};