Eliminate round_impl double-promotion warnings for c++03.

This commit is contained in:
Antonio Sanchez
2021-03-24 10:12:02 -07:00
committed by Rasmus Munk Larsen
parent 748489ef9c
commit 87729ea39f
3 changed files with 42 additions and 12 deletions

View File

@@ -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
{