Skip to content

Commit

Permalink
Correct tolerances in float16 test
Browse files Browse the repository at this point in the history
  • Loading branch information
eschnett committed Jan 28, 2025
1 parent 3454bd9 commit ee58a50
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions autotest/cpp/testfloat16.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
}
}
Expand Down Expand Up @@ -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;
Expand All @@ -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));
}
}

Expand All @@ -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));
}
}
}
Expand Down

0 comments on commit ee58a50

Please sign in to comment.