Prev Next near_equal_f

Determine if Two Values Are Nearly Equal

Syntax
e = near_equal_f(xyra)

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

x
The argument x has prototype
     double precision 
x

y
The argument y has prototype
     double precision 
y

r
The relative error criteria r has prototype
     double precision 
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 precision 
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
     logical 
e
If either the relative or absolute error condition is satisfied, it is true. Otherwise, it is false.

Example
The following is an example and test of near_equal_f. It returns true if the test succeeds and false if it fails.
 
c Use integer for return value so that this function is callable by C
      integer function ok_near_equal_f()
      double precision x, y, r, a
      logical near_equal_f
      external near_equal_f
      x = 1.1
      y = 1.2
      r = .1
      a = 0.
      if( near_equal_f(x, y, r, a) ) then
            ok_near_equal_f = 1
      else
            ok_near_equal_f = 0
      endif
      end

Input File: getstarted/near_equal_f.f