60 changes: 60 additions & 0 deletions libc/test/src/math/smoke/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1597,6 +1597,66 @@ add_fp_unittest(
libc.src.__support.FPUtil.manipulation_functions
)

add_fp_unittest(
issignaling_test
SUITE
libc-math-smoke-tests
SRCS
issignaling_test.cpp
HDRS
IsSignalingTest.h
DEPENDS
libc.src.math.issignaling
)

add_fp_unittest(
issignalingf_test
SUITE
libc-math-smoke-tests
SRCS
issignalingf_test.cpp
HDRS
IsSignalingTest.h
DEPENDS
libc.src.math.issignalingf
)

add_fp_unittest(
issignalingl_test
SUITE
libc-math-smoke-tests
SRCS
issignalingl_test.cpp
HDRS
IsSignalingTest.h
DEPENDS
libc.src.math.issignalingl
)

add_fp_unittest(
issignalingf16_test
SUITE
libc-math-smoke-tests
SRCS
issignalingf16_test.cpp
HDRS
IsSignalingTest.h
DEPENDS
libc.src.math.issignalingf16
)

add_fp_unittest(
issignalingf128_test
SUITE
libc-math-smoke-tests
SRCS
issignalingf128_test.cpp
HDRS
IsSignalingTest.h
DEPENDS
libc.src.math.issignalingf128
)

add_fp_unittest(
llogb_test
SUITE
Expand Down
60 changes: 60 additions & 0 deletions libc/test/src/math/smoke/IsSignalingTest.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
//===-- Utility class to test different flavors of issignaling --*- 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_ISSIGNALINGTEST_H
#define LLVM_LIBC_TEST_SRC_MATH_SMOKE_ISSIGNALINGTEST_H

#include "test/UnitTest/FEnvSafeTest.h"
#include "test/UnitTest/FPMatcher.h"
#include "test/UnitTest/Test.h"

#include "hdr/math_macros.h"

template <typename T>
class IsSignalingTest : public LIBC_NAMESPACE::testing::FEnvSafeTest {

DECLARE_SPECIAL_CONSTANTS(T)

public:
typedef int (*IsSignalingFunc)(T);

void testSpecialNumbers(IsSignalingFunc func) {
EXPECT_EQ(func(aNaN), 0);
EXPECT_EQ(func(neg_aNaN), 0);
EXPECT_EQ(func(sNaN), 1);
EXPECT_EQ(func(neg_sNaN), 1);
EXPECT_EQ(func(inf), 0);
EXPECT_EQ(func(neg_inf), 0);
EXPECT_EQ(func(min_normal), 0);
EXPECT_EQ(func(max_normal), 0);
EXPECT_EQ(func(neg_max_normal), 0);
EXPECT_EQ(func(min_denormal), 0);
EXPECT_EQ(func(neg_min_denormal), 0);
EXPECT_EQ(func(max_denormal), 0);
EXPECT_EQ(func(zero), 0);
EXPECT_EQ(func(neg_zero), 0);
}

void testRoundedNumbers(IsSignalingFunc func) {
EXPECT_EQ(func(T(1.0)), 0);
EXPECT_EQ(func(T(-1.0)), 0);
EXPECT_EQ(func(T(10.0)), 0);
EXPECT_EQ(func(T(-10.0)), 0);
EXPECT_EQ(func(T(1234.0)), 0);
EXPECT_EQ(func(T(-1234.0)), 0);
}
};

#define LIST_ISSIGNALING_TESTS(T, func) \
using LlvmLibcIsSignalingTest = IsSignalingTest<T>; \
TEST_F(LlvmLibcIsSignalingTest, SpecialNumbers) { \
testSpecialNumbers(&func); \
} \
TEST_F(LlvmLibcIsSignalingTest, RoundedNubmers) { testRoundedNumbers(&func); }

#endif // LLVM_LIBC_TEST_SRC_MATH_SMOKE_ISSIGNALINGTEST_H
13 changes: 13 additions & 0 deletions libc/test/src/math/smoke/issignaling_test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//===-- Unittests for issignaling -----------------------------------------===//
//
// 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
//
//===----------------------------------------------------------------------===//

#include "IsSignalingTest.h"

#include "src/math/issignaling.h"

LIST_ISSIGNALING_TESTS(double, LIBC_NAMESPACE::issignaling)
13 changes: 13 additions & 0 deletions libc/test/src/math/smoke/issignalingf128_test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//===-- Unittests for issignalingf128 -------------------------------------===//
//
// 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
//
//===----------------------------------------------------------------------===//

#include "IsSignalingTest.h"

#include "src/math/issignalingf128.h"

LIST_ISSIGNALING_TESTS(float128, LIBC_NAMESPACE::issignalingf128)
13 changes: 13 additions & 0 deletions libc/test/src/math/smoke/issignalingf16_test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//===-- Unittests for issignalingf16 --------------------------------------===//
//
// 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
//
//===----------------------------------------------------------------------===//

#include "IsSignalingTest.h"

#include "src/math/issignalingf16.h"

LIST_ISSIGNALING_TESTS(float16, LIBC_NAMESPACE::issignalingf16)
13 changes: 13 additions & 0 deletions libc/test/src/math/smoke/issignalingf_test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//===-- Unittests for issignalingf ----------------------------------------===//
//
// 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
//
//===----------------------------------------------------------------------===//

#include "IsSignalingTest.h"

#include "src/math/issignalingf.h"

LIST_ISSIGNALING_TESTS(float, LIBC_NAMESPACE::issignalingf)
13 changes: 13 additions & 0 deletions libc/test/src/math/smoke/issignalingl_test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//===-- Unittests for issignalingl ----------------------------------------===//
//
// 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
//
//===----------------------------------------------------------------------===//

#include "IsSignalingTest.h"

#include "src/math/issignalingl.h"

LIST_ISSIGNALING_TESTS(long double, LIBC_NAMESPACE::issignalingl)