Do-s and Don't-s for floating point arithmetic?

后端 未结 7 1934
臣服心动
臣服心动 2021-02-13 16:32

What are some good do-s and don\'t-s for floating point arithmetic (IEEE754 in case there\'s confusion) to ensure good numerical stability and high accuracy in your results?

7条回答
  •  感情败类
    2021-02-13 16:43

    DO understand how floating point behave.

    DON'T believe that simple rules will be enough to use them correctly.

    For instance, at least two answers proposed that comparing floating point for equality should be prohibited. First there are cases where comparing them for equality is what is needed. Then when doing range check is what is needed, you also need to be aware that it has its pitfall, for example it isn't transitive which is a property most people will assume for equality test.

提交回复
热议问题