source: trunk/test_more/std_math.cpp @ 3495

Last change on this file since 3495 was 3060, checked in by bradbell, 6 years ago
  1. Fix warning generated by bug/eigen_mul.sh.
  2. Item 1 required changing arbitrary conversion to AD<Base> to be explicit.
  3. Item 2 required some explicit type conversions.

base_require.hpp: remove trailing slash in documentaiton.
ad.hpp: comment about explicit and implicit constructors.

  • Property svn:keywords set to Id
File size: 1.6 KB
Line 
1/* $Id: std_math.cpp 3060 2013-12-27 20:38:57Z bradbell $ */
2/* --------------------------------------------------------------------------
3CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-13 Bradley M. Bell
4
5CppAD is distributed under multiple licenses. This distribution is under
6the terms of the
7                    Eclipse 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.