Prev Next near_equal_c

Determine if Two Values Are Nearly Equal

Syntax
Purpose
x
y
r
a
e
Example

Syntax
e = near_equal_c(xyra)

Purpose
Returns true, if x is nearly equal to y and false otherwise.

x
The argument x has prototype
     double 
x

y
The argument y has prototype
     double 
y

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:
 
     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)
     }

Input File: omh/getstarted/near_equal_c.c