计算斜率和偏置
斜率偏置定标概述
使用斜率偏置定标时,您必须指定数字的斜率和偏置。斜率偏置定标数的真实值可以表示为:
计算斜率和偏置
从所需的端点、符号性和字长开始。
lower_bound = 999; upper_bound = 1000; is_signed = true; word_length = 16;
要查找具有指定字长和符号性的 fi 对象的范围,请使用 函数。
[q_min, q_max] = range(fi([], is_signed, word_length, 0));
要查找斜率和偏置,请求解方程组:
lower_bound = slope * q_min bias
upper_bound = slope * q_max bias
以矩阵形式重写这些方程。
求解斜率和偏置。
a = double ([q_min, 1; q_max, 1]); b = double ([lower_bound; upper_bound]); x = a\b; format long g
要查找斜率或精度,请调用斜率偏置向量 x 的第一个元素。
slope = x(1)
slope =
1.52590218966964e-05要查找偏置,请调用向量 x 的第二个元素。
bias = x(2)
bias =
999.500007629511创建一个具有斜率偏置定标的 numerictype 对象。
t = numerictype(is_signed, word_length, slope, bias)
t =
datatypemode: fixed-point: slope and bias scaling
signedness: signed
wordlength: 16
slope: 1.5259021896696368e-5
bias: 999.500007629511创建一个 numerictype 为 t 的 fi 对象。
a = fi(999.255, t)
a =
999.254993514916
datatypemode: fixed-point: slope and bias scaling
signedness: signed
wordlength: 16
slope: 1.5259021896696368e-5
bias: 999.500007629511通过查找 a 的范围,验证您创建的 fi 对象是否具有正确的设定。
range(a)
ans =
999 1000
datatypemode: fixed-point: slope and bias scaling
signedness: signed
wordlength: 16
slope: 1.5259021896696368e-5
bias: 999.500007629511