Prev Next Index-> contents reference index search external Up-> overview get_started start_embed near_equal_c overview-> License why Install get_started running files titles+headings cross format spellchecking latex other browser glossary wish_list whatsNew get_started-> start_simple start_head start_image start_pre start_font start_spell start_latex start_verbatim start_src start_embed start_multiple start_cref start_index start_embed-> view_near_equal_c near_equal_c view_near_equal_f near_equal_f near_equal_c Headings-> Syntax Purpose x y r a e Example

Determine if Two Values Are Nearly Equal

Syntax
e = near_equal_c(x, y, r, a)

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:  // 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) } 
Input File: getstarted/near_equal_c.c