Prev Next a_double_unary_fun_xam.cpp Headings

@(@\newcommand{\B}[1]{ {\bf #1} } \newcommand{\R}[1]{ {\rm #1} }@)@
C++: a_double Unary Functions with AD Result: Example and Test
// This test fails in Octave and so is skipped by make check_lib_octave
# include <cstdio>
# include <string>
# include <cppad/swig/cppad_swig.hpp>

bool a_double_unary_fun_xam(void) {
     using cppad_swig::a_double;
     using cppad_swig::vec_bool;
     using cppad_swig::vec_int;
     using cppad_swig::vec_double;
     using cppad_swig::vec_a_double;
     using cppad_swig::a_fun;
     using cppad_swig::sparse_rc;
     using cppad_swig::sparse_rcv;
     using cppad_swig::sparse_jac_work;
     using cppad_swig::sparse_hes_work;
     using std::string;
     //
     // initialize return variable
     bool ok = true;
     //------------------------------------------------------------------------
     //
     // fabs
     a_double one = cppad_swig::a_double(1.0);
     a_double abs_one = one.fabs();
     ok = ok && abs_one.value() == 1.0;
     //
     // pi/4
     a_double pi_4 = one.atan();
     //
     // sqrt(2)
     a_double tmp = cppad_swig::a_double(2.0);
     a_double r2 = tmp.sqrt();
     //
     // sin(pi/4)  * sqrt(2) = 1.0;
     tmp = r2 * pi_4.sin() ;
     ok = ok && tmp.near_equal(one) ;
     //
     // cos(pi/4)  * sqrt(2) = 1.0;
     tmp = r2 * pi_4.cos() ;
     ok = ok && tmp.near_equal(one) ;
     //
     // tan(pi/4)  = 1.0;
     tmp = pi_4.tan() ;
     ok = ok && tmp.near_equal(one) ;
     //
     return( ok );
}

Input File: build/lib/example/cplusplus/a_double_unary_fun_xam.cpp