[libc-commits] [libc] [libc][math] Add MPFR unit tests for nearbyint{, f, l, f16} (PR #94479)

via libc-commits libc-commits at lists.llvm.org
Wed Jun 26 14:04:07 PDT 2024


================
@@ -0,0 +1,128 @@
+//===-- Utility class to test different flavors of nearbyint ----*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_TEST_SRC_MATH_NEARBYINTTEST_H
+#define LLVM_LIBC_TEST_SRC_MATH_NEARBYINTTEST_H
+
+#include "src/__support/CPP/algorithm.h"
+#include "src/__support/FPUtil/FEnvImpl.h"
+#include "test/UnitTest/FEnvSafeTest.h"
+#include "test/UnitTest/FPMatcher.h"
+#include "test/UnitTest/Test.h"
+#include "utils/MPFRWrapper/MPFRUtils.h"
+
+#include "hdr/fenv_macros.h"
+
+namespace mpfr = LIBC_NAMESPACE::testing::mpfr;
+
+template <typename T>
+class NearbyIntTestTemplate : public LIBC_NAMESPACE::testing::FEnvSafeTest {
+
+  DECLARE_SPECIAL_CONSTANTS(T)
+
+  static constexpr int ROUNDING_MODES[4] = {FE_UPWARD, FE_DOWNWARD,
----------------
lntue wrote:

Why don't you use:
```
using namespace LIBC_NAMESPACE::fputil::testing;
static constexpr RoundingMode ROUNDING_MODES[4] = { RoundingMode::Upward, ... };
```

Then you can replace all the `LIBC_NAMESPACE::fputil::set_round()` below with:
```
    ForceRoundingMode __r(mode);
    if (__r.success) {
      ...
    }
```

https://github.com/llvm/llvm-project/pull/94479


More information about the libc-commits mailing list