base_limits

View page source

Base Type Requirements for Numeric Limits

numeric_limits

A specialization for CppAD::numeric_limits must be defined in order to use the type AD < Base > . CppAD does not use a specialization of std::numeric_limits< Base > . Since C++11, using a specialization of std::numeric_limits< Base > would require that Base be a literal type.

CPPAD_NUMERIC_LIMITS

In most cases, this macro can be used to define the specialization where the numeric limits for the type Base are the same as the standard numeric limits for the type Other . For most Base types, there is a choice of Other , for which the following preprocessor macro invocation suffices:

      namespace CppAD {
            CPPAD_NUMERIC_LIMITS ( Other , Base )
      }

e.g., see numeric_limits for the type double . The macro CPPAD_NUMERIC_LIMITS is defined by

# define CPPAD_NUMERIC_LIMITS(Other, Base) \
template <> class numeric_limits<Base>\
{\
   public:\
   static Base min(void) \
   {  return static_cast<Base>( std::numeric_limits<Other>::min() ); }\
   static Base max(void) \
   {  return static_cast<Base>( std::numeric_limits<Other>::max() ); }\
   static Base epsilon(void) \
   {  return static_cast<Base>( std::numeric_limits<Other>::epsilon() ); }\
   static Base quiet_NaN(void) \
   {  return static_cast<Base>( std::numeric_limits<Other>::quiet_NaN() ); }\
   static Base infinity(void) \
   {  return static_cast<Base>( std::numeric_limits<Other>::infinity() ); }\
   static const int digits10 = std::numeric_limits<Other>::digits10;\
   static const int max_digits10 = std::numeric_limits<Other>::max_digits10;\
};