From d6f9bcd1ccccf168ff7ff49325b1070b4183b3c7 Mon Sep 17 00:00:00 2001 From: Thomas Schlichter Date: Wed, 2 Oct 2024 11:21:09 +0200 Subject: [PATCH] fix test log2_approx64.boundaries The test was actually never executed correctly (unsigned -10 is never <= 10), and log2_approx64_ref() was not accurate enough. Therefore replace it by directly comparing one value above and one value below each rounding boundary. --- openair1/PHY/TOOLS/tests/test_log2_approx.cpp | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/openair1/PHY/TOOLS/tests/test_log2_approx.cpp b/openair1/PHY/TOOLS/tests/test_log2_approx.cpp index c05540b61c..2a8536a3c1 100644 --- a/openair1/PHY/TOOLS/tests/test_log2_approx.cpp +++ b/openair1/PHY/TOOLS/tests/test_log2_approx.cpp @@ -10,11 +10,6 @@ uint8_t log2_approx_ref(uint32_t x) return std::round(std::log2(x)); } -uint8_t log2_approx64_ref(unsigned long long int x) -{ - return std::round(std::log2(static_cast(x))); -} - TEST(log2_approx, complete) { for (uint32_t i = 0; i < UINT32_MAX; i++) @@ -23,12 +18,10 @@ TEST(log2_approx, complete) TEST(log2_approx64, boundaries) { - for (long double i = 0; i < 64; i++) { - unsigned long long i2 = std::pow(2.0L, i + 0.5L); - for (unsigned long long j = -10; j <= 10; j++) { - unsigned long long x = i2 + j; - EXPECT_EQ(log2_approx64(x), log2_approx64_ref(x)); - } + for (int i = 0; i < 64; i++) { + unsigned long long int i2 = std::pow(2.0L, i + 0.5L); + EXPECT_EQ(log2_approx64(i2), i) << "log2(" << i2 << ")"; + EXPECT_EQ(log2_approx64(i2 + 1), i + 1) << "log2(" << i2 + 1 << ")"; } }