by ehutch79 · 14y ago · 0 comments
The best thing to do here would be to use an inline comparison function with a threshold:
inline bool is_equal(double a, double b, double threshold = 0.0000001f)
{
if ( abs(a-b) < threshold )
{
return true;
}
else
{
return false;
}
}
Unfortunately, compounding floating point operations can drastically reduce calculation accuracy, leading to requiring a greater threshold value... Which is why I highly recommend reading the article titled "What Every Computer Scientist Should Know About Floating-Point Arithmetic" by David Goldberg (circa 1991, available at http://docs.oracle.com/cd/E19957-01/806-3568/ncg_goldberg.ht...).