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

前端 未结 5 1382
死守一世寂寞
死守一世寂寞 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

    Tests for inequality are exact, as are tests for equality. People get confused because they don't realize that the values they are working with might not be exactly what they think they are. So, yes, the comment on the final function call is correct. That branch will never be taken.

提交回复
热议问题