CppAD: A C++ Algorithmic Differentiation Package  20171217
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
base_to_string.hpp
Go to the documentation of this file.
1 # ifndef CPPAD_CORE_BASE_TO_STRING_HPP
2 # define CPPAD_CORE_BASE_TO_STRING_HPP
3 
4 /* --------------------------------------------------------------------------
5 CppAD: C++ Algorithmic Differentiation: Copyright (C) 2003-17 Bradley M. Bell
6 
7 CppAD is distributed under multiple licenses. This distribution is under
8 the terms of the
9  Eclipse Public License Version 1.0.
10 
11 A copy of this license is included in the COPYING file of this distribution.
12 Please visit http://www.coin-or.org/CppAD/ for information on other licenses.
13 -------------------------------------------------------------------------- */
14 /*
15 $begin base_to_string$$
16 $spell
17  std
18  namespace
19  CppAD
20  struct
21  const
22  stringstream
23  setprecision
24  str
25 $$
26 
27 $section Extending to_string To Another Floating Point Type$$
28 
29 $head Base Requirement$$
30 If the function $cref to_string$$ is used by an
31 $cref/AD type above Base/glossary/AD Type Above Base/$$,
32 A specialization for the template structure
33 $code CppAD::to_string_struct$$ must be defined.
34 
35 $head CPPAD_TO_STRING$$
36 For most $icode Base$$ types,
37 the following can be used to define the specialization:
38 $codei%
39  namespace CppAD {
40  CPPAD_TO_STRING(%Base%)
41  }
42 %$$
43 Note that the $code CPPAD_TO_STRING$$ macro assumes that the
44 $cref base_limits$$ and $cref base_std_math$$ have already been defined
45 for this type.
46 This macro is defined as follows:
47 $srccode%cpp% */
48 # define CPPAD_TO_STRING(Base) \
49 template <> struct to_string_struct<Base>\
50 { std::string operator()(const Base& value) \
51  { std::stringstream os;\
52  int n_digits = 1 + CppAD::numeric_limits<Base>::digits10; \
53  os << std::setprecision(n_digits);\
54  os << value;\
55  return os.str();\
56  }\
57 };
58 /* %$$
59 $end
60 ------------------------------------------------------------------------------
61 */
62 // make sure to_string has been included
64 
65 # endif