Floating Point, how much can I trust less than / greater than comparisons?

前端 未结 5 1364
死守一世寂寞
死守一世寂寞 2021-02-19 04:08

Let\'s say I have two floating point numbers, and I want to compare them. If one is greater than the other, the program should take one fork. If the opposite is true, it should

5条回答
  •  既然无缘
    2021-02-19 04:54

    Short answer, it is guaranteed never to be called.

    If a then a will always be less than b plus a positive amount, however small. In which case, testing if a is less than b + an amount will be true.

    The third case won't get reached.

提交回复
热议问题