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.

This commit is contained in:
Benoit Jacob 2010-03-30 14:16:54 -04:00
parent 8f99ae5ea4
commit 9e0d8697c7
2 changed files with 15 additions and 1 deletions

View File

@ -132,7 +132,7 @@ 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)));
return ei_cast_to_int(std::ceil(-ei_log(NumTraits<RealScalar>::epsilon())/ei_log(RealScalar(10))));
}
};

View File

@ -44,6 +44,20 @@ template<typename T> inline typename NumTraits<T>::Real ei_hypot(T x, T y)
return p * ei_sqrt(T(1) + qp*qp);
}
template<typename T> struct ei_cast_to_int_impl
{
static int run(const T& x)
{
return int(x);
}
};
template<typename T> inline int ei_cast_to_int(const T& x)
{
return ei_cast_to_int_impl<T>::run(x);
}
/**************
*** int ***
**************/