r
The relative error criteria r has prototype
double r It must be greater than or equal zero.
The relative error condition is satisfied if
\[
| x - y | \leq r ( |x| + |y| )
\]
where \leq
denotes less than or equal.
a
The absolute error criteria a has prototype
double a It must be greater than or equal zero.
The absolute error condition is satisfied if
\[
| x - y | \leq a
\]
e
The return value e has prototype
int e If either the relative or absolute error condition is satisfied,
it is one.
Otherwise, it is zero.
Example
The following is an example and test of near_equal_c,
it returns true if the test succeeds and false if it fails:
// This extern statement should be in an include file so that it can be
// included and checked by near_equal_c.c.
extern int near_equal_c(double x, double y, double r, double a);
int ok_near_equal_c()
{ double x = 1.1;
double y = 1.2;
double r = .1;
double a = 0.;
if( near_equal_c(x, y, r, a) )
return 1; // expected return value (true)
else return 0; // error return value (false)
}