source: trunk/test_more/std_math.cpp @ 1524

Last change on this file since 1524 was 1370, checked in by bradbell, 11 years ago

trunk: Fix svn_add_id.sh and use it set Id property for some missed files.

  • Property svn:keywords set to Id
File size: 1.7 KB
Line 
1/* $Id: std_math.cpp 1370 2009-05-31 05:31:50Z bradbell $ */
2/* --------------------------------------------------------------------------
3CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-07 Bradley M. Bell
4
5CppAD is distributed under multiple licenses. This distribution is under
6the terms of the
7                    Common Public License Version 1.0.
8
9A copy of this license is included in the COPYING file of this distribution.
10Please visit http://www.coin-or.org/CppAD/ for information on other licenses.
11-------------------------------------------------------------------------- */
12
13/*
14Test the using standard math functions with AD< AD<double> >
15*/
16
17# include <cppad/cppad.hpp>
18
19typedef CppAD::AD<double>      ADdouble;
20typedef CppAD::AD< ADdouble > ADDdouble;
21
22bool std_math(void)
23{       using CppAD::NearEqual; 
24        bool ok = true;
25        ADDdouble half   = .5;
26        ADDdouble one    = 1.;
27        ADDdouble two    = 2.;
28        ADDdouble ten    = 10.;
29        ADDdouble small  = 1e-6;
30        ADDdouble pi_4   = 3.141592653 / 4.;
31        ADDdouble root_2 =  sqrt(two);
32
33        ADDdouble y = acos(one / root_2);
34        ok &= NearEqual( pi_4, y, small, small );
35
36        y = cos(pi_4);
37        ok &= NearEqual( one / root_2, y, small, small );
38
39        y = asin(one / root_2);
40        ok &= NearEqual( pi_4, y, small, small );
41
42        y = sin(pi_4);
43        ok &= NearEqual( one / root_2, y, small, small );
44
45        y = atan(one);
46        ok &= NearEqual( pi_4, y, small, small );
47
48        y = tan(pi_4);
49        ok &= NearEqual( one, y, small, small );
50
51        y = two * cosh(one);
52        ok &= NearEqual( exp(one) + exp(-one), y, small, small );
53
54        y = two * sinh(one);
55        ok &= NearEqual( exp(one) - exp(-one), y, small, small );
56
57        y = log( exp(one) );
58        ok &= NearEqual( one, y, small, small );
59
60        y = log10( exp( log(ten) ) );
61        ok &= NearEqual( one, y, small, small );
62
63        return ok;
64}
Note: See TracBrowser for help on using the repository browser.