Skip to content

Commit 37d48ab

Browse files
committed
Ensure abs(short) calls abs(int) not abs(double)
* Vc/scalar/math.h: Overload abs(Scalar::Vector<short>) so that it can cast to int explicitly. Otherwise older libstdc++ will call the abs(double) overload.
1 parent 876ff5c commit 37d48ab

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

Vc/scalar/math.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,13 +84,17 @@ template<typename T> static Vc_ALWAYS_INLINE Scalar::Vector<T> rsqrt(const Scala
8484

8585
template <typename T,
8686
typename = enable_if<std::is_same<T, double>::value || std::is_same<T, float>::value ||
87-
std::is_same<T, short>::value ||
8887
std::is_same<T, int>::value>>
8988
Vc_ALWAYS_INLINE Vc_PURE Scalar::Vector<T> abs(Scalar::Vector<T> x)
9089
{
9190
return std::abs(x.data());
9291
}
9392

93+
Vc_ALWAYS_INLINE Vc_PURE Scalar::Vector<short> abs(Scalar::Vector<short> x)
94+
{
95+
return std::abs(static_cast<int>(x.data()));
96+
}
97+
9498
template<typename T> static Vc_ALWAYS_INLINE void sincos(const Scalar::Vector<T> &x, Scalar::Vector<T> *sin, Scalar::Vector<T> *cos)
9599
{
96100
#if defined(_WIN32) || defined(__APPLE__)

0 commit comments

Comments
 (0)