[libc-commits] [libc] [libc][math][c23] Implement canonicalize functions (PR #85940)

via libc-commits libc-commits at lists.llvm.org
Sun Mar 24 08:18:38 PDT 2024


================
@@ -0,0 +1,192 @@
+//===-- Utility class to test canonicalize[f|l] -----------------*- 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_SMOKE_CANONICALIZETEST_H
+#define LLVM_LIBC_TEST_SRC_MATH_SMOKE_CANONICALIZETEST_H
+
+#include "src/__support/FPUtil/FPBits.h"
+#include "test/UnitTest/FPMatcher.h"
+#include "test/UnitTest/Test.h"
+
+#include "include/llvm-libc-macros/math-macros.h"
+
+#define TEST_SPECIAL(x, y, expected, expected_exception)                       \
+  EXPECT_FP_EQ(expected, f(&x, &y));                                           \
+  EXPECT_FP_EXCEPTION(expected_exception);                                     \
+  LIBC_NAMESPACE::fputil::clear_except(FE_ALL_EXCEPT)
+
+#define TEST_REGULAR(x, y, expected) TEST_SPECIAL(x, y, expected, 0)
+
+template <typename T>
+class CanonicalizeTest : public LIBC_NAMESPACE::testing::Test {
+
+  DECLARE_SPECIAL_CONSTANTS(T)
+
+public:
+  typedef T (*CanonicalizeFunc)(T *, T *);
+  using FPBits = LIBC_NAMESPACE::fputil::FPBits<T>;
+  using StorageType = typename FPBits::StorageType;
+
+  void testSpecialNumbers(CanonicalizeFunc f) {
+    T cx;
+    TEST_SPECIAL(cx, zero, 0, 0);
+    EXPECT_EQ(cx, T(0.0));
+    TEST_SPECIAL(cx, neg_zero, 0, 0);
+    EXPECT_EQ(cx, T(-0.0));
+    TEST_SPECIAL(cx, inf, 0, 0);
+    EXPECT_EQ(cx, inf);
+    TEST_SPECIAL(cx, neg_inf, 0, 0);
+    EXPECT_EQ(cx, neg_inf);
+    TEST_SPECIAL(cx, sNaN, 1, FE_INVALID);
+    EXPECT_EQ(cx, aNaN);
+    TEST_SPECIAL(cx, -sNaN, 1, FE_INVALID);
+    EXPECT_EQ(cx, -aNaN);
+  }
+
+  if constexpr (LIBC_NAMESPACE::fputil::get_fp_type() == FPType::X86_Binary80) {
+    void testX64_80SpecialNumbers(CanonicalizeFunc f) {
----------------
lntue wrote:

the `if constexpr` should be inside the test function body.

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


More information about the libc-commits mailing list