1 /* epsilon-equal.c: define a error resist compare. */ 2 3 #include <math.h> 4 5 #include "epsilon-equal.h" 6 7 /* Numerical errors sometimes make a floating point number just slightly 8 larger or smaller than its true value. When it matters, we need to 9 compare with some tolerance, REAL_EPSILON, defined in kbase.h. */ 10 11 bool epsilon_equal(float const v1,float const v2)12epsilon_equal(float const v1, 13 float const v2) { 14 15 return 16 v1 == v2 /* Usually they'll be exactly equal, anyway. */ 17 || fabs(v1 - v2) <= REAL_EPSILON; 18 } 19 20