Sunday, September 2, 2018

c++ - What is the most effective way for float and double comparison?

What would be the most efficient way to compare two double or two float values?



Simply doing this is not correct:



bool CompareDoubles1 (double A, double B)
{
return A == B;
}



But something like:



bool CompareDoubles2 (double A, double B) 
{
diff = A - B;
return (diff < EPSILON) && (-diff < EPSILON);
}



Seems to waste processing.



Does anyone know a smarter float comparer?

No comments:

Post a Comment

plot explanation - Why did Peaches&#39; mom hang on the tree? - Movies &amp; TV

In the middle of the movie Ice Age: Continental Drift Peaches' mom asked Peaches to go to sleep. Then, she hung on the tree. This parti...