[libc-commits] [libc] [libc][math] implement `signbit` (PR #97791)
via libc-commits
libc-commits at lists.llvm.org
Wed Jul 10 08:18:12 PDT 2024
================
@@ -0,0 +1,59 @@
+//===-- Utility class to test the signbit macro [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_INCLUDE_MATH_SIGNBIT_H
+#define LLVM_LIBC_TEST_INCLUDE_MATH_SIGNBIT_H
+
+#include "test/UnitTest/FEnvSafeTest.h"
+#include "test/UnitTest/FPMatcher.h"
+#include "test/UnitTest/Test.h"
+
+#include "include/llvm-libc-macros/math-function-macros.h"
+
+#define PI 3.14159265358979323846
+
+template <typename T>
+class SignbitTest : public LIBC_NAMESPACE::testing::FEnvSafeTest {
+
+ DECLARE_SPECIAL_CONSTANTS(T)
+
+public:
+ typedef bool (*SignbitFunc)(T);
+
+ void testSpecialNumbers(SignbitFunc func) {
+ EXPECT_EQ(signbit(zero), 0);
+ EXPECT_EQ(signbit(PI), 0);
+ EXPECT_EQ(signbit(inf), 0);
+ EXPECT_EQ(signbit(aNaN), 0);
+
+ EXPECT_EQ(signbit(neg_zero), 1);
+ EXPECT_EQ(signbit(-PI), 1);
+ EXPECT_EQ(signbit(neg_inf), 1);
+ EXPECT_EQ(signbit(neg_aNaN), 1);
+ }
+
+ void testSpecialCases(SignbitFunc func) {
----------------
lntue wrote:
We don't need / should not testing `signbit` in combination with other operations. This test might be fragile, for example, `inf + neg_inf` is a NaN, but it could be signed or unsigned. The above `testSpecialNumbers` is enough.
https://github.com/llvm/llvm-project/pull/97791
More information about the libc-commits
mailing list