Prev Next base_float.hpp

@(@\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 float

CondExpOp
The type float is a relatively simple type that supports <, <=, ==, >=, and > operators; see ordered type . Hence its CondExpOp function is defined by
namespace CppAD {
     inline float CondExpOp(
          enum CompareOp     cop          ,
          const float&       left         ,
          const float&       right        ,
          const float&       exp_if_true  ,
          const float&       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(float)
}
uses CondExpOp above to define CondExpRel for float arguments and Rel equal to Lt, Le, Eq, Ge, and Gt.

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

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

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

azmul

namespace CppAD {
     CPPAD_AZMUL( float )
}

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

Unary Standard Math
The following macro invocations import the float 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 double 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;
# if CPPAD_USE_CPLUSPLUS_2011
     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 float abs(const float& x)
     {     return std::fabs(x); }
}

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

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

namespace CppAD {
     using std::pow;
}

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

namespace CppAD {
     CPPAD_NUMERIC_LIMITS(float, float)
}

to_string
There is no need to define to_string for float 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/core/base_float.hpp