Prev Next Index-> contents reference index search external Up-> CppAD AD base_require base_example base_double.hpp AD-> ad_ctor ad_assign Convert ADValued BoolValued VecAD base_require base_require-> base_member base_cond_exp base_identical base_ordered base_std_math base_limits base_to_string base_hash base_example base_example-> base_alloc.hpp base_require.cpp base_adolc.hpp base_float.hpp base_double.hpp base_complex.hpp base_double.hpp Headings-> CondExpOp CondExpRel EqualOpSeq Identical Integer azmul Ordered Unary Standard Math sign pow numeric_limits to_string

$\newcommand{\W}[1]{ \; #1 \; } \newcommand{\R}[1]{ {\rm #1} } \newcommand{\B}[1]{ {\bf #1} } \newcommand{\D}[2]{ \frac{\partial #1}{\partial #2} } \newcommand{\DD}[3]{ \frac{\partial^2 #1}{\partial #2 \partial #3} } \newcommand{\Dpow}[2]{ \frac{\partial^{#1}}{\partial {#2}^{#1}} } \newcommand{\dpow}[2]{ \frac{ {\rm d}^{#1}}{{\rm d}\, {#2}^{#1}} }$
Enable use of AD<Base> where Base is double

CondExpOp
The type double is a relatively simple type that supports <, <=, ==, >=, and > operators; see ordered type . Hence its CondExpOp function is defined by
namespace CppAD {
inline double CondExpOp(
enum CompareOp     cop          ,
const double&       left         ,
const double&       right        ,
const double&       exp_if_true  ,
const double&       exp_if_false )
{     return CondExpTemplate(cop, left, right, exp_if_true, exp_if_false);
}
}

CondExpRel

}

uses CondExpOp above to define CondExpRel for double arguments and Rel equal to Lt, Le, Eq, Ge, and Gt.

EqualOpSeq
The type double is simple (in this respect) and so we define
namespace CppAD {
inline bool EqualOpSeq(const double& x, const double& y)
{     return x == y; }
}

Identical
The type double is simple (in this respect) and so we define
namespace CppAD {
inline bool IdenticalPar(const double& x)
{     return true; }
inline bool IdenticalZero(const double& x)
{     return (x == 0.); }
inline bool IdenticalOne(const double& x)
{     return (x == 1.); }
inline bool IdenticalEqualPar(const double& x, const double& y)
{     return (x == y); }
}

Integer
namespace CppAD {
inline int Integer(const double& x)
{     return static_cast<int>(x); }
}

azmul

}


Ordered
The double type supports ordered comparisons
namespace CppAD {
inline bool GreaterThanZero(const double& x)
{     return x > 0.; }
inline bool GreaterThanOrZero(const double& x)
{     return x >= 0.; }
inline bool LessThanZero(const double& x)
{     return x < 0.; }
inline bool LessThanOrZero(const double& x)
{     return x <= 0.; }
inline bool abs_geq(const double& x, const double& y)
{     return std::fabs(x) >= std::fabs(y); }
}

Unary Standard Math
The following macro invocations import the double versions of the unary standard math functions into the CppAD namespace. Importing avoids ambiguity errors when using both the CppAD and std namespaces. Note this also defines the float versions of these functions.
namespace CppAD {
using std::acos;
using std::asin;
using std::atan;
using std::cos;
using std::cosh;
using std::exp;
using std::fabs;
using std::log;
using std::log10;
using std::sin;
using std::sinh;
using std::sqrt;
using std::tan;
using std::tanh;
using std::erf;
using std::asinh;
using std::acosh;
using std::atanh;
using std::expm1;
using std::log1p;
# endif
}
The absolute value function is special because its std name is fabs
namespace CppAD {
inline double abs(const double& x)
{     return std::fabs(x); }
}

sign
The following defines the CppAD::sign function that is required to use AD<double>:
namespace CppAD {
inline double sign(const double& x)
{     if( x > 0. )
return 1.;
if( x == 0. )
return 0.;
return -1.;
}
}

pow
The following defines a CppAD::pow function that is required to use AD<double>. As with the unary standard math functions, this has the exact same signature as std::pow, so use it instead of defining another function.

using std::pow;
}


numeric_limits
The following defines the CppAD numeric_limits for the type double:


There is no need to define to_string for double because it is defined by including cppad/utility/to_string.hpp; see to_string . See base_complex.hpp for an example where it is necessary to define to_string for a Base type.