base_to_string

View page source

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;\
      int n_digits = 1 + CppAD::numeric_limits<Base>::digits10; \
      os << std::setprecision(n_digits);\
      os << value;\
      return os.str();\
   }\
};