<?xml version='1.0'?>
<html xmlns='http://www.w3.org/1999/xhtml'
      xmlns:math='http://www.w3.org/1998/Math/MathML'
>
<head>
<title>Compare AD and Base Objects for Nearly Equal</title>
<meta name="description" id="description" content="Compare AD and Base Objects for Nearly Equal"/>
<meta name="keywords" id="keywords" content=" Nearequal Ad with Base "/>
<style type='text/css'>
body { color : black }
body { background-color : white }
A:link { color : blue }
A:visited { color : purple }
A:active { color : purple }
</style>
<script type='text/javascript' language='JavaScript' src='_nearequalext_xml.js'>
</script>
</head>
<body>
<table><tr>
<td>
<a href="http://www.coin-or.org/CppAD/" target="_top"><img border="0" src="_image.gif"/></a>
</td>
<td><a href="compare.cpp.xml" target="_top">Prev</a>
</td><td><a href="near_equal_ext.cpp.xml" target="_top">Next</a>
</td><td>
<select onchange='choose_across0(this)'>
<option>Index-&gt;</option>
<option>contents</option>
<option>reference</option>
<option>index</option>
<option>search</option>
<option>external</option>
</select>
</td>
<td>
<select onchange='choose_up0(this)'>
<option>Up-&gt;</option>
<option>CppAD</option>
<option>AD</option>
<option>BoolValued</option>
<option>NearEqualExt</option>
</select>
</td>
<td>
<select onchange='choose_down3(this)'>
<option>CppAD-&gt;</option>
<option>Install</option>
<option>Introduction</option>
<option>AD</option>
<option>ADFun</option>
<option>preprocessor</option>
<option>multi_thread</option>
<option>library</option>
<option>ipopt_solve</option>
<option>Example</option>
<option>speed</option>
<option>Appendix</option>
</select>
</td>
<td>
<select onchange='choose_down2(this)'>
<option>AD-&gt;</option>
<option>ad_ctor</option>
<option>ad_assign</option>
<option>Convert</option>
<option>ADValued</option>
<option>BoolValued</option>
<option>VecAD</option>
<option>base_require</option>
</select>
</td>
<td>
<select onchange='choose_down1(this)'>
<option>BoolValued-&gt;</option>
<option>Compare</option>
<option>NearEqualExt</option>
<option>BoolFun</option>
<option>ParVar</option>
<option>EqualOpSeq</option>
</select>
</td>
<td>
<select onchange='choose_down0(this)'>
<option>NearEqualExt-&gt;</option>
<option>near_equal_ext.cpp</option>
</select>
</td>
<td>
<select onchange='choose_current0(this)'>
<option>Headings-&gt;</option>
<option>Syntax</option>
<option>Purpose</option>
<option>x</option>
<option>y</option>
<option>r</option>
<option>a</option>
<option>b</option>
<option>Type</option>
<option>Operation Sequence</option>
<option>Example</option>
</select>
</td>
</tr></table><br/>



<center><b><big><big>Compare AD and Base Objects for Nearly Equal</big></big></b></center>
<br/>
<b><big><a name="Syntax" id="Syntax">Syntax</a></big></b>

<br/>

<code><i><font color="black"><span style='white-space: nowrap'>b</span></font></i><font color="blue"><span style='white-space: nowrap'>&#xA0;=&#xA0;NearEqual(</span></font><i><font color="black"><span style='white-space: nowrap'>x</span></font></i><font color="blue"><span style='white-space: nowrap'>,&#xA0;</span></font><i><font color="black"><span style='white-space: nowrap'>y</span></font></i><font color="blue"><span style='white-space: nowrap'>,&#xA0;</span></font><i><font color="black"><span style='white-space: nowrap'>r</span></font></i><font color="blue"><span style='white-space: nowrap'>,&#xA0;</span></font><i><font color="black"><span style='white-space: nowrap'>a</span></font></i><font color="blue"><span style='white-space: nowrap'>)</span></font></code>



<br/>
<br/>
<b><big><a name="Purpose" id="Purpose">Purpose</a></big></b>
<br/>
The routine <a href="nearequal.xml" target="_top"><span style='white-space: nowrap'>NearEqual</span></a>
 determines if two objects of
the same type are nearly.
This routine is extended to the case where one object can have type

<code><i><font color="black"><span style='white-space: nowrap'>Type</span></font></i></code>
 while the other can have type

<code><font color="blue"><span style='white-space: nowrap'>AD&lt;</span></font><i><font color="black"><span style='white-space: nowrap'>Type</span></font></i><font color="blue"><span style='white-space: nowrap'>&gt;</span></font></code>
 or

<code><font color="blue"><span style='white-space: nowrap'>AD&lt;&#xA0;std::complex&lt;</span></font><i><font color="black"><span style='white-space: nowrap'>Type</span></font></i><font color="blue"><span style='white-space: nowrap'>&gt;&#xA0;&gt;</span></font></code>
.

<br/>
<br/>
<b><big><a name="x" id="x">x</a></big></b>
<br/>
The arguments 
<code><i><font color="black"><span style='white-space: nowrap'>x</span></font></i></code>
 
has one of the following possible prototypes:

<code><font color="blue"><span style='white-space: nowrap'><br/>
&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;const&#xA0;</span></font><i><font color="black"><span style='white-space: nowrap'>Type</span></font></i><font color="blue"><span style='white-space: nowrap'>&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&amp;</span></font><i><font color="black"><span style='white-space: nowrap'>x</span></font></i><font color="blue"><span style='white-space: nowrap'><br/>
&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;const&#xA0;AD&lt;</span></font><i><font color="black"><span style='white-space: nowrap'>Type</span></font></i><font color="blue"><span style='white-space: nowrap'>&gt;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&amp;</span></font><i><font color="black"><span style='white-space: nowrap'>x</span></font></i><font color="blue"><span style='white-space: nowrap'><br/>
&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;const&#xA0;AD&lt;&#xA0;std::complex&lt;</span></font><i><font color="black"><span style='white-space: nowrap'>Type</span></font></i><font color="blue"><span style='white-space: nowrap'>&gt;&#xA0;&gt;&#xA0;&amp;</span></font><i><font color="black"><span style='white-space: nowrap'>x</span></font></i><font color="blue"><span style='white-space: nowrap'><br/>
</span></font></code>
<br/>
<b><big><a name="y" id="y">y</a></big></b>
<br/>
The arguments 
<code><i><font color="black"><span style='white-space: nowrap'>y</span></font></i></code>
 
has one of the following possible prototypes:

<code><font color="blue"><span style='white-space: nowrap'><br/>
&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;const&#xA0;</span></font><i><font color="black"><span style='white-space: nowrap'>Type</span></font></i><font color="blue"><span style='white-space: nowrap'>&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&amp;</span></font><i><font color="black"><span style='white-space: nowrap'>y</span></font></i><font color="blue"><span style='white-space: nowrap'><br/>
&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;const&#xA0;AD&lt;</span></font><i><font color="black"><span style='white-space: nowrap'>Type</span></font></i><font color="blue"><span style='white-space: nowrap'>&gt;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&amp;</span></font><i><font color="black"><span style='white-space: nowrap'>y</span></font></i><font color="blue"><span style='white-space: nowrap'><br/>
&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;const&#xA0;AD&lt;&#xA0;std::complex&lt;</span></font><i><font color="black"><span style='white-space: nowrap'>Type</span></font></i><font color="blue"><span style='white-space: nowrap'>&gt;&#xA0;&gt;&#xA0;&amp;</span></font><i><font color="black"><span style='white-space: nowrap'>x</span></font></i><font color="blue"><span style='white-space: nowrap'><br/>
</span></font></code>
<br/>
<b><big><a name="r" id="r">r</a></big></b>
<br/>
The relative error criteria 
<code><i><font color="black"><span style='white-space: nowrap'>r</span></font></i></code>
 has prototype

<code><font color="blue"><span style='white-space: nowrap'><br/>
&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;const&#xA0;</span></font><i><font color="black"><span style='white-space: nowrap'>Type</span></font></i><font color="blue"><span style='white-space: nowrap'>&#xA0;&amp;</span></font><i><font color="black"><span style='white-space: nowrap'>r</span></font></i><font color="blue"><span style='white-space: nowrap'><br/>
</span></font></code>
It must be greater than or equal to zero.
The relative error condition is defined as:

<math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><mrow>
<mfrac><mrow><mo stretchy="false">|</mo>
<mi mathvariant='italic'>x</mi>
<mo stretchy="false">-</mo>
<mi mathvariant='italic'>y</mi>
<mo stretchy="false">|</mo>
</mrow>
<mrow><mo stretchy="false">|</mo>
<mi mathvariant='italic'>x</mi>
<mo stretchy="false">|</mo>
<mo stretchy="false">+</mo>
<mo stretchy="false">|</mo>
<mi mathvariant='italic'>y</mi>
<mo stretchy="false">|</mo>
</mrow>
</mfrac>
<mo stretchy="false">&#x02264;</mo>
<mi mathvariant='italic'>r</mi>
</mrow></math>

<br/>
<b><big><a name="a" id="a">a</a></big></b>
<br/>
The absolute error criteria 
<code><i><font color="black"><span style='white-space: nowrap'>a</span></font></i></code>
 has prototype

<code><font color="blue"><span style='white-space: nowrap'><br/>
&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;const&#xA0;</span></font><i><font color="black"><span style='white-space: nowrap'>Type</span></font></i><font color="blue"><span style='white-space: nowrap'>&#xA0;&amp;</span></font><i><font color="black"><span style='white-space: nowrap'>a</span></font></i><font color="blue"><span style='white-space: nowrap'><br/>
</span></font></code>
It must be greater than or equal to zero.
The absolute error condition is defined as:

<math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><mrow>
<mo stretchy="false">|</mo>
<mi mathvariant='italic'>x</mi>
<mo stretchy="false">-</mo>
<mi mathvariant='italic'>y</mi>
<mo stretchy="false">|</mo>
<mo stretchy="false">&#x02264;</mo>
<mi mathvariant='italic'>a</mi>
</mrow></math>

<br/>
<b><big><a name="b" id="b">b</a></big></b>
<br/>
The return value 
<code><i><font color="black"><span style='white-space: nowrap'>b</span></font></i></code>
 has prototype

<code><font color="blue"><span style='white-space: nowrap'><br/>
&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;bool&#xA0;</span></font><i><font color="black"><span style='white-space: nowrap'>b</span></font></i><font color="blue"><span style='white-space: nowrap'><br/>
</span></font></code>
If either 
<code><i><font color="black"><span style='white-space: nowrap'>x</span></font></i></code>
 or 
<code><i><font color="black"><span style='white-space: nowrap'>y</span></font></i></code>
 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.

<br/>
<br/>
<b><big><a name="Type" id="Type">Type</a></big></b>
<br/>
The type 
<code><i><font color="black"><span style='white-space: nowrap'>Type</span></font></i></code>
 must be a
<a href="numerictype.xml" target="_top"><span style='white-space: nowrap'>NumericType</span></a>
.
The routine <a href="checknumerictype.xml" target="_top"><span style='white-space: nowrap'>CheckNumericType</span></a>
 will generate
an error message if this is not the case.
If 
<code><i><font color="black"><span style='white-space: nowrap'>a</span></font></i></code>
 and 
<code><i><font color="black"><span style='white-space: nowrap'>b</span></font></i></code>
 have type 
<code><i><font color="black"><span style='white-space: nowrap'>Type</span></font></i></code>
,
the following operation must be defined 
<table><tr><td align='left'  valign='top'>

<b>Operation</b>     </td><td align='left'  valign='top'>
 
	<b>Description</b> </td></tr><tr><td align='left'  valign='top'>


<code><i><font color="black"><span style='white-space: nowrap'>a</span></font></i><font color="blue"><span style='white-space: nowrap'>&#xA0;&lt;=&#xA0;</span></font><i><font color="black"><span style='white-space: nowrap'>b</span></font></i></code>
  </td><td align='left'  valign='top'>
 
	less that or equal operator (returns a <code><font color="blue">bool</font></code> object)
</td></tr>
</table>
<br/>
<b><big><a name="Operation Sequence" id="Operation Sequence">Operation Sequence</a></big></b>
<br/>
The result of this operation is not an
<a href="glossary.xml#AD of Base" target="_top"><span style='white-space: nowrap'>AD&#xA0;of&#xA0;Base</span></a>
 object.
Thus it will not be recorded as part of an
AD of 
<code><i><font color="black"><span style='white-space: nowrap'>Base</span></font></i></code>

<a href="glossary.xml#Operation.Sequence" target="_top"><span style='white-space: nowrap'>operation&#xA0;sequence</span></a>
.

<br/>
<br/>
<b><big><a name="Example" id="Example">Example</a></big></b>

<br/>
The file <a href="near_equal_ext.cpp.xml" target="_top"><span style='white-space: nowrap'>near_equal_ext.cpp</span></a>
 contains an example
and test of this extension of <a href="nearequal.xml" target="_top"><span style='white-space: nowrap'>NearEqual</span></a>
.
It return true if it succeeds and false otherwise.


<hr/>Input File: cppad/local/near_equal_ext.hpp

</body>
</html>
