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

| Prev | Next |  |  |  |  |  | base_float.hpp |

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 define the unary standard math functions required to use `AD<float>`: (in the CppAD namespace) `

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

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

`
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/local/base_float.hpp