[libc-commits] [libc] [libc][math] Implement fpclassify macro. (PR #109519)
Shourya Goel via libc-commits
libc-commits at lists.llvm.org
Sat Sep 21 08:38:23 PDT 2024
https://github.com/Sh0g0-1758 updated https://github.com/llvm/llvm-project/pull/109519
>From 7b63f088f061f7a0ef4e9dac417e1a02251d47f0 Mon Sep 17 00:00:00 2001
From: Sh0g0-1758 <shouryagoel10000 at gmail.com>
Date: Sat, 21 Sep 2024 12:47:30 +0530
Subject: [PATCH 1/9] implement fpclassify
---
.../llvm-libc-macros/math-function-macros.h | 1 +
libc/test/include/CMakeLists.txt | 45 +++++++++++++++++
libc/test/include/FpClassifyTest.h | 50 +++++++++++++++++++
libc/test/include/fpclassify_test.c | 25 ++++++++++
libc/test/include/fpclassify_test.cpp | 12 +++++
libc/test/include/fpclassifyf_test.cpp | 12 +++++
libc/test/include/fpclassifyl_test.cpp | 12 +++++
7 files changed, 157 insertions(+)
create mode 100644 libc/test/include/FpClassifyTest.h
create mode 100644 libc/test/include/fpclassify_test.c
create mode 100644 libc/test/include/fpclassify_test.cpp
create mode 100644 libc/test/include/fpclassifyf_test.cpp
create mode 100644 libc/test/include/fpclassifyl_test.cpp
diff --git a/libc/include/llvm-libc-macros/math-function-macros.h b/libc/include/llvm-libc-macros/math-function-macros.h
index afbabd023203a2..0b7ee53a3a5a77 100644
--- a/libc/include/llvm-libc-macros/math-function-macros.h
+++ b/libc/include/llvm-libc-macros/math-function-macros.h
@@ -14,5 +14,6 @@
#define isnan(x) __builtin_isnan(x)
#define signbit(x) __builtin_signbit(x)
#define iszero(x) (x == 0)
+#define fpclassify(a, b, c, d, e, f) __builtin_fpclassify(a, b, c, d, e, f)
#endif // LLVM_LIBC_MACROS_MATH_FUNCTION_MACROS_H
diff --git a/libc/test/include/CMakeLists.txt b/libc/test/include/CMakeLists.txt
index 1a2f18731565c2..ca38b6fa48a236 100644
--- a/libc/test/include/CMakeLists.txt
+++ b/libc/test/include/CMakeLists.txt
@@ -81,6 +81,36 @@ add_libc_test(
libc.include.llvm-libc-macros.stdckdint_macros
)
+add_libc_test(
+ fpclassify_test
+ SUITE
+ libc_include_tests
+ SRCS
+ fpclassify_test.cpp
+ DEPENDS
+ libc.include.llvm-libc-macros.math_function_macros
+)
+
+add_libc_test(
+ fpclassifyf_test
+ SUITE
+ libc_include_tests
+ SRCS
+ fpclassifyf_test.cpp
+ DEPENDS
+ libc.include.llvm-libc-macros.math_function_macros
+)
+
+add_libc_test(
+ fpclassifyl_test
+ SUITE
+ libc_include_tests
+ SRCS
+ fpclassifyl_test.cpp
+ DEPENDS
+ libc.include.llvm-libc-macros.math_function_macros
+)
+
add_libc_test(
iszero_test
SUITE
@@ -291,6 +321,21 @@ add_libc_test(
libc.include.llvm-libc-macros.math_function_macros
)
+add_libc_test(
+ fpclassify_c_test
+ C_TEST
+ UNIT_TEST_ONLY
+ SUITE
+ libc_include_tests
+ SRCS
+ fpclassify_test.c
+ COMPILE_OPTIONS
+ -Wall
+ -Werror
+ DEPENDS
+ libc.include.llvm-libc-macros.math_function_macros
+)
+
add_libc_test(
iszero_c_test
C_TEST
diff --git a/libc/test/include/FpClassifyTest.h b/libc/test/include/FpClassifyTest.h
new file mode 100644
index 00000000000000..65edf77c2cd355
--- /dev/null
+++ b/libc/test/include/FpClassifyTest.h
@@ -0,0 +1,50 @@
+//===-- Utility class to test the fpclassify macro -----------------*- 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_FPCLASSIFY_H
+#define LLVM_LIBC_TEST_INCLUDE_MATH_FPCLASSIFY_H
+
+#include "test/UnitTest/FPMatcher.h"
+#include "test/UnitTest/Test.h"
+
+#include "include/llvm-libc-macros/math-function-macros.h"
+
+template <typename T> class FpClassifyTest : public LIBC_NAMESPACE::testing::Test {
+ DECLARE_SPECIAL_CONSTANTS(T)
+
+public:
+ typedef int (*FpClassifyFunc)(T, T, T, T, T, T);
+
+ void testSpecialNumbers(FpClassifyFunc func) {
+ EXPECT_EQ(func(1, 2, 3, 4, 5, inf), 1);
+ EXPECT_EQ(func(1, 2, 3, 4, 5, neg_inf), 1);
+ EXPECT_EQ(func(1, 2, 3, 4, 5, aNaN), 2);
+ EXPECT_EQ(func(1, 2, 3, 4, 5, neg_aNaN), 2);
+ EXPECT_EQ(func(1, 2, 3, 4, 5, sNaN), 2);
+ EXPECT_EQ(func(1, 2, 3, 4, 5, neg_sNaN), 2);
+ EXPECT_EQ(func(1, 2, 3, 4, 5, min_normal), 3);
+ EXPECT_EQ(func(1, 2, 3, 4, 5, max_normal), 3);
+ EXPECT_EQ(func(1, 2, 3, 4, 5, neg_max_normal), 3);
+ EXPECT_EQ(func(1, 2, 3, 4, 5, min_denormal), 4);
+ EXPECT_EQ(func(1, 2, 3, 4, 5, neg_min_denormal), 4);
+ EXPECT_EQ(func(1, 2, 3, 4, 5, max_denormal), 4);
+ EXPECT_EQ(func(1, 2, 3, 4, 5, zero), 5);
+ EXPECT_EQ(func(1, 2, 3, 4, 5, neg_zero), 5);
+ }
+};
+
+#define LIST_FPCLASSIFY_TESTS(T, func) \
+ using LlvmLibcFpClassifyTest = FpClassifyTest<T>; \
+ TEST_F(LlvmLibcFpClassifyTest, SpecialNumbers) { \
+ auto fpclassify_func = [](T a, T b, T c, T d, T e, T f) { \
+ return func(a, b, c, d, e, f); \
+ }; \
+ testSpecialNumbers(fpclassify_func); \
+ }
+
+#endif // LLVM_LIBC_TEST_INCLUDE_MATH_FPCLASSIFY_H
diff --git a/libc/test/include/fpclassify_test.c b/libc/test/include/fpclassify_test.c
new file mode 100644
index 00000000000000..f3b90bb6de87fc
--- /dev/null
+++ b/libc/test/include/fpclassify_test.c
@@ -0,0 +1,25 @@
+//===-- Unittests for fpclassify macro ------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDSList-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+#include "include/llvm-libc-macros/math-function-macros.h"
+
+#include <assert.h>
+
+// check if macro is defined
+#ifndef fpclassify
+#error "fpclassify macro is not defined"
+#else
+int main(void) {
+ assert(fpclassify(1, 2, 3, 4, 5, 1.819f) == 3);
+ assert(fpclassify(1, 2, 3, 4, 5, -1.726) == 3);
+ assert(fpclassify(1, 2, 3, 4, 5, 1.426L) == 3);
+ assert(fpclassify(1, 2, 3, 4, 5, -0.0f) == 5);
+ assert(fpclassify(1, 2, 3, 4, 5, 0.0) == 5);
+ assert(fpclassify(1, 2, 3, 4, 5, -0.0L) == 5);
+ return 0;
+}
+#endif
\ No newline at end of file
diff --git a/libc/test/include/fpclassify_test.cpp b/libc/test/include/fpclassify_test.cpp
new file mode 100644
index 00000000000000..93c8e3c7c60533
--- /dev/null
+++ b/libc/test/include/fpclassify_test.cpp
@@ -0,0 +1,12 @@
+//===-- Unittest for fpclassify[d] macro ----------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDSList-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "FpClassifyTest.h"
+#include "include/llvm-libc-macros/math-function-macros.h"
+
+LIST_FPCLASSIFY_TESTS(double, fpclassify)
diff --git a/libc/test/include/fpclassifyf_test.cpp b/libc/test/include/fpclassifyf_test.cpp
new file mode 100644
index 00000000000000..875482a6a233c7
--- /dev/null
+++ b/libc/test/include/fpclassifyf_test.cpp
@@ -0,0 +1,12 @@
+//===-- Unittest for fpclassify[f] macro ----------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDSList-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "FpClassifyTest.h"
+#include "include/llvm-libc-macros/math-function-macros.h"
+
+LIST_FPCLASSIFY_TESTS(float, fpclassify)
diff --git a/libc/test/include/fpclassifyl_test.cpp b/libc/test/include/fpclassifyl_test.cpp
new file mode 100644
index 00000000000000..6627956a0d35b9
--- /dev/null
+++ b/libc/test/include/fpclassifyl_test.cpp
@@ -0,0 +1,12 @@
+//===-- Unittest for fpclassify[l] macro ----------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDSList-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "FpClassifyTest.h"
+#include "include/llvm-libc-macros/math-function-macros.h"
+
+LIST_FPCLASSIFY_TESTS(long double, fpclassify)
>From 70d47819fbc429b2b93dfbc5fc4054865533ad75 Mon Sep 17 00:00:00 2001
From: Sh0g0-1758 <shouryagoel10000 at gmail.com>
Date: Sat, 21 Sep 2024 12:48:12 +0530
Subject: [PATCH 2/9] ran clang fmt
---
libc/test/include/FpClassifyTest.h | 8 +++++---
1 file changed, 5 insertions(+), 3 deletions(-)
diff --git a/libc/test/include/FpClassifyTest.h b/libc/test/include/FpClassifyTest.h
index 65edf77c2cd355..75a4ada899dd0c 100644
--- a/libc/test/include/FpClassifyTest.h
+++ b/libc/test/include/FpClassifyTest.h
@@ -1,4 +1,5 @@
-//===-- Utility class to test the fpclassify macro -----------------*- C++ -*-===//
+//===-- Utility class to test the fpclassify macro -----------------*- C++
+//-*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
@@ -14,7 +15,8 @@
#include "include/llvm-libc-macros/math-function-macros.h"
-template <typename T> class FpClassifyTest : public LIBC_NAMESPACE::testing::Test {
+template <typename T>
+class FpClassifyTest : public LIBC_NAMESPACE::testing::Test {
DECLARE_SPECIAL_CONSTANTS(T)
public:
@@ -42,7 +44,7 @@ template <typename T> class FpClassifyTest : public LIBC_NAMESPACE::testing::Tes
using LlvmLibcFpClassifyTest = FpClassifyTest<T>; \
TEST_F(LlvmLibcFpClassifyTest, SpecialNumbers) { \
auto fpclassify_func = [](T a, T b, T c, T d, T e, T f) { \
- return func(a, b, c, d, e, f); \
+ return func(a, b, c, d, e, f); \
}; \
testSpecialNumbers(fpclassify_func); \
}
>From 24bb08e415988e1db7454f1e7dec957215a8b6ed Mon Sep 17 00:00:00 2001
From: Sh0g0-1758 <shouryagoel10000 at gmail.com>
Date: Sat, 21 Sep 2024 12:50:25 +0530
Subject: [PATCH 3/9] added new line
---
libc/test/include/fpclassify_test.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/libc/test/include/fpclassify_test.c b/libc/test/include/fpclassify_test.c
index f3b90bb6de87fc..ecfcf4eb178d19 100644
--- a/libc/test/include/fpclassify_test.c
+++ b/libc/test/include/fpclassify_test.c
@@ -22,4 +22,4 @@ int main(void) {
assert(fpclassify(1, 2, 3, 4, 5, -0.0L) == 5);
return 0;
}
-#endif
\ No newline at end of file
+#endif
>From 428dc12fe6c999b2f33baadd412777f0fd55d651 Mon Sep 17 00:00:00 2001
From: Sh0g0-1758 <shouryagoel10000 at gmail.com>
Date: Sat, 21 Sep 2024 12:55:14 +0530
Subject: [PATCH 4/9] refactor tests
---
libc/test/include/FpClassifyTest.h | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)
diff --git a/libc/test/include/FpClassifyTest.h b/libc/test/include/FpClassifyTest.h
index 75a4ada899dd0c..48d7c32ce256c9 100644
--- a/libc/test/include/FpClassifyTest.h
+++ b/libc/test/include/FpClassifyTest.h
@@ -23,12 +23,12 @@ class FpClassifyTest : public LIBC_NAMESPACE::testing::Test {
typedef int (*FpClassifyFunc)(T, T, T, T, T, T);
void testSpecialNumbers(FpClassifyFunc func) {
- EXPECT_EQ(func(1, 2, 3, 4, 5, inf), 1);
- EXPECT_EQ(func(1, 2, 3, 4, 5, neg_inf), 1);
- EXPECT_EQ(func(1, 2, 3, 4, 5, aNaN), 2);
- EXPECT_EQ(func(1, 2, 3, 4, 5, neg_aNaN), 2);
- EXPECT_EQ(func(1, 2, 3, 4, 5, sNaN), 2);
- EXPECT_EQ(func(1, 2, 3, 4, 5, neg_sNaN), 2);
+ EXPECT_EQ(func(1, 2, 3, 4, 5, aNaN), 1);
+ EXPECT_EQ(func(1, 2, 3, 4, 5, neg_aNaN), 1);
+ EXPECT_EQ(func(1, 2, 3, 4, 5, sNaN), 1);
+ EXPECT_EQ(func(1, 2, 3, 4, 5, neg_sNaN), 1);
+ EXPECT_EQ(func(1, 2, 3, 4, 5, inf), 2);
+ EXPECT_EQ(func(1, 2, 3, 4, 5, neg_inf), 2);
EXPECT_EQ(func(1, 2, 3, 4, 5, min_normal), 3);
EXPECT_EQ(func(1, 2, 3, 4, 5, max_normal), 3);
EXPECT_EQ(func(1, 2, 3, 4, 5, neg_max_normal), 3);
>From ed468cb9ce87d12bb4972e58c1d1892306a71927 Mon Sep 17 00:00:00 2001
From: Sh0g0-1758 <shouryagoel10000 at gmail.com>
Date: Sat, 21 Sep 2024 19:43:28 +0530
Subject: [PATCH 5/9] nit
---
libc/test/include/FpClassifyTest.h | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/libc/test/include/FpClassifyTest.h b/libc/test/include/FpClassifyTest.h
index 48d7c32ce256c9..4cd9f1002a9091 100644
--- a/libc/test/include/FpClassifyTest.h
+++ b/libc/test/include/FpClassifyTest.h
@@ -1,5 +1,4 @@
-//===-- Utility class to test the fpclassify macro -----------------*- C++
-//-*-===//
+//===-- Utility class to test the fpclassify macro -------------*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
>From 9fa292124f23965d99a0be420eacbc1822a02ac7 Mon Sep 17 00:00:00 2001
From: Sh0g0-1758 <shouryagoel10000 at gmail.com>
Date: Sat, 21 Sep 2024 19:52:40 +0530
Subject: [PATCH 6/9] refactor function definition
---
.../llvm-libc-macros/math-function-macros.h | 4 +-
libc/test/include/FpClassifyTest.h | 40 +++++++++++--------
libc/test/include/fpclassify_test.c | 12 +++---
3 files changed, 32 insertions(+), 24 deletions(-)
diff --git a/libc/include/llvm-libc-macros/math-function-macros.h b/libc/include/llvm-libc-macros/math-function-macros.h
index 0b7ee53a3a5a77..ef1be1005787eb 100644
--- a/libc/include/llvm-libc-macros/math-function-macros.h
+++ b/libc/include/llvm-libc-macros/math-function-macros.h
@@ -9,11 +9,13 @@
#ifndef LLVM_LIBC_MACROS_MATH_FUNCTION_MACROS_H
#define LLVM_LIBC_MACROS_MATH_FUNCTION_MACROS_H
+#include "math-macros.h"
+
#define isfinite(x) __builtin_isfinite(x)
#define isinf(x) __builtin_isinf(x)
#define isnan(x) __builtin_isnan(x)
#define signbit(x) __builtin_signbit(x)
#define iszero(x) (x == 0)
-#define fpclassify(a, b, c, d, e, f) __builtin_fpclassify(a, b, c, d, e, f)
+#define fpclassify(x) __builtin_fpclassify(FP_NAN, FP_INFINITE, FP_NORMAL, FP_SUBNORMAL, FP_ZERO, x)
#endif // LLVM_LIBC_MACROS_MATH_FUNCTION_MACROS_H
diff --git a/libc/test/include/FpClassifyTest.h b/libc/test/include/FpClassifyTest.h
index 4cd9f1002a9091..924b2e3518e37f 100644
--- a/libc/test/include/FpClassifyTest.h
+++ b/libc/test/include/FpClassifyTest.h
@@ -19,31 +19,37 @@ class FpClassifyTest : public LIBC_NAMESPACE::testing::Test {
DECLARE_SPECIAL_CONSTANTS(T)
public:
- typedef int (*FpClassifyFunc)(T, T, T, T, T, T);
+ typedef int (*FpClassifyFunc)(T);
void testSpecialNumbers(FpClassifyFunc func) {
- EXPECT_EQ(func(1, 2, 3, 4, 5, aNaN), 1);
- EXPECT_EQ(func(1, 2, 3, 4, 5, neg_aNaN), 1);
- EXPECT_EQ(func(1, 2, 3, 4, 5, sNaN), 1);
- EXPECT_EQ(func(1, 2, 3, 4, 5, neg_sNaN), 1);
- EXPECT_EQ(func(1, 2, 3, 4, 5, inf), 2);
- EXPECT_EQ(func(1, 2, 3, 4, 5, neg_inf), 2);
- EXPECT_EQ(func(1, 2, 3, 4, 5, min_normal), 3);
- EXPECT_EQ(func(1, 2, 3, 4, 5, max_normal), 3);
- EXPECT_EQ(func(1, 2, 3, 4, 5, neg_max_normal), 3);
- EXPECT_EQ(func(1, 2, 3, 4, 5, min_denormal), 4);
- EXPECT_EQ(func(1, 2, 3, 4, 5, neg_min_denormal), 4);
- EXPECT_EQ(func(1, 2, 3, 4, 5, max_denormal), 4);
- EXPECT_EQ(func(1, 2, 3, 4, 5, zero), 5);
- EXPECT_EQ(func(1, 2, 3, 4, 5, neg_zero), 5);
+ EXPECT_EQ(func(aNaN), 0);
+ EXPECT_EQ(func(neg_aNaN), 0);
+ EXPECT_EQ(func(sNaN), 0);
+ EXPECT_EQ(func(neg_sNaN), 0);
+ EXPECT_EQ(func(inf), 1);
+ EXPECT_EQ(func(neg_inf), 1);
+ EXPECT_EQ(func(min_normal), 4);
+ EXPECT_EQ(func(max_normal), 4);
+ EXPECT_EQ(func(neg_max_normal), 4);
+ EXPECT_EQ(func(min_denormal), 3);
+ EXPECT_EQ(func(neg_min_denormal), 3);
+ EXPECT_EQ(func(max_denormal), 3);
+ EXPECT_EQ(func(zero), 2);
+ EXPECT_EQ(func(neg_zero), 2);
}
};
+#define FP_NAN 0
+#define FP_INFINITE 1
+#define FP_ZERO 2
+#define FP_SUBNORMAL 3
+#define FP_NORMAL 4
+
#define LIST_FPCLASSIFY_TESTS(T, func) \
using LlvmLibcFpClassifyTest = FpClassifyTest<T>; \
TEST_F(LlvmLibcFpClassifyTest, SpecialNumbers) { \
- auto fpclassify_func = [](T a, T b, T c, T d, T e, T f) { \
- return func(a, b, c, d, e, f); \
+ auto fpclassify_func = [](T x) { \
+ return func(x); \
}; \
testSpecialNumbers(fpclassify_func); \
}
diff --git a/libc/test/include/fpclassify_test.c b/libc/test/include/fpclassify_test.c
index ecfcf4eb178d19..436e3cca2b5f0a 100644
--- a/libc/test/include/fpclassify_test.c
+++ b/libc/test/include/fpclassify_test.c
@@ -14,12 +14,12 @@
#error "fpclassify macro is not defined"
#else
int main(void) {
- assert(fpclassify(1, 2, 3, 4, 5, 1.819f) == 3);
- assert(fpclassify(1, 2, 3, 4, 5, -1.726) == 3);
- assert(fpclassify(1, 2, 3, 4, 5, 1.426L) == 3);
- assert(fpclassify(1, 2, 3, 4, 5, -0.0f) == 5);
- assert(fpclassify(1, 2, 3, 4, 5, 0.0) == 5);
- assert(fpclassify(1, 2, 3, 4, 5, -0.0L) == 5);
+ assert(fpclassify(1.819f) == 4);
+ assert(fpclassify(-1.726) == 4);
+ assert(fpclassify(1.426L) == 4);
+ assert(fpclassify(-0.0f) == 2);
+ assert(fpclassify(0.0) == 2);
+ assert(fpclassify(-0.0L) == 2);
return 0;
}
#endif
>From 1e808ab3105f53cd55099352f5f1612252c5147a Mon Sep 17 00:00:00 2001
From: Sh0g0-1758 <shouryagoel10000 at gmail.com>
Date: Sat, 21 Sep 2024 19:53:46 +0530
Subject: [PATCH 7/9] ran git clang format
---
libc/include/llvm-libc-macros/math-function-macros.h | 3 ++-
libc/test/include/FpClassifyTest.h | 4 +---
2 files changed, 3 insertions(+), 4 deletions(-)
diff --git a/libc/include/llvm-libc-macros/math-function-macros.h b/libc/include/llvm-libc-macros/math-function-macros.h
index ef1be1005787eb..4eaeb6958a5cb4 100644
--- a/libc/include/llvm-libc-macros/math-function-macros.h
+++ b/libc/include/llvm-libc-macros/math-function-macros.h
@@ -16,6 +16,7 @@
#define isnan(x) __builtin_isnan(x)
#define signbit(x) __builtin_signbit(x)
#define iszero(x) (x == 0)
-#define fpclassify(x) __builtin_fpclassify(FP_NAN, FP_INFINITE, FP_NORMAL, FP_SUBNORMAL, FP_ZERO, x)
+#define fpclassify(x) \
+ __builtin_fpclassify(FP_NAN, FP_INFINITE, FP_NORMAL, FP_SUBNORMAL, FP_ZERO, x)
#endif // LLVM_LIBC_MACROS_MATH_FUNCTION_MACROS_H
diff --git a/libc/test/include/FpClassifyTest.h b/libc/test/include/FpClassifyTest.h
index 924b2e3518e37f..292a7f8890a59e 100644
--- a/libc/test/include/FpClassifyTest.h
+++ b/libc/test/include/FpClassifyTest.h
@@ -48,9 +48,7 @@ class FpClassifyTest : public LIBC_NAMESPACE::testing::Test {
#define LIST_FPCLASSIFY_TESTS(T, func) \
using LlvmLibcFpClassifyTest = FpClassifyTest<T>; \
TEST_F(LlvmLibcFpClassifyTest, SpecialNumbers) { \
- auto fpclassify_func = [](T x) { \
- return func(x); \
- }; \
+ auto fpclassify_func = [](T x) { return func(x); }; \
testSpecialNumbers(fpclassify_func); \
}
>From 1fa264dcc97d3ab45921a2828ba5281103b78f13 Mon Sep 17 00:00:00 2001
From: Sh0g0-1758 <shouryagoel10000 at gmail.com>
Date: Sat, 21 Sep 2024 19:55:58 +0530
Subject: [PATCH 8/9] nit
---
libc/test/include/FpClassifyTest.h | 6 ------
1 file changed, 6 deletions(-)
diff --git a/libc/test/include/FpClassifyTest.h b/libc/test/include/FpClassifyTest.h
index 292a7f8890a59e..ef2716b03979a4 100644
--- a/libc/test/include/FpClassifyTest.h
+++ b/libc/test/include/FpClassifyTest.h
@@ -39,12 +39,6 @@ class FpClassifyTest : public LIBC_NAMESPACE::testing::Test {
}
};
-#define FP_NAN 0
-#define FP_INFINITE 1
-#define FP_ZERO 2
-#define FP_SUBNORMAL 3
-#define FP_NORMAL 4
-
#define LIST_FPCLASSIFY_TESTS(T, func) \
using LlvmLibcFpClassifyTest = FpClassifyTest<T>; \
TEST_F(LlvmLibcFpClassifyTest, SpecialNumbers) { \
>From 7ec31f6e73c7dd7700dde585141a9d22a010b9b4 Mon Sep 17 00:00:00 2001
From: Sh0g0-1758 <shouryagoel10000 at gmail.com>
Date: Sat, 21 Sep 2024 21:07:53 +0530
Subject: [PATCH 9/9] nit
---
libc/test/include/FpClassifyTest.h | 28 ++++++++++++++--------------
libc/test/include/fpclassify_test.c | 12 ++++++------
2 files changed, 20 insertions(+), 20 deletions(-)
diff --git a/libc/test/include/FpClassifyTest.h b/libc/test/include/FpClassifyTest.h
index ef2716b03979a4..067ce4df083fe3 100644
--- a/libc/test/include/FpClassifyTest.h
+++ b/libc/test/include/FpClassifyTest.h
@@ -22,20 +22,20 @@ class FpClassifyTest : public LIBC_NAMESPACE::testing::Test {
typedef int (*FpClassifyFunc)(T);
void testSpecialNumbers(FpClassifyFunc func) {
- EXPECT_EQ(func(aNaN), 0);
- EXPECT_EQ(func(neg_aNaN), 0);
- EXPECT_EQ(func(sNaN), 0);
- EXPECT_EQ(func(neg_sNaN), 0);
- EXPECT_EQ(func(inf), 1);
- EXPECT_EQ(func(neg_inf), 1);
- EXPECT_EQ(func(min_normal), 4);
- EXPECT_EQ(func(max_normal), 4);
- EXPECT_EQ(func(neg_max_normal), 4);
- EXPECT_EQ(func(min_denormal), 3);
- EXPECT_EQ(func(neg_min_denormal), 3);
- EXPECT_EQ(func(max_denormal), 3);
- EXPECT_EQ(func(zero), 2);
- EXPECT_EQ(func(neg_zero), 2);
+ EXPECT_EQ(func(aNaN), FP_NAN);
+ EXPECT_EQ(func(neg_aNaN), FP_NAN);
+ EXPECT_EQ(func(sNaN), FP_NAN);
+ EXPECT_EQ(func(neg_sNaN), FP_NAN);
+ EXPECT_EQ(func(inf), FP_INFINITE);
+ EXPECT_EQ(func(neg_inf), FP_INFINITE);
+ EXPECT_EQ(func(min_normal), FP_NORMAL);
+ EXPECT_EQ(func(max_normal), FP_NORMAL);
+ EXPECT_EQ(func(neg_max_normal), FP_NORMAL);
+ EXPECT_EQ(func(min_denormal), FP_SUBNORMAL);
+ EXPECT_EQ(func(neg_min_denormal), FP_SUBNORMAL);
+ EXPECT_EQ(func(max_denormal), FP_SUBNORMAL);
+ EXPECT_EQ(func(zero), FP_ZERO);
+ EXPECT_EQ(func(neg_zero), FP_ZERO);
}
};
diff --git a/libc/test/include/fpclassify_test.c b/libc/test/include/fpclassify_test.c
index 436e3cca2b5f0a..9a9b62cfdc70a5 100644
--- a/libc/test/include/fpclassify_test.c
+++ b/libc/test/include/fpclassify_test.c
@@ -14,12 +14,12 @@
#error "fpclassify macro is not defined"
#else
int main(void) {
- assert(fpclassify(1.819f) == 4);
- assert(fpclassify(-1.726) == 4);
- assert(fpclassify(1.426L) == 4);
- assert(fpclassify(-0.0f) == 2);
- assert(fpclassify(0.0) == 2);
- assert(fpclassify(-0.0L) == 2);
+ assert(fpclassify(1.819f) == FP_NORMAL);
+ assert(fpclassify(-1.726) == FP_NORMAL);
+ assert(fpclassify(1.426L) == FP_NORMAL);
+ assert(fpclassify(-0.0f) == FP_ZERO);
+ assert(fpclassify(0.0) == FP_ZERO);
+ assert(fpclassify(-0.0L) == FP_ZERO);
return 0;
}
#endif
More information about the libc-commits
mailing list