diff options
author | Simon Praetorius <simon.praetorius@tu-dresden.de> | 2017-03-24 17:45:56 +0100 |
---|---|---|
committer | Simon Praetorius <simon.praetorius@tu-dresden.de> | 2017-03-24 17:45:56 +0100 |
commit | 511810797e35471568091c44e947329f0060698e (patch) | |
tree | e08f7807d788df53365f9753b16f4569aee8548e /Eigen/src/Core/NumTraits.h | |
parent | aae19c70ac273a2d40daf18a3cd15c0b0075662b (diff) |
Issue with mpreal and std::numeric_limits, i.e. digits is not a constant. Added a digits() traits in NumTraits with fallback to static constant. Specialization for mpreal added in MPRealSupport.
Diffstat (limited to 'Eigen/src/Core/NumTraits.h')
-rw-r--r-- | Eigen/src/Core/NumTraits.h | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/Eigen/src/Core/NumTraits.h b/Eigen/src/Core/NumTraits.h index aebc0c259..4d896a098 100644 --- a/Eigen/src/Core/NumTraits.h +++ b/Eigen/src/Core/NumTraits.h @@ -41,6 +41,34 @@ struct default_digits10_impl<T,false,true> // Integer static int run() { return 0; } }; + +// default implementation of digits(), based on numeric_limits if specialized, +// 0 for integer types, and log2(epsilon()) otherwise. +template< typename T, + bool use_numeric_limits = std::numeric_limits<T>::is_specialized, + bool is_integer = NumTraits<T>::IsInteger> +struct default_digits_impl +{ + static int run() { return std::numeric_limits<T>::digits; } +}; + +template<typename T> +struct default_digits_impl<T,false,false> // Floating point +{ + static int run() { + using std::log; + using std::ceil; + typedef typename NumTraits<T>::Real Real; + return int(ceil(-log(NumTraits<Real>::epsilon())/log(static_cast<Real>(2)))); + } +}; + +template<typename T> +struct default_digits_impl<T,false,true> // Integer +{ + static int run() { return 0; } +}; + } // end namespace internal /** \class NumTraits @@ -119,6 +147,12 @@ template<typename T> struct GenericNumTraits } EIGEN_DEVICE_FUNC + static inline int digits() + { + return internal::default_digits_impl<T>::run(); + } + + EIGEN_DEVICE_FUNC static inline Real dummy_precision() { // make sure to override this for floating-point types |