为了在C语言中比较两个双精度浮点型变量,我定义了一个
#define EQUALITY_EPSILON = 1e-8
。进行比较的方法如下:if((img_score[i] - img_score[j]) >= EQUALITY_EPSILON){
// handle for ith score greater than jth score
}
else if((img_score[j] - img_score[i]) >= EQUALITY_EPSILON){
// handle for ith score smaller than jth score
}
else{
// handle for ith score equal to jth score
}
我面临的问题是,我的代码得分非常小,因此对于 EQUALITY_EPSILON = 1e-8
,在某些情况下比较的结果会变成相等。我的问题是我可以将 EQUALITY_EPSILON
设定得多小?