diff options
author | Benoit Jacob <jacob.benoit.1@gmail.com> | 2010-03-30 11:38:09 -0400 |
---|---|---|
committer | Benoit Jacob <jacob.benoit.1@gmail.com> | 2010-03-30 11:38:09 -0400 |
commit | 8f99ae5ea44965396a6174ab97a41f0a2101b984 (patch) | |
tree | a901f5a2c4398e0e2b0026ba65f5be06a7dbb360 /Eigen/src/Core/IO.h | |
parent | e6300efb5c97cbd66b58b944441f66147bb375ad (diff) |
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:
Diffstat (limited to 'Eigen/src/Core/IO.h')
-rw-r--r-- | Eigen/src/Core/IO.h | 14 |
1 files 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<Derived>::format(const IOFormat& fmt) const return WithFormat<Derived>(derived(), fmt); } +template<typename Scalar> +struct ei_significant_decimals_impl +{ + typedef typename NumTraits<Scalar>::Real RealScalar; + static inline int run() + { + return (int) std::ceil(-ei_log(NumTraits<RealScalar>::epsilon())/ei_log(RealScalar(10))); + } +}; + /** \internal * print the matrix \a _m to the output stream \a s using the output format \a fmt */ template<typename Derived> @@ -145,9 +155,7 @@ std::ostream & ei_print_matrix(std::ostream & s, const Derived& _m, const IOForm { if (NumTraits<Scalar>::HasFloatingPoint) { - typedef typename NumTraits<Scalar>::Real RealScalar; - RealScalar explicit_precision_fp = std::ceil(-ei_log(NumTraits<Scalar>::epsilon())/ei_log(10.0)); - explicit_precision = static_cast<std::streamsize>(explicit_precision_fp); + explicit_precision = ei_significant_decimals_impl<Scalar>::run(); } else { |