<?xml version='1.0'?>
<?xml-stylesheet type='text/xsl' href='pmathml.xsl'?>
<html xmlns='http://www.w3.org/1999/xhtml'>
<head>
<title>Convert From AD to Integer: Example and Test</title>
<meta name="description" id="description" content="Convert From AD to Integer: Example and Test"/>
<meta name="keywords" id="keywords" content=" Integer example test "/>
<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='_integer.cpp_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="integer.xml" target="_top">Prev</a>
</td><td><a href="output.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>Convert</option>
<option>Integer</option>
<option>Integer.cpp</option>
</select>
</td>
<td>
<select onchange='choose_down3(this)'>
<option>AD-&gt;</option>
<option>Default</option>
<option>ad_copy</option>
<option>Convert</option>
<option>ADValued</option>
<option>BoolValued</option>
<option>VecAD</option>
<option>base_require</option>
</select>
</td>
<td>
<select onchange='choose_down2(this)'>
<option>Convert-&gt;</option>
<option>Value</option>
<option>Integer</option>
<option>Output</option>
<option>PrintFor</option>
<option>Var2Par</option>
</select>
</td>
<td>
<select onchange='choose_down1(this)'>
<option>Integer-&gt;</option>
<option>Integer.cpp</option>
</select>
</td>
<td>Integer.cpp</td>
<td>Headings</td>
</tr></table><br/>



<center><b><big><big>Convert From AD to Integer: Example and Test</big></big></b></center>
<code><font color="blue"><pre style='display:inline'> 

# include &lt;cppad/cppad.hpp&gt;

bool Integer(void)
{	bool ok = true;
	using CppAD::AD;
	using CppAD::Integer;

	// domain space vector
	size_t n = 2;
	<a href="test_vector.xml" target="_top">CPPAD_TEST_VECTOR</a>&lt; <a href="ad.xml" target="_top">AD</a>&lt;double&gt; &gt; x(n);
	x[0] = 3.5;
	x[1] = 4.5;

	// check integer before recording
	ok &amp;= (Integer(x[0]) == 3);
	ok &amp;= (Integer(x[1]) == 4);

	// start recording

	// declare independent variables and start tape recording
	CppAD::<a href="independent.xml" target="_top">Independent</a>(x);

	// check integer during recording
	ok &amp;= (Integer(x[0]) == 3);
	ok &amp;= (Integer(x[1]) == 4);

	// check integer for VecAD element
	CppAD::VecAD&lt;double&gt; v(1);
	<a href="ad.xml" target="_top">AD</a>&lt;double&gt; zero(0);
	v[zero] = 2;
	ok &amp;= (Integer(v[zero]) == 2);

	// range space vector 
	size_t m = 1;
	<a href="test_vector.xml" target="_top">CPPAD_TEST_VECTOR</a>&lt; <a href="ad.xml" target="_top">AD</a>&lt;double&gt; &gt; y(m);
	y[0] = - x[1];

	// create f: x -&gt; y and stop recording
	CppAD::<a href="funconstruct.xml" target="_top">ADFun</a>&lt;double&gt; f(x, y);

	// check integer after recording
	ok &amp;= (Integer(x[0]) ==  3.);
	ok &amp;= (Integer(x[1]) ==  4.);
	ok &amp;= (Integer(y[0]) == -4.);

	return ok;
}
</pre>

</font></code>


<hr/>Input File: example/integer.cpp

</body>
</html>

