From 3604c23dfc8edb00aae72456ef3ff765eb795db5 Mon Sep 17 00:00:00 2001 From: Akiel <56521583+akielaries@users.noreply.github.com> Date: Sat, 13 Jul 2024 20:01:36 -0700 Subject: [PATCH] [libc][math] implement `signbit` and math macro unit tests (#97791) This PR resolves #96322 and implements the `signbit` macro under a new header `generic-math-macros.h`. This also removed the `TODO` in `math-macros.h` and moves `isfinite`, `isinf`, and `isnan` to the same generic maths header. Finally, a test file `generic-math-macros_test.cpp` that adds coverage to the above 4 macros. Fixes #96322. --- .../llvm-libc-macros/math-function-macros.h | 1 + libc/test/include/CMakeLists.txt | 180 ++++++++++++++++++ libc/test/include/IsFiniteTest.h | 39 ++++ libc/test/include/IsInfTest.h | 39 ++++ libc/test/include/IsNanTest.h | 39 ++++ libc/test/include/SignbitTest.h | 37 ++++ libc/test/include/isfinite_test.c | 22 +++ libc/test/include/isfinite_test.cpp | 12 ++ libc/test/include/isfinitef_test.cpp | 12 ++ libc/test/include/isfinitel_test.cpp | 12 ++ libc/test/include/isinf_test.c | 22 +++ libc/test/include/isinf_test.cpp | 12 ++ libc/test/include/isinff_test.cpp | 12 ++ libc/test/include/isinfl_test.cpp | 12 ++ libc/test/include/isnan_test.c | 22 +++ libc/test/include/isnan_test.cpp | 12 ++ libc/test/include/isnanf_test.cpp | 12 ++ libc/test/include/isnanl_test.cpp | 12 ++ libc/test/include/signbit_test.c | 25 +++ libc/test/include/signbit_test.cpp | 12 ++ libc/test/include/signbitf_test.cpp | 12 ++ libc/test/include/signbitl_test.cpp | 12 ++ 22 files changed, 570 insertions(+) create mode 100644 libc/test/include/IsFiniteTest.h create mode 100644 libc/test/include/IsInfTest.h create mode 100644 libc/test/include/IsNanTest.h create mode 100644 libc/test/include/SignbitTest.h create mode 100644 libc/test/include/isfinite_test.c create mode 100644 libc/test/include/isfinite_test.cpp create mode 100644 libc/test/include/isfinitef_test.cpp create mode 100644 libc/test/include/isfinitel_test.cpp create mode 100644 libc/test/include/isinf_test.c create mode 100644 libc/test/include/isinf_test.cpp create mode 100644 libc/test/include/isinff_test.cpp create mode 100644 libc/test/include/isinfl_test.cpp create mode 100644 libc/test/include/isnan_test.c create mode 100644 libc/test/include/isnan_test.cpp create mode 100644 libc/test/include/isnanf_test.cpp create mode 100644 libc/test/include/isnanl_test.cpp create mode 100644 libc/test/include/signbit_test.c create mode 100644 libc/test/include/signbit_test.cpp create mode 100644 libc/test/include/signbitf_test.cpp create mode 100644 libc/test/include/signbitl_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 551719af2b4d..8d18997bed8d 100644 --- a/libc/include/llvm-libc-macros/math-function-macros.h +++ b/libc/include/llvm-libc-macros/math-function-macros.h @@ -12,5 +12,6 @@ #define isfinite(x) __builtin_isfinite(x) #define isinf(x) __builtin_isinf(x) #define isnan(x) __builtin_isnan(x) +#define signbit(x) __builtin_signbit(x) #endif // LLVM_LIBC_MACROS_MATH_FUNCTION_MACROS_H diff --git a/libc/test/include/CMakeLists.txt b/libc/test/include/CMakeLists.txt index 4be42289f8fe..32513f234b9b 100644 --- a/libc/test/include/CMakeLists.txt +++ b/libc/test/include/CMakeLists.txt @@ -80,3 +80,183 @@ add_libc_test( DEPENDS libc.include.llvm-libc-macros.stdckdint_macros ) + +add_libc_test( + signbit_test + SUITE + libc_include_tests + SRCS + signbit_test.cpp + DEPENDS + libc.include.llvm-libc-macros.math_function_macros +) + +add_libc_test( + signbitf_test + SUITE + libc_include_tests + SRCS + signbitf_test.cpp + DEPENDS + libc.include.llvm-libc-macros.math_function_macros +) + +add_libc_test( + signbitl_test + SUITE + libc_include_tests + SRCS + signbitl_test.cpp + DEPENDS + libc.include.llvm-libc-macros.math_function_macros +) + +add_libc_test( + isnan_test + SUITE + libc_include_tests + SRCS + isnan_test.cpp + DEPENDS + libc.include.llvm-libc-macros.math_function_macros +) + +add_libc_test( + isnanf_test + SUITE + libc_include_tests + SRCS + isnanf_test.cpp + DEPENDS + libc.include.llvm-libc-macros.math_function_macros +) + +add_libc_test( + isnanl_test + SUITE + libc_include_tests + SRCS + isnanl_test.cpp + DEPENDS + libc.include.llvm-libc-macros.math_function_macros +) + +add_libc_test( + isinf_test + SUITE + libc_include_tests + SRCS + isinf_test.cpp + DEPENDS + libc.include.llvm-libc-macros.math_function_macros +) + +add_libc_test( + isinff_test + SUITE + libc_include_tests + SRCS + isinff_test.cpp + DEPENDS + libc.include.llvm-libc-macros.math_function_macros +) + +add_libc_test( + isinfl_test + SUITE + libc_include_tests + SRCS + isinfl_test.cpp + DEPENDS + libc.include.llvm-libc-macros.math_function_macros +) + +add_libc_test( + isfinite_test + SUITE + libc_include_tests + SRCS + isfinite_test.cpp + DEPENDS + libc.include.llvm-libc-macros.math_function_macros +) + +add_libc_test( + isfinitef_test + SUITE + libc_include_tests + SRCS + isfinitef_test.cpp + DEPENDS + libc.include.llvm-libc-macros.math_function_macros +) + +add_libc_test( + isfinitel_test + SUITE + libc_include_tests + SRCS + isfinitel_test.cpp + DEPENDS + libc.include.llvm-libc-macros.math_function_macros +) + +add_libc_test( + signbit_c_test + C_TEST + UNIT_TEST_ONLY + SUITE + libc_include_tests + SRCS + signbit_test.c + COMPILE_OPTIONS + -Wall + -Werror + DEPENDS + libc.include.llvm-libc-macros.math_function_macros +) + +add_libc_test( + isnan_c_test + C_TEST + UNIT_TEST_ONLY + SUITE + libc_include_tests + SRCS + isnan_test.c + COMPILE_OPTIONS + -Wall + -Werror + DEPENDS + libc.include.llvm-libc-macros.math_function_macros +) + +add_libc_test( + isinf_c_test + C_TEST + UNIT_TEST_ONLY + SUITE + libc_include_tests + SRCS + isinf_test.c + COMPILE_OPTIONS + -Wall + -Werror + DEPENDS + libc.include.llvm-libc-macros.math_function_macros +) + +add_libc_test( + isfinite_c_test + C_TEST + UNIT_TEST_ONLY + SUITE + libc_include_tests + SRCS + isfinite_test.c + COMPILE_OPTIONS + -Wall + -Werror + DEPENDS + libc.include.llvm-libc-macros.math_function_macros +) diff --git a/libc/test/include/IsFiniteTest.h b/libc/test/include/IsFiniteTest.h new file mode 100644 index 000000000000..3d2fc0daae4c --- /dev/null +++ b/libc/test/include/IsFiniteTest.h @@ -0,0 +1,39 @@ +//===-- Utility class to test the isfinite 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_ISFINITE_H +#define LLVM_LIBC_TEST_INCLUDE_MATH_ISFINITE_H + +#include "test/UnitTest/FPMatcher.h" +#include "test/UnitTest/Test.h" + +#include "include/llvm-libc-macros/math-function-macros.h" + +template +class IsFiniteTest : public LIBC_NAMESPACE::testing::Test { + DECLARE_SPECIAL_CONSTANTS(T) + +public: + typedef int (*IsFiniteFunc)(T); + + void testSpecialNumbers(IsFiniteFunc func) { + EXPECT_EQ(func(inf), 0); + EXPECT_EQ(func(neg_inf), 0); + EXPECT_EQ(func(zero), 1); + EXPECT_EQ(func(neg_zero), 1); + } +}; + +#define LIST_ISFINITE_TESTS(T, func) \ + using LlvmLibcIsFiniteTest = IsFiniteTest; \ + TEST_F(LlvmLibcIsFiniteTest, SpecialNumbers) { \ + auto isfinite_func = [](T x) { return func(x); }; \ + testSpecialNumbers(isfinite_func); \ + } + +#endif // LLVM_LIBC_TEST_INCLUDE_MATH_ISFINITE_H diff --git a/libc/test/include/IsInfTest.h b/libc/test/include/IsInfTest.h new file mode 100644 index 000000000000..7993a49c15fe --- /dev/null +++ b/libc/test/include/IsInfTest.h @@ -0,0 +1,39 @@ +//===-- Utility class to test the isinf 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_ISINF_H +#define LLVM_LIBC_TEST_INCLUDE_MATH_ISINF_H + +#include "test/UnitTest/FPMatcher.h" +#include "test/UnitTest/Test.h" + +#include "include/llvm-libc-macros/math-function-macros.h" + +template class IsInfTest : public LIBC_NAMESPACE::testing::Test { + + DECLARE_SPECIAL_CONSTANTS(T) + +public: + typedef int (*IsInfFunc)(T); + + void testSpecialNumbers(IsInfFunc func) { + EXPECT_EQ(func(zero), 0); + EXPECT_EQ(func(neg_zero), 0); + EXPECT_EQ(func(inf), 1); + EXPECT_EQ(func(neg_inf), 1); + } +}; + +#define LIST_ISINF_TESTS(T, func) \ + using LlvmLibcIsInfTest = IsInfTest; \ + TEST_F(LlvmLibcIsInfTest, SpecialNumbers) { \ + auto isinf_func = [](T x) { return func(x); }; \ + testSpecialNumbers(isinf_func); \ + } + +#endif // LLVM_LIBC_TEST_INCLUDE_MATH_ISINF_H diff --git a/libc/test/include/IsNanTest.h b/libc/test/include/IsNanTest.h new file mode 100644 index 000000000000..362699a18dfc --- /dev/null +++ b/libc/test/include/IsNanTest.h @@ -0,0 +1,39 @@ +//===-- Utility class to test the isnan 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 nanormation. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_LIBC_TEST_INCLUDE_MATH_ISNAN_H +#define LLVM_LIBC_TEST_INCLUDE_MATH_ISNAN_H + +#include "test/UnitTest/FPMatcher.h" +#include "test/UnitTest/Test.h" + +#include "include/llvm-libc-macros/math-function-macros.h" + +template class IsNanTest : public LIBC_NAMESPACE::testing::Test { + + DECLARE_SPECIAL_CONSTANTS(T) + +public: + typedef int (*IsNanFunc)(T); + + void testSpecialNumbers(IsNanFunc func) { + EXPECT_EQ(func(zero), 0); + EXPECT_EQ(func(neg_zero), 0); + EXPECT_EQ(func(aNaN), 1); + EXPECT_EQ(func(sNaN), 1); + } +}; + +#define LIST_ISNAN_TESTS(T, func) \ + using LlvmLibcIsNanTest = IsNanTest; \ + TEST_F(LlvmLibcIsNanTest, SpecialNumbers) { \ + auto isnan_func = [](T x) { return func(x); }; \ + testSpecialNumbers(isnan_func); \ + } + +#endif // LLVM_LIBC_TEST_INCLUDE_MATH_ISNAN_H diff --git a/libc/test/include/SignbitTest.h b/libc/test/include/SignbitTest.h new file mode 100644 index 000000000000..85d499823088 --- /dev/null +++ b/libc/test/include/SignbitTest.h @@ -0,0 +1,37 @@ +//===-- 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/FPMatcher.h" +#include "test/UnitTest/Test.h" + +#include "include/llvm-libc-macros/math-function-macros.h" + +template class SignbitTest : public LIBC_NAMESPACE::testing::Test { + + DECLARE_SPECIAL_CONSTANTS(T) + +public: + typedef int (*SignbitFunc)(T); + + void testSpecialNumbers(SignbitFunc func) { + EXPECT_EQ(func(1), 0); + EXPECT_EQ(func(-1), 1); + } +}; + +#define LIST_SIGNBIT_TESTS(T, func) \ + using LlvmLibcSignbitTest = SignbitTest; \ + TEST_F(LlvmLibcSignbitTest, SpecialNumbers) { \ + auto signbit_func = [](T x) { return func(x); }; \ + testSpecialNumbers(signbit_func); \ + } + +#endif // LLVM_LIBC_TEST_INCLUDE_MATH_SIGNBIT_H diff --git a/libc/test/include/isfinite_test.c b/libc/test/include/isfinite_test.c new file mode 100644 index 000000000000..5fbf4b4ca8ef --- /dev/null +++ b/libc/test/include/isfinite_test.c @@ -0,0 +1,22 @@ +//===-- Unittests for isfinite 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 + +// check if macro is defined +#ifndef isfinite +#error "isfinite macro is not defined" +#else +int main(void) { + assert(isfinite(1.0f)); + assert(isfinite(1.0)); + assert(isfinite(1.0L)); + return 0; +} +#endif diff --git a/libc/test/include/isfinite_test.cpp b/libc/test/include/isfinite_test.cpp new file mode 100644 index 000000000000..79ac44206e63 --- /dev/null +++ b/libc/test/include/isfinite_test.cpp @@ -0,0 +1,12 @@ +//===-- Unittest for isfinite[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 "IsFiniteTest.h" +#include "include/llvm-libc-macros/math-function-macros.h" + +LIST_ISFINITE_TESTS(double, isfinite) diff --git a/libc/test/include/isfinitef_test.cpp b/libc/test/include/isfinitef_test.cpp new file mode 100644 index 000000000000..b1f66cd040e1 --- /dev/null +++ b/libc/test/include/isfinitef_test.cpp @@ -0,0 +1,12 @@ +//===-- Unittest for isfinite[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 "IsFiniteTest.h" +#include "include/llvm-libc-macros/math-function-macros.h" + +LIST_ISFINITE_TESTS(float, isfinite) diff --git a/libc/test/include/isfinitel_test.cpp b/libc/test/include/isfinitel_test.cpp new file mode 100644 index 000000000000..9087cd69ba01 --- /dev/null +++ b/libc/test/include/isfinitel_test.cpp @@ -0,0 +1,12 @@ +//===-- Unittest for isfinite[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 "IsFiniteTest.h" +#include "include/llvm-libc-macros/math-function-macros.h" + +LIST_ISFINITE_TESTS(long double, isfinite) diff --git a/libc/test/include/isinf_test.c b/libc/test/include/isinf_test.c new file mode 100644 index 000000000000..cc099cb61258 --- /dev/null +++ b/libc/test/include/isinf_test.c @@ -0,0 +1,22 @@ +//===-- Unittests for isinf 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 + +// check if macro is defined +#ifndef isinf +#error "isinf macro is not defined" +#else +int main(void) { + assert(!isinf(1.0f)); + assert(!isinf(1.0)); + assert(!isinf(1.0L)); + return 0; +} +#endif diff --git a/libc/test/include/isinf_test.cpp b/libc/test/include/isinf_test.cpp new file mode 100644 index 000000000000..ecf19d078489 --- /dev/null +++ b/libc/test/include/isinf_test.cpp @@ -0,0 +1,12 @@ +//===-- Unittest for isinf[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 "IsInfTest.h" +#include "include/llvm-libc-macros/math-function-macros.h" + +LIST_ISINF_TESTS(double, isinf) diff --git a/libc/test/include/isinff_test.cpp b/libc/test/include/isinff_test.cpp new file mode 100644 index 000000000000..a2170c766bf6 --- /dev/null +++ b/libc/test/include/isinff_test.cpp @@ -0,0 +1,12 @@ +//===-- Unittest for isinf[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 "IsInfTest.h" +#include "include/llvm-libc-macros/math-function-macros.h" + +LIST_ISINF_TESTS(float, isinf) diff --git a/libc/test/include/isinfl_test.cpp b/libc/test/include/isinfl_test.cpp new file mode 100644 index 000000000000..e4fb91d9608f --- /dev/null +++ b/libc/test/include/isinfl_test.cpp @@ -0,0 +1,12 @@ +//===-- Unittest for isinf[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 "IsInfTest.h" +#include "include/llvm-libc-macros/math-function-macros.h" + +LIST_ISINF_TESTS(long double, isinf) diff --git a/libc/test/include/isnan_test.c b/libc/test/include/isnan_test.c new file mode 100644 index 000000000000..ec0f8032356b --- /dev/null +++ b/libc/test/include/isnan_test.c @@ -0,0 +1,22 @@ +//===-- Unittests for isnan 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 + +// check if macro is defined +#ifndef isnan +#error "isnan macro is not defined" +#else +int main(void) { + assert(!isnan(1.0f)); + assert(!isnan(1.0)); + assert(!isnan(1.0L)); + return 0; +} +#endif diff --git a/libc/test/include/isnan_test.cpp b/libc/test/include/isnan_test.cpp new file mode 100644 index 000000000000..07dfab740724 --- /dev/null +++ b/libc/test/include/isnan_test.cpp @@ -0,0 +1,12 @@ +//===-- Unittest for isnan[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 "IsNanTest.h" +#include "include/llvm-libc-macros/math-function-macros.h" + +LIST_ISNAN_TESTS(double, isnan) diff --git a/libc/test/include/isnanf_test.cpp b/libc/test/include/isnanf_test.cpp new file mode 100644 index 000000000000..e78a8e45e023 --- /dev/null +++ b/libc/test/include/isnanf_test.cpp @@ -0,0 +1,12 @@ +//===-- Unittest for isnan[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 "IsNanTest.h" +#include "include/llvm-libc-macros/math-function-macros.h" + +LIST_ISNAN_TESTS(float, isnan) diff --git a/libc/test/include/isnanl_test.cpp b/libc/test/include/isnanl_test.cpp new file mode 100644 index 000000000000..84759a3ab28b --- /dev/null +++ b/libc/test/include/isnanl_test.cpp @@ -0,0 +1,12 @@ +//===-- Unittest for isnan[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 "IsNanTest.h" +#include "include/llvm-libc-macros/math-function-macros.h" + +LIST_ISNAN_TESTS(long double, isnan) diff --git a/libc/test/include/signbit_test.c b/libc/test/include/signbit_test.c new file mode 100644 index 000000000000..7e2460f3203a --- /dev/null +++ b/libc/test/include/signbit_test.c @@ -0,0 +1,25 @@ +//===-- Unittests for signbit 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 + +// check if macro is defined +#ifndef signbit +#error "signbit macro is not defined" +#else +int main(void) { + assert(!signbit(1.0f)); + assert(!signbit(1.0)); + assert(!signbit(1.0L)); + assert(signbit(-1.0f)); + assert(signbit(-1.0)); + assert(signbit(-1.0L)); + return 0; +} +#endif diff --git a/libc/test/include/signbit_test.cpp b/libc/test/include/signbit_test.cpp new file mode 100644 index 000000000000..d97ab0b1e0a8 --- /dev/null +++ b/libc/test/include/signbit_test.cpp @@ -0,0 +1,12 @@ +//===-- Unittest for signbit [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 "SignbitTest.h" +#include "include/llvm-libc-macros/math-function-macros.h" + +LIST_SIGNBIT_TESTS(double, signbit) diff --git a/libc/test/include/signbitf_test.cpp b/libc/test/include/signbitf_test.cpp new file mode 100644 index 000000000000..3a4bf933ec81 --- /dev/null +++ b/libc/test/include/signbitf_test.cpp @@ -0,0 +1,12 @@ +//===-- Unittests for signbit [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 "SignbitTest.h" +#include "include/llvm-libc-macros/math-function-macros.h" + +LIST_SIGNBIT_TESTS(float, signbit) diff --git a/libc/test/include/signbitl_test.cpp b/libc/test/include/signbitl_test.cpp new file mode 100644 index 000000000000..5859840b4562 --- /dev/null +++ b/libc/test/include/signbitl_test.cpp @@ -0,0 +1,12 @@ +//===-- Unittests for signbit[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 "SignbitTest.h" +#include "include/llvm-libc-macros/math-function-macros.h" + +LIST_SIGNBIT_TESTS(long double, signbit)