comparison of floating point values


//code

int testFunc(double value)

double test = 0.0;

if(val<=test)
std::cout<<"Both are Equal"<<std::endl;


///

The if loop may result to true if value ==0 but comparison of floating point values are not proper and violate the coding standard.
How can I carry out such a comparison??????????

Regards,
Sanjib
fabs(a-b) < epsilon
Also ensure that floating point is really what you want.
Depending on the application, sometimes Decimal is more appropriate and you can avoid these issues.
For example, for money values, you want to use Decimal and not floating point.
Topic archived. No new replies allowed.