biased vs unbiased rounding

 

biased rounding un-biased rounding:

1. 正數的時候 行為一樣 1-4 round down, 5-9 round up
>> HW上是看到1就進位
ex. S0.8 ([8:0]) roundS0.3
[4]1: [8:5]+1
[4]0: [8:5]
2. 負數的時候
biased rounding和正數一樣行為
ex. S0.8 ([8:0]) roundS0.3
[4]1: [8:5]+1
[4]0: [8:5]
unbiased rounding要多判斷後面的位數
ex. S0.8 ([8:0]) roundS0.3
[4]1 && [3:0]有任意1:          [8:5]+1
[4]0 || ([4]1 && [3:0]0): [8:5]

 

可以參考下面這個例子 :只有-1.5的case有差別。

 
 
 

 

S4.4

S4.0 biased

S4.0 unbiased

-1

111110000

11111

11111

-1.25

111101100

11111

11111

-1.5

111101000

11111 (-1)

11110 (-2)

-1.75

111100100

11110

11110

-2

111100000

11110

11110

 

signed numbers addition overflow process:

eg. s2.0 + s2.0 = s3.0  to avoid overflow 

   [-4]  |     1 0 0

+ [-1]  |     1 1 1

= [-5]  |   1 0 1 1   

 

 

=====================================background knowledge=======================

signed number overflow:

a[N-1:0].   only bit[N-1] and bit[N-2] both have carry, then result does NOT overflow;  otherwise, viseverse.

OF = Cn-1 xor Cn-2 

eg.1

 [+2]cplmnt = 010

 [+3]cplmnt = 011

=[-3]cplment=101   (OF=0 xor 1=1, overflow)

eg.2

  [-2] = 110

  [-3] = 101

=[+3]= 011    (OF=1 xor 0=1, overflow)

 

發佈了18 篇原創文章 · 獲贊 9 · 訪問量 4萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章