machine precision and max and min value of a double-precision type

前端 未结 3 373
死守一世寂寞
死守一世寂寞 2021-01-16 07:16

(1) I have met several cases where epsilon is added to a non-negative variable to guarantee nonzero value. So I wonder why not add the minimum value that the data type can r

3条回答
  •  深忆病人
    2021-01-16 07:42

    1. Epsilons are added to test equality between two values that should be equal, but aren't because of rounding errors. While you could use the smallest positive value for epsilon, it wouldn't be optimal, because it's simply too small. The rounding errors caused by floating point arithmetic almost always exceed that smallest value, so a larger epsilon is needed. How large depends on your desired accuracy.

    2. I don't understand the question. Are the reciprocals useful for what? I can't think of any reason why they would be useful.

    3. In general, dividing by very small values is a bad idea as it will cause very large rounding errors. I'm not sure what you mean by adding an upper bound. Just avoid dividing by small values wherever possible.

提交回复
热议问题