Thursday 13 June 2019

Comparing two floats/doubles in c++

I read that floats/doubles equality should be implemented using an interval (given by some epsilon):



bool aresame(double a, double b)
{
return (fabs(a-b) < EPSILON);
}


Is their any predefined value of EPSILON that I can use or do I have to define it myself, something like, 0.0000000001?

No comments:

Post a Comment

php - file_get_contents shows unexpected output while reading a file

I want to output an inline jpg image as a base64 encoded string, however when I do this : $contents = file_get_contents($filename); print &q...