Extending to_string To Another Floating Point Type
Keywords: extending to_string to another floating point type base requirement cppad_to_string

| Prev | Next |  |  |  |  |  | base_to_string |

Extending to_string To Another Floating Point Type
Base Requirement
If the function to_string is used by an AD type above Base , A specialization for the template structure `CppAD::to_string_struct` must be defined.
CPPAD_TO_STRING
For most `Base` types, the following can be used to define the specialization: `
namespace CppAD {
CPPAD_TO_STRING(Base)
}
` Note that the `CPPAD_TO_STRING` macro assumes that the base_limits and base_std_math have already been defined for this type. This macro is defined as follows: `

    # define CPPAD_TO_STRING(Base) \
    template <> struct to_string_struct<Base>\
    {    std::string operator()(const Base& value) \
         {    std::stringstream os;\
              Base epsilon    = CppAD::numeric_limits<Base>::epsilon();\
              Base log10      = CppAD::log( epsilon ) / CppAD::log(Base(10.));\
              size_t n_digits = 1 - Integer( log10 );\
              os << std::setprecision(n_digits);\
              os << value;\
              return os.str();\
         }\
    };

`

Input File: cppad/local/base_to_string.hpp