Can you compare floating point values exactly to zero?

后端 未结 8 1326
一生所求
一生所求 2020-12-18 17:57

I know we can\'t compare 2 floating point values using ==. We can only compare they are within some interval of each other. I know

if(val == 0.512)
         


        
8条回答
  •  春和景丽
    2020-12-18 18:58

    I would still recommend following the tolerance idiom and not compare to zero exactly.

提交回复
热议问题