diff --git a/Eigen/src/Core/arch/SSE/TypeCasting.h b/Eigen/src/Core/arch/SSE/TypeCasting.h index 454f4d38d..c84893230 100644 --- a/Eigen/src/Core/arch/SSE/TypeCasting.h +++ b/Eigen/src/Core/arch/SSE/TypeCasting.h @@ -24,7 +24,7 @@ struct type_casting_traits { }; template<> EIGEN_STRONG_INLINE Packet4i pcast(const Packet4f& a) { - return _mm_cvtps_epi32(a); + return _mm_cvttps_epi32(a); } diff --git a/unsupported/test/cxx11_tensor_casts.cpp b/unsupported/test/cxx11_tensor_casts.cpp index f53679d7b..729e43327 100644 --- a/unsupported/test/cxx11_tensor_casts.cpp +++ b/unsupported/test/cxx11_tensor_casts.cpp @@ -56,6 +56,25 @@ static void test_vectorized_cast() } +static void test_float_to_int_cast() +{ + Tensor ftensor(20,30); + ftensor = ftensor.random() * 1000.0f; + Tensor dtensor(20,30); + dtensor = dtensor.random() * 1000.0; + + Tensor i1tensor = ftensor.cast(); + Tensor i2tensor = dtensor.cast(); + + for (int i = 0; i < 20; ++i) { + for (int j = 0; j < 30; ++j) { + VERIFY_IS_EQUAL(i1tensor(i,j), static_cast(ftensor(i,j))); + VERIFY_IS_EQUAL(i2tensor(i,j), static_cast(dtensor(i,j))); + } + } +} + + static void test_big_to_small_type_cast() { Tensor dtensor(20, 30); @@ -90,6 +109,7 @@ void test_cxx11_tensor_casts() { CALL_SUBTEST(test_simple_cast()); CALL_SUBTEST(test_vectorized_cast()); + CALL_SUBTEST(test_float_to_int_cast()); CALL_SUBTEST(test_big_to_small_type_cast()); CALL_SUBTEST(test_small_to_big_type_cast()); }