diff options
Diffstat (limited to 'Eigen/src/Core/MathFunctions.h')
-rw-r--r-- | Eigen/src/Core/MathFunctions.h | 38 |
1 files changed, 31 insertions, 7 deletions
diff --git a/Eigen/src/Core/MathFunctions.h b/Eigen/src/Core/MathFunctions.h index c8db56e9b..29201214f 100644 --- a/Eigen/src/Core/MathFunctions.h +++ b/Eigen/src/Core/MathFunctions.h @@ -485,14 +485,31 @@ struct round_impl EIGEN_STATIC_ASSERT((!NumTraits<Scalar>::IsComplex), NUMERIC_TYPE_MUST_BE_REAL) #if EIGEN_HAS_CXX11_MATH EIGEN_USING_STD(round); +#endif return Scalar(round(x)); -#elif EIGEN_HAS_C99_MATH - if (is_same<Scalar, float>::value) { - return Scalar(::roundf(x)); - } else { - return Scalar(round(x)); - } + } +}; + +#if !EIGEN_HAS_CXX11_MATH +#if EIGEN_HAS_C99_MATH +// Use ::roundf for float. +template<> +struct round_impl<float> { + EIGEN_DEVICE_FUNC + static inline float run(const float& x) + { + return ::roundf(x); + } +}; #else +template<typename Scalar> +struct round_using_floor_ceil_impl +{ + EIGEN_DEVICE_FUNC + static inline Scalar run(const Scalar& x) + { + EIGEN_STATIC_ASSERT((!NumTraits<Scalar>::IsComplex), NUMERIC_TYPE_MUST_BE_REAL) + // Without C99 round/roundf, resort to floor/ceil. EIGEN_USING_STD(floor); EIGEN_USING_STD(ceil); // If not enough precision to resolve a decimal at all, return the input. @@ -502,10 +519,17 @@ struct round_impl return x; } return (x > Scalar(0)) ? Scalar(floor(x + Scalar(0.5))) : Scalar(ceil(x - Scalar(0.5))); -#endif } }; +template<> +struct round_impl<float> : round_using_floor_ceil_impl<float> {}; + +template<> +struct round_impl<double> : round_using_floor_ceil_impl<double> {}; +#endif // EIGEN_HAS_C99_MATH +#endif // !EIGEN_HAS_CXX11_MATH + template<typename Scalar> struct round_retval { |