2023年12月15日 星期五

Rounding

Rounding 是用較短的、簡單的、或 more explicit 的近似值表示數值,例如 $23.4476 用 $23.45, 表示、,the fraction 312/937 用 1/3 表示,或 √2 用 1.414 表示。

捨棄低位元時,增加尾數 0 或減少小數位數,決定是否進位。

round down:捨去,是指 round toward zero,但在 2’s complement 數值會是 round toward negative infinity,負值是有所不同。

round up:進位。

round toward zero:無條件捨去法。正數捨去低位元是變小,負數捨去低位元是捨去一些負值而變大,所以都是趨向 0。ROUNDDOWN() truncate()

round away from zero:無條件進位法。捨去低位元時一律進位,正數是變大,負數是變小,所以都是遠離 0。ROUNDUP()

round toward negative infinity:程式的無條件捨去法。一般程式數值用 2’s complement,正數捨去低位元是變小,負數捨去低位元也是變小。floor()

round half down

round half up

round half toward zero (五捨六入)

round half away from zero (四捨五入)

round half toward even (四捨六入五成雙)

round half toward odd

round half alternatively

round half randomly

stochastic round

參考

  1. https://en.wikipedia.org/wiki/Rounding

truncation:無條件捨去法
round (round-to-nearest)

  • 傳統是四捨五入,只看一位是五就進位,其實五居中 (biased rounding)
  • convergent rounding:不只看一位
  • unbiased rounding:如果剛好居中,只會變成是偶數。

沒有留言:

張貼留言

SIP header Via

所有 SIP 訊息 都要有 Via,縮寫 v。一開始的 UAC 和後續途經的每個 proxy 都會疊加一個 Via 放傳送的位址,依序作為回應的路徑。 格式 sent-protocol sent-by [ ;branch= branch ][ ; 參數 ...] s...