## 计算斜率和偏置

### 什么是斜率偏置定标

`$real\text{-}worldvalue=\left(slope×integer\right)+bias$`

`$slope=slopeadjustmentfactor×{2}^{fixedexponent}$`

### 计算斜率和偏置

```lower_bound = 999; upper_bound = 1000; is_signed = true; word_length = 16;```

`[Q_min, Q_max] = range(fi([], is_signed, word_length, 0));`

`lower_bound = slope * Q_min + bias `

`upper_bound = slope * Q_max + bias`

`$\left[\begin{array}{c}\text{lower_bound}\\ \text{upper_bound}\end{array}\right]\text{=}\left[\begin{array}{cc}\text{Q_min}& \text{1}\\ \text{Q_max}& \text{1}\end{array}\right]\text{×}\left[\begin{array}{c}\text{slope}\\ \text{bias}\end{array}\right]$`

```A = double ([Q_min, 1; Q_max, 1]); b = double ([lower_bound; upper_bound]); x = A\b; format long g```

`slope = x(1)`
```slope = 1.52590218966964e-05```

`bias = x(2)`
```bias = 999.500007629511```

`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```

`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```

`range(a)`
```ans = 999 1000 DataTypeMode: Fixed-point: slope and bias scaling Signedness: Signed WordLength: 16 Slope: 1.5259021896696368e-5 Bias: 999.500007629511```