Prev Next Index-> contents reference index search external Up-> CppAD utility NearEqual CppAD-> Install Introduction AD ADFun preprocessor multi_thread utility ipopt_solve Example speed Appendix utility-> ErrorHandler NearEqual speed_test SpeedTest time_test test_boolofvoid NumericType CheckNumericType SimpleVector CheckSimpleVector nan pow_int Poly LuDetAndSolve RombergOne RombergMul Runge45 Rosen34 OdeErrControl OdeGear OdeGearControl CppAD_vector thread_alloc index_sort to_string set_union sparse_rc sparse_rcv NearEqual-> near_equal.cpp Headings-> Syntax Purpose x y r a b Type Include Files Example Exercise

$\newcommand{\W}[1]{ \; #1 \; } \newcommand{\R}[1]{ {\rm #1} } \newcommand{\B}[1]{ {\bf #1} } \newcommand{\D}[2]{ \frac{\partial #1}{\partial #2} } \newcommand{\DD}[3]{ \frac{\partial^2 #1}{\partial #2 \partial #3} } \newcommand{\Dpow}[2]{ \frac{\partial^{#1}}{\partial {#2}^{#1}} } \newcommand{\dpow}[2]{ \frac{ {\rm d}^{#1}}{{\rm d}\, {#2}^{#1}} }$
Determine if Two Values Are Nearly Equal

Syntax
# include <cppad/utility/near_equal.hpp>  b = NearEqual(x, y, r, a)

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

x
The argument x has one of the following possible prototypes       const Type               &x,      const std::complex<Type> &x, 
y
The argument y has one of the following possible prototypes       const Type               &y,      const std::complex<Type> &y, 
r
The relative error criteria r has prototype       const Type &r  It must be greater than or equal to zero. The relative error condition is defined as: $$| x - y | \leq r ( |x| + |y| )$$

a
The absolute error criteria a has prototype       const Type &a  It must be greater than or equal to zero. The absolute error condition is defined as: $$| x - y | \leq a$$

b
The return value b has prototype       bool b  If either x or y is infinite or not a number, the return value is false. Otherwise, if either the relative or absolute error condition (defined above) is satisfied, the return value is true. Otherwise, the return value is false.

Type
The type Type must be a NumericType . The routine CheckNumericType will generate an error message if this is not the case. In addition, the following operations must be defined objects a and b of type Type :
 Operation Description a <= b less that or equal operator (returns a bool object)

Include Files
The file cppad/near_equal.hpp is included by cppad/cppad.hpp but it can also be included separately with out the rest of the CppAD routines.

Example
The file near_equal.cpp contains an example and test of NearEqual. It return true if it succeeds and false otherwise.

Exercise
Create and run a program that contains the following code:  using std::complex; using std::cout; using std::endl; complex<double> one(1., 0), i(0., 1); complex<double> x = one / i; complex<double> y = - i; double r = 1e-12; double a = 0; bool ok = CppAD::NearEqual(x, y, r, a); if( ok ) cout << "Ok" << endl; else cout << "Error" << endl;