Main Content

기울기 및 편향 계산하기

기울기 편향 스케일링이란?

기울기 편향 스케일링을 사용할 경우 숫자의 편향과 기울기를 지정해야 합니다. 기울기 편향 스케일링된 숫자의 실제 값은 다음과 같이 표현될 수 있습니다.

real-world value=(slope×integer)+bias

slope=slope adjustment factor×2fixed exponent

기울기 및 편향 계산하기

원하는 끝점과 부호의 유무, 워드 길이로 시작합니다.

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

지정된 워드 길이와 부호의 유무가 적용된 fi 객체의 범위를 찾기 위해 range 함수를 사용합니다.

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

기울기 및 편향을 구하기 위해 다음 연립방정식을 풉니다.

lower_bound = slope * Q_min + bias

upper_bound = slope * Q_max + bias

이 방정식을 다음과 같이 행렬 형식으로 다시 작성합니다.

[lower_boundupper_bound]=[Q_min1Q_max1]×[slopebias]

기울기 및 편향을 구합니다.

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