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