How to correctly and standardly compare floats?

后端 未结 8 1354
夕颜
夕颜 2020-11-27 04:30

Every time I start a new project and when I need to compare some float or double variables I write the code like this one:

if (fabs(prev.min[i] - cur->min         


        
8条回答
  •  离开以前
    2020-11-27 04:50

    The Standard provides an epsilon value. It's in and you can access the value by std::numeric_limits::epsilon and std::numeric_limits::epsilon. There are other values in there, but I didn't check what exactly is.

提交回复
热议问题