The base value for epsilon is the difference between 1.0and the next highest represented value. In C ++, this value is available as std::numeric_limits<T>::epsilon().
, , , , . , , , :
double epsilon = std::numeric_limits<double>::epsilon();
bool is_near = abs(0.1+0.2 - 0.3) < 0.3 * (2*epsilon);
:
bool is_approximately_equal(double a, double b) {
double scale = max(abs(a), abs(b));
return abs(a - b) < scale * (2*epsilon);
}
, , , , . ( ), . - characteristic_value * epsilon.