Prev Next

@(@\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}} }@)@
Convert Certain Types to a String

# include <cppad/utility/to_string.hpp>
s = to_string(value) .

See Also
base_to_string , ad_to_string

This routine is similar to the C++11 routine std::to_string with the following differences:
  1. It works with C++98.
  2. It has been extended to the fundamental floating point types.
  3. It has specifications for extending to an arbitrary type; see base_to_string .
  4. If <cppad/cppad.hpp> is included, and it has been extended to a Base type, it automatically extends to the AD types above Base .
  5. For integer types, conversion to a string is exact. For floating point types, conversion to a string yields a value that has relative error within machine epsilon.


The argument value can have the following prototype
Integer&  value
where Integer is any of the fundamental integer types; e.g., short int and unsigned long. Note that if C++11 is supported by this compilation, unsigned long long is also a fundamental integer type.

The argument value can have the following prototype
Float&  value
where Float is any of the fundamental floating point types; i.e., float, double, and long double.

The return value has prototype
and contains a representation of the specified value .

If value is an Integer , the representation is equivalent to os << value where os is an std::ostringstream.

If value is a Float , enough digits are used in the representation so that the result is accurate to withing round off error.

The file to_string.cpp contains an example and test of this routine. It returns true if it succeeds and false otherwise.
Input File: cppad/utility/to_string.hpp