diff options
author | Gael Guennebaud <g.gael@free.fr> | 2017-11-10 10:28:54 +0000 |
---|---|---|
committer | Gael Guennebaud <g.gael@free.fr> | 2017-11-10 10:28:54 +0000 |
commit | 1495b98a8e8ce08b1c6ed04fd23db41a68785340 (patch) | |
tree | 856d1d17a111b9e2a83a057405d4d68ec61d843e /Eigen/src/Core/NumTraits.h | |
parent | fc453243801f883a0a7ac3614e43fd9f5c8de2b8 (diff) | |
parent | 511810797e35471568091c44e947329f0060698e (diff) |
Merged in spraetor/eigen (pull request PR-305)
Issue with mpreal and std::numeric_limits::digits
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 92a9ae1ea..5567d4c90 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 |