\(\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}} }\)
base_to_string¶
View page sourceExtending 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();\
}\
};