[libc-commits] [libc] [libc][math] Adds entrypoint and tests for nearbyintf128, scalbnf128 (PR #88443)
Michael Flanders via libc-commits
libc-commits at lists.llvm.org
Fri Apr 12 16:00:27 PDT 2024
================
@@ -0,0 +1,105 @@
+//===-- 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 "hdr/fenv_macros.h"
+#include "src/__support/FPUtil/FEnvImpl.h"
+#include "src/__support/FPUtil/FPBits.h"
+#include "test/UnitTest/FPMatcher.h"
+#include "test/UnitTest/Test.h"
+
+static constexpr int ROUNDING_MODES[4] = {FE_UPWARD, FE_DOWNWARD, FE_TOWARDZERO,
+ FE_TONEAREST};
+
+template <typename T>
+class NearbyIntTestTemplate : public LIBC_NAMESPACE::testing::Test {
+
+ DECLARE_SPECIAL_CONSTANTS(T)
+
+public:
+ typedef T (*NearbyIntFunc)(T);
+
+ void testNaN(NearbyIntFunc func) { ASSERT_FP_EQ(func(aNaN), aNaN); }
+
+ void testInfinities(NearbyIntFunc func) {
+ ASSERT_FP_EQ(func(inf), inf);
+ ASSERT_FP_EQ(func(neg_inf), neg_inf);
+ }
+
+ void testZeroes(NearbyIntFunc func) {
+ ASSERT_FP_EQ(func(zero), zero);
+ ASSERT_FP_EQ(func(neg_zero), neg_zero);
+ }
+
+ void testIntegers(NearbyIntFunc func) {
+ for (int mode : ROUNDING_MODES) {
+ LIBC_NAMESPACE::fputil::set_round(mode);
----------------
Flandini wrote:
I switched them to using `ForceRoundingMode`. I also added some individual rounding mode matchers to `FPMatcher.h`.
https://github.com/llvm/llvm-project/pull/88443
More information about the libc-commits
mailing list