mirror of
https://gitlab.com/libeigen/eigen.git
synced 2024-12-21 07:19:46 +08:00
Use std::round when c++11 is used, custom implementation otherwise
This commit is contained in:
parent
e21e29a088
commit
e26134ed62
@ -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<typename Scalar>
|
||||
struct round_impl {
|
||||
static inline Scalar run(const Scalar& x)
|
||||
{
|
||||
EIGEN_STATIC_ASSERT((!NumTraits<Scalar>::IsComplex), NUMERIC_TYPE_MUST_BE_REAL)
|
||||
using std::round;
|
||||
return round(x);
|
||||
}
|
||||
};
|
||||
// No C++11, use our own implementation
|
||||
#else
|
||||
template<typename Scalar>
|
||||
struct round_impl
|
||||
{
|
||||
static inline Scalar run(const Scalar& x)
|
||||
{
|
||||
EIGEN_STATIC_ASSERT((!NumTraits<Scalar>::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<typename Scalar>
|
||||
struct round_retval
|
||||
{
|
||||
typedef Scalar type;
|
||||
};
|
||||
|
||||
/****************************************************************************
|
||||
* Implementation of log1p *
|
||||
****************************************************************************/
|
||||
template<typename Scalar, bool isComplex = NumTraits<Scalar>::IsComplex >
|
||||
struct log1p_impl
|
||||
@ -775,13 +812,11 @@ bool (isInf)(const std::complex<T>& x)
|
||||
return isinf(real(x)) || isinf(imag(x));
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
template<typename Scalar>
|
||||
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<typename T>
|
||||
|
Loading…
Reference in New Issue
Block a user