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