From 0f1ebf8c810d159afbf3ec705183363964890b9b Mon Sep 17 00:00:00 2001 From: serge-sans-paille Date: Mon, 16 Oct 2023 08:38:02 +0200 Subject: [PATCH] Test nearbyint_as_int using xsimd's scalar version instead of lround Fix #948 --- .../xsimd/arch/generic/xsimd_generic_math.hpp | 4 ++-- test/test_rounding.cpp | 17 ++--------------- 2 files changed, 4 insertions(+), 17 deletions(-) diff --git a/include/xsimd/arch/generic/xsimd_generic_math.hpp b/include/xsimd/arch/generic/xsimd_generic_math.hpp index f9be00d6c..10bf2abff 100644 --- a/include/xsimd/arch/generic/xsimd_generic_math.hpp +++ b/include/xsimd/arch/generic/xsimd_generic_math.hpp @@ -1855,7 +1855,7 @@ namespace xsimd { using U = as_integer_t; return kernel::detail::apply_transform([](float x) noexcept -> U - { return std::lroundf(x); }, + { return std::nearbyintf(x); }, self); } @@ -1865,7 +1865,7 @@ namespace xsimd { using U = as_integer_t; return kernel::detail::apply_transform([](double x) noexcept -> U - { return std::llround(x); }, + { return std::nearbyint(x); }, self); } diff --git a/test/test_rounding.cpp b/test/test_rounding.cpp index 26ba2dc7b..aa7f2b5a5 100644 --- a/test/test_rounding.cpp +++ b/test/test_rounding.cpp @@ -14,19 +14,6 @@ #include "test_utils.hpp" -namespace detail -{ - inline xsimd::as_integer_t nearbyint_as_int(float a) - { - return std::lroundf(a); - } - - inline xsimd::as_integer_t nearbyint_as_int(double a) - { - return std::llround(a); - } -} - template struct rounding_test { @@ -163,7 +150,7 @@ struct rounding_test std::array res; std::transform(input.cbegin(), input.cend(), expected.begin(), [](const value_type& v) - { return detail::nearbyint_as_int(v); }); + { return xsimd::nearbyint_as_int(v); }); batch_type in; int_batch_type out; for (size_t i = 0; i < nb_batches; i += size) @@ -174,7 +161,7 @@ struct rounding_test } for (size_t i = nb_batches; i < nb_input; ++i) { - res[i] = detail::nearbyint_as_int(input[i]); + res[i] = xsimd::nearbyint_as_int(input[i]); } size_t diff = detail::get_nb_diff(res, expected); INFO("nearbyint_as_int");