Efficiently computing (a - K) / (a + K) with improved accuracy

后端 未结 6 1756
抹茶落季
抹茶落季 2021-02-18 15:44

In various contexts, for example for the argument reduction for mathematical functions, one needs to compute (a - K) / (a + K), where a is a positive v

6条回答
  •  粉色の甜心
    2021-02-18 16:16

    If a is large compared to K, then (a-K)/(a+K) = 1 - 2K / (a + K) will give a good approximation. If a is small compared to K, then 2a / (a + K) - 1 will give a good approximation. If K/2 ≤ a ≤ 2K, then a-K is an exact operation, so doing the division will give a decent result.

提交回复
热议问题