From ee58a50b7c4ea9df68de19a9eaf16d38130ad4e4 Mon Sep 17 00:00:00 2001 From: Erik Schnetter Date: Tue, 28 Jan 2025 09:45:03 -0500 Subject: [PATCH] Correct tolerances in float16 test --- autotest/cpp/testfloat16.cpp | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/autotest/cpp/testfloat16.cpp b/autotest/cpp/testfloat16.cpp index 0a8608bcda70..497467f28a0d 100644 --- a/autotest/cpp/testfloat16.cpp +++ b/autotest/cpp/testfloat16.cpp @@ -86,12 +86,13 @@ TEST(TestFloat16, arithmetic) EXPECT_EQ(GFloat16(x) + GFloat16(y), x + y); EXPECT_EQ(GFloat16(x) - GFloat16(y), x - y); + using std::fabs; EXPECT_NEAR(GFloat16(x) * GFloat16(y), x * y, - std::fabs(x * y / 1024)); + fabs(x * y / 1024)); if (j != 0) { EXPECT_NEAR(GFloat16(x) / GFloat16(y), x / y, - std::fabs(x / y / 1024)); + fabs(x / y / 1024)); } } } @@ -130,8 +131,9 @@ TEST(TestFloat16, math) EXPECT_EQ(isnan(GFloat16(x)), isnan(x)); using std::abs; EXPECT_EQ(abs(GFloat16(x)), abs(x)); + using std::fabs; using std::cbrt; - EXPECT_NEAR(cbrt(GFloat16(x)), cbrt(x), std::fabs(cbrt(x) / 1024)); + EXPECT_NEAR(cbrt(GFloat16(x)), cbrt(x), fabs(cbrt(x) / 1024)); using std::ceil; EXPECT_EQ(ceil(GFloat16(x)), ceil(x)); using std::fabs; @@ -143,7 +145,7 @@ TEST(TestFloat16, math) if (x >= 0) { using std::sqrt; - EXPECT_NEAR(sqrt(GFloat16(x)), sqrt(x), std::fabs(sqrt(x) / 1024)); + EXPECT_NEAR(sqrt(GFloat16(x)), sqrt(x), fabs(sqrt(x) / 1024)); } } @@ -166,7 +168,8 @@ TEST(TestFloat16, math) EXPECT_EQ(min(GFloat16(x), GFloat16(y)), GFloat16(min(x, y))); using std::pow; EXPECT_EQ(pow(GFloat16(x), GFloat16(y)), GFloat16(pow(x, y))); - EXPECT_NEAR(pow(GFloat16(x), j), GFloat16(pow(x, j))); + using std::fabs; + EXPECT_NEAR(pow(GFloat16(x), j), GFloat16(pow(x, j)), fabs(pow(x, j) / 1024)); } } }