I am trying to compare 2 doubles which fall in [0.0, 1.0].
My function (taken from https://stackoverflow.com/a/17341 )-
inline bool isEqual(double x, double y)
{
const double epsilon = 0.000001;
return fabs(x - y) < epsilon;
}
Usage-
cerr << isEqual(1.000001, 1.000002) << endl;
cerr << isEqual(1.000010, 1.000020) << endl;
The output is-
0
0
Whereas I am expecting first to be true
, second to be false
. Please tell me where I am going wrong and how to fix it?