I have a very simple code and I don't understad it's result.
I think, this have to print "OK" but does not!
#include<iostream>
#include<math.h>
class real
{
double value;
double error;
public:
real(double,double);
friend bool operator==(const real&,const double);
};
real::real(double val, double err) : value(val), error(fabs(err)) {}
bool operator==(const real& x1, const double x2)
{
// after substituting: 0.1 <= 0.1 is true!
return fabs(x2-x1.value) <= x1.error;
}
int main()
{
real x(1.1,0.1);
if (x == 1.0) std::cout << "OK" << std::endl;
return 0;
}
Any idea?