py_near_equal

View page source

Python: Check That Values are Nearly Equal

Prototype

def near_equal(x, y, rel_error, vec = [], os = sys.stderr ) :

Nearly Equal

Checks if two values are nearly equal; i.e., if

   std::fabs(x - y) <= abs_error

where the absolute error abs_error is defined below.

Scalar

is the type of the operands we are checking.

x

is the left operand in the nearly equal check.

y

is the right operand in the nearly equal check.

rel_error

is the relative error used during the comparison.

vec

This vector specifies extra values to include when scaling the relative error. The default for this argument is an empty vector.

abs_error

  1. scale is the maximum of the absolute value of x, y , and the elements of vec

  2. tiny is the minimum positive normalized value of type Scalar

  3. abs_error is maximum of tiny and rel_error times scale .

os

If the values are not nearly equal, a messages is written to this stream describing the comparison failure. The default for this argument is standard error.

xam_near_equal.py contains an example and test of this routine.