biased rounding 跟 un-biased rounding:
•1. 正數的時候 行為一樣 1-4 round down, 5-9 round up
•>> 在HW上是看到1就進位
•ex. S0.8 ([8:0]) 要 round到S0.3
•[4]是1: [8:5]+1
•[4]是0: [8:5]
•
•2. 負數的時候
•biased rounding和正數一樣行為
•ex. S0.8 ([8:0]) 要 round到S0.3
•[4]是1: [8:5]+1
•[4]是0: [8:5]
•
•
•unbiased rounding要多判斷後面的位數
•ex. S0.8 ([8:0]) 要 round到S0.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)