浮点数的比较方式,比较两个浮点数的大小,通过精度判断大小

bool Equal(double d1, double d2, double dEpsilon)
{
    if (abs(d1 - d2) < dEpsilon)
        return true;
    else
        return false;
}

bool GreaterThan(double value1, double value2, double dEpsilon)
{
        return value1 - value2 > dEpsilon;
}

bool GreaterEqualThan(double value1, double value2, double dEpsilon)
{
    return dEpsilon >= value2 - value1;
}

bool LessThan(double value1, double value2, double dEpsilon)
{
    return dEpsilon < value2 - value1;    
                                              
}

bool LessEqualThan(double value1, double value2, double dEpsilon)
{
    return value1 - value2 <= dEpsilon;
}
 

你可能感兴趣的:(C++,c++)