From 8f99ae5ea44965396a6174ab97a41f0a2101b984 Mon Sep 17 00:00:00 2001 From: Benoit Jacob Date: Tue, 30 Mar 2010 11:38:09 -0400 Subject: [PATCH] move the computation of the number of significant digits to a templated helper struct, that can be specialized to custom types if needed. Should address this request: http://forum.kde.org/viewtopic.php?f=74&t=86914 --- Eigen/src/Core/IO.h | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/Eigen/src/Core/IO.h b/Eigen/src/Core/IO.h index 3e8d2bc66..ffb214894 100644 --- a/Eigen/src/Core/IO.h +++ b/Eigen/src/Core/IO.h @@ -126,6 +126,16 @@ DenseBase::format(const IOFormat& fmt) const return WithFormat(derived(), fmt); } +template +struct ei_significant_decimals_impl +{ + typedef typename NumTraits::Real RealScalar; + static inline int run() + { + return (int) std::ceil(-ei_log(NumTraits::epsilon())/ei_log(RealScalar(10))); + } +}; + /** \internal * print the matrix \a _m to the output stream \a s using the output format \a fmt */ template @@ -145,9 +155,7 @@ std::ostream & ei_print_matrix(std::ostream & s, const Derived& _m, const IOForm { if (NumTraits::HasFloatingPoint) { - typedef typename NumTraits::Real RealScalar; - RealScalar explicit_precision_fp = std::ceil(-ei_log(NumTraits::epsilon())/ei_log(10.0)); - explicit_precision = static_cast(explicit_precision_fp); + explicit_precision = ei_significant_decimals_impl::run(); } else {