diff --git a/Eigen/src/Core/MathFunctions.h b/Eigen/src/Core/MathFunctions.h index 36a6eb650..a7e75b4a9 100644 --- a/Eigen/src/Core/MathFunctions.h +++ b/Eigen/src/Core/MathFunctions.h @@ -395,7 +395,44 @@ inline NewType cast(const OldType& x) } /**************************************************************************** -* Implementation of logp1 * +* Implementation of round * +****************************************************************************/ +// In C++11 we can specialize round_impl for real Scalars +// Let's be conservative and enable the default C++11 implementation only if we are sure it exists +#if (__cplusplus >= 201103L) && (EIGEN_COMP_GNUC_STRICT || EIGEN_COMP_CLANG || EIGEN_COMP_MSVC || EIGEN_COMP_ICC) \ + && (EIGEN_ARCH_i386_OR_x86_64) && (EIGEN_OS_GNULINUX || EIGEN_OS_WIN_STRICT || EIGEN_OS_MAC) + template + struct round_impl { + static inline Scalar run(const Scalar& x) + { + EIGEN_STATIC_ASSERT((!NumTraits::IsComplex), NUMERIC_TYPE_MUST_BE_REAL) + using std::round; + return round(x); + } + }; +// No C++11, use our own implementation +#else + template + struct round_impl + { + static inline Scalar run(const Scalar& x) + { + EIGEN_STATIC_ASSERT((!NumTraits::IsComplex), NUMERIC_TYPE_MUST_BE_REAL) + using std::floor; + using std::ceil; + return (x > 0.0) ? floor(x + 0.5) : ceil(x - 0.5); + } + }; +#endif + +template +struct round_retval +{ + typedef Scalar type; +}; + +/**************************************************************************** +* Implementation of log1p * ****************************************************************************/ template::IsComplex > struct log1p_impl @@ -775,13 +812,11 @@ bool (isInf)(const std::complex& x) return isinf(real(x)) || isinf(imag(x)); } -template +template EIGEN_DEVICE_FUNC -T (round)(const T& x) +inline EIGEN_MATHFUNC_RETVAL(round, Scalar) round(const Scalar& x) { - using std::floor; - using std::ceil; - return (x > 0.0) ? floor(x + 0.5) : ceil(x - 0.5); + return EIGEN_MATHFUNC_IMPL(round, Scalar)::run(x); } template