[libc-commits] [libc] [libc][math][c23] Add MPFR exhaustive test for fmodf16 (PR #94656)
via libc-commits
libc-commits at lists.llvm.org
Mon Jun 24 15:39:23 PDT 2024
================
@@ -68,22 +69,84 @@ struct UnaryOpChecker : public virtual LIBC_NAMESPACE::testing::Test {
}
};
+template <typename OutType, typename InType = OutType>
+using BinaryOp = OutType(InType, InType);
+
+template <typename OutType, typename InType, mpfr::Operation Op,
+ BinaryOp<OutType, InType> Func>
+struct BinaryOpChecker : public virtual LIBC_NAMESPACE::testing::Test {
+ using FloatType = InType;
+ using FPBits = LIBC_NAMESPACE::fputil::FPBits<FloatType>;
+ using StorageType = typename FPBits::StorageType;
+
+ // Check in a range, return the number of failures.
+ uint64_t check(StorageType x_start, StorageType x_stop, StorageType y_start,
+ StorageType y_stop, mpfr::RoundingMode rounding) {
+ mpfr::ForceRoundingMode r(rounding);
+ if (!r.success)
+ return x_stop > x_start || y_stop > y_start;
+ StorageType xbits = x_start;
+ uint64_t failed = 0;
+ do {
+ FloatType x = FPBits(xbits).get_val();
+ StorageType ybits = y_start;
+ do {
+ FloatType y = FPBits(ybits).get_val();
+ mpfr::BinaryInput<FloatType> input{x, y};
+ bool correct = TEST_MPFR_MATCH_ROUNDING_SILENTLY(Op, input, Func(x, y),
+ 0.5, rounding);
+ failed += (!correct);
+ // Uncomment to print out failed values.
+ // if (!correct) {
+ // EXPECT_MPFR_MATCH_ROUNDING(Op, input, Func(x, y), 0.5, rounding);
+ // }
+ } while (ybits++ < y_stop);
+ } while (xbits++ < x_stop);
+ return failed;
+ }
+};
+
// Checker class needs inherit from LIBC_NAMESPACE::testing::Test and provide
// StorageType and check method.
-template <typename Checker>
+template <typename Checker, size_t Increment = 1 << 20>
struct LlvmLibcExhaustiveMathTest
: public virtual LIBC_NAMESPACE::testing::Test,
public Checker {
using FloatType = typename Checker::FloatType;
using FPBits = typename Checker::FPBits;
using StorageType = typename Checker::StorageType;
- static constexpr StorageType INCREMENT = (1 << 20);
+ static constexpr StorageType INCREMENT = Increment;
----------------
overmighty wrote:
Should probably get rid of this and use the template argument directly.
https://github.com/llvm/llvm-project/pull/94656
More information about the libc-commits
mailing list