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
# include <cstdio>
# include <cppad/py/cppad_py.hpp>

bool a_double_unary_fun_xam(void) {
     using cppad_py::a_double;
     //
     // initialize return variable
     bool ok = true;
     //------------------------------------------------------------------------
     //
     // fabs
     a_double a1(1.0);
     a_double abs1 = a1.fabs();
     ok = ok && abs1 == 1.0;
     //
     // pi/4
     a_double pi_4 = a1.atan();
     //
     // sqrt(2)
     a_double atmp(2.0);
     a_double r2 = atmp.sqrt();
     //
     // sin(pi/4)  * sqrt(2) = 1.0;
     atmp = r2 * pi_4.sin() ;
     ok = ok && atmp.near_equal(a1) ;
     //
     // cos(pi/4)  * sqrt(2) = 1.0;
     atmp = r2 * pi_4.cos() ;
     ok = ok && atmp.near_equal(a1) ;
     //
     // tan(pi/4)  = 1.0;
     atmp = pi_4.tan() ;
     ok = ok && atmp.near_equal(a1) ;
     //
     return( ok );
}

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