Compare double to zero using epsilon

后端 未结 11 1338
醉梦人生
醉梦人生 2020-11-29 15:54

Today, I was looking through some C++ code (written by somebody else) and found this section:

double someValue = ...
if (someValue <  std::numeric_limits&         


        
11条回答
  •  抹茶落季
    2020-11-29 16:35

    I think that depend on the precision of your computer. Take a look on this table: you can see that if your epsilon is represented by double, but your precision is higher, the comparison is not equivalent to

    someValue == 0.0
    

    Good question anyway!

提交回复
热议问题