C ++ comparison floating point data type is equal to (float double)

bool isE(double a,double b)
{
    if(fabs(a-b)<1e-6)
        return true;
    else
        return false;     
} 

abs () // find the absolute value of type int

fabs () // absolute value of the floating-point

bool Equal(double a, double b)
{
    if((a- b > -0.0000001) && (a - b < 0.0000001))
        return true;
    else
        return false;
}

 

Guess you like

Origin www.cnblogs.com/didiaoxiaoguai/p/11545041.html