CppAD: A C++ Algorithmic Differentiation Package  20171217
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
base_limits.hpp
Go to the documentation of this file.
1 # ifndef CPPAD_CORE_BASE_LIMITS_HPP
2 # define CPPAD_CORE_BASE_LIMITS_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 /*
16 $begin base_limits$$
17 $spell
18  std
19  namespace
20  CppAD
21 $$
22 
23 $section Base Type Requirements for Numeric Limits$$
24 
25 $head CppAD::numeric_limits$$
26 A specialization for
27 $cref/CppAD::numeric_limits/numeric_limits/$$
28 must be defined in order to use the type $codei%AD<%Base%>%$$.
29 CppAD does not use a specialization of
30 $codei%std::numeric_limits<%Base%>%$$.
31 Since C++11, using a specialization of
32 $codei%std::numeric_limits<%Base%>%$$
33 would require that $icode Base$$ be a literal type.
34 
35 $head CPPAD_NUMERIC_LIMITS$$
36 In most cases, this macro can be used to define the specialization where
37 the numeric limits for the type $icode Base$$
38 are the same as the standard numeric limits for the type $icode Other$$.
39 For most $icode Base$$ types,
40 there is a choice of $icode Other$$,
41 for which the following preprocessor macro invocation suffices:
42 $codei%
43  namespace CppAD {
44  CPPAD_NUMERIC_LIMITS(%Other%, %Base%)
45  }
46 %$$
47 where the macro is defined by
48 $srccode%cpp% */
49 # define CPPAD_NUMERIC_LIMITS(Other, Base) \
50 template <> class numeric_limits<Base>\
51 {\
52  public:\
53  static Base min(void) \
54  { return static_cast<Base>( std::numeric_limits<Other>::min() ); }\
55  static Base max(void) \
56  { return static_cast<Base>( std::numeric_limits<Other>::max() ); }\
57  static Base epsilon(void) \
58  { return static_cast<Base>( std::numeric_limits<Other>::epsilon() ); }\
59  static Base quiet_NaN(void) \
60  { return static_cast<Base>( std::numeric_limits<Other>::quiet_NaN() ); }\
61  static const int digits10 = std::numeric_limits<Other>::digits10;\
62 };
63 /* %$$
64 $end
65 */
66 
67 # endif