From 9e0d8697c78fb4668246c59186eca342ba3eff88 Mon Sep 17 00:00:00 2001 From: Benoit Jacob Date: Tue, 30 Mar 2010 14:16:54 -0400 Subject: [PATCH] add ei_cast_to_int, we are indeed somethings (e.g. in IO.h) casting scalars to int and the only way to allow users to extend that to their own scalar types that don't have int cast operators, was to allow them specialize ei_cast_to_int_impl. --- Eigen/src/Core/IO.h | 2 +- Eigen/src/Core/MathFunctions.h | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/Eigen/src/Core/IO.h b/Eigen/src/Core/IO.h index ffb214894..22db103ed 100644 --- a/Eigen/src/Core/IO.h +++ b/Eigen/src/Core/IO.h @@ -132,7 +132,7 @@ 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))); + return ei_cast_to_int(std::ceil(-ei_log(NumTraits::epsilon())/ei_log(RealScalar(10)))); } }; diff --git a/Eigen/src/Core/MathFunctions.h b/Eigen/src/Core/MathFunctions.h index c97a68e50..943b44cfa 100644 --- a/Eigen/src/Core/MathFunctions.h +++ b/Eigen/src/Core/MathFunctions.h @@ -44,6 +44,20 @@ template inline typename NumTraits::Real ei_hypot(T x, T y) return p * ei_sqrt(T(1) + qp*qp); } +template struct ei_cast_to_int_impl +{ + static int run(const T& x) + { + return int(x); + } +}; + +template inline int ei_cast_to_int(const T& x) +{ + return ei_cast_to_int_impl::run(x); +} + + /************** *** int *** **************/