Enable use of AD<Base> where Base is double
Keywords: enable use ad<base> where base is double condexpop condexprel equalopseq identical integer azmul ordered unary standard math sign pow numeric_limits to_string

| Prev | Next |  |  |  |  |  | base_double.hpp |

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
The CPPAD_COND_EXP_REL macro invocation `

    namespace CppAD {
         CPPAD_COND_EXP_REL(double)
    }

` 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 `

    namespace CppAD {
         CPPAD_AZMUL( double )
    }

`
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 define the unary standard math functions required to use `AD<double>`: `

    namespace CppAD {
         CPPAD_STANDARD_MATH_UNARY(double, acos)
         CPPAD_STANDARD_MATH_UNARY(double, asin)
         CPPAD_STANDARD_MATH_UNARY(double, atan)
         CPPAD_STANDARD_MATH_UNARY(double, cos)
         CPPAD_STANDARD_MATH_UNARY(double, cosh)
         CPPAD_STANDARD_MATH_UNARY(double, exp)
         CPPAD_STANDARD_MATH_UNARY(double, fabs)
         CPPAD_STANDARD_MATH_UNARY(double, log)
         CPPAD_STANDARD_MATH_UNARY(double, log10)
         CPPAD_STANDARD_MATH_UNARY(double, sin)
         CPPAD_STANDARD_MATH_UNARY(double, sinh)
         CPPAD_STANDARD_MATH_UNARY(double, sqrt)
         CPPAD_STANDARD_MATH_UNARY(double, tan)
         CPPAD_STANDARD_MATH_UNARY(double, tanh)
    # if CPPAD_USE_CPLUSPLUS_2011
         CPPAD_STANDARD_MATH_UNARY(double, erf)
         CPPAD_STANDARD_MATH_UNARY(double, asinh)
         CPPAD_STANDARD_MATH_UNARY(double, acosh)
         CPPAD_STANDARD_MATH_UNARY(double, atanh)
         CPPAD_STANDARD_MATH_UNARY(double, expm1)
         CPPAD_STANDARD_MATH_UNARY(double, 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>`: `

    namespace CppAD {
         inline double pow(const double& x, const double& y)
         { return std::pow(x, y); }
    }

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

    namespace CppAD {
         CPPAD_NUMERIC_LIMITS(double, double)
    }

`
to_string
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.

Input File: cppad/local/base_double.hpp