xref: /aosp_15_r20/external/llvm-libc/test/include/IsSubnormalTest.h (revision 71db0c75aadcf003ffe3238005f61d7618a3fead)
1 //===-- Utility class to test the issubnormal macro  ------------*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 #ifndef LLVM_LIBC_TEST_INCLUDE_MATH_ISSUBNORMAL_H
10 #define LLVM_LIBC_TEST_INCLUDE_MATH_ISSUBNORMAL_H
11 
12 #include "test/UnitTest/FPMatcher.h"
13 #include "test/UnitTest/Test.h"
14 
15 #include "include/llvm-libc-macros/math-function-macros.h"
16 
17 template <typename T>
18 class IsSubnormalTest : public LIBC_NAMESPACE::testing::Test {
19   DECLARE_SPECIAL_CONSTANTS(T)
20 
21 public:
22   typedef bool (*IsSubnormalFunc)(T);
23 
testSpecialNumbers(IsSubnormalFunc func)24   void testSpecialNumbers(IsSubnormalFunc func) {
25     EXPECT_FALSE(func(aNaN));
26     EXPECT_FALSE(func(neg_aNaN));
27     EXPECT_FALSE(func(sNaN));
28     EXPECT_FALSE(func(neg_sNaN));
29     EXPECT_FALSE(func(inf));
30     EXPECT_FALSE(func(neg_inf));
31     EXPECT_FALSE(func(min_normal));
32     EXPECT_FALSE(func(max_normal));
33     EXPECT_FALSE(func(neg_max_normal));
34     EXPECT_TRUE(func(min_denormal));
35     EXPECT_TRUE(func(neg_min_denormal));
36     EXPECT_TRUE(func(max_denormal));
37     EXPECT_FALSE(func(zero));
38     EXPECT_FALSE(func(neg_zero));
39   }
40 };
41 
42 #define LIST_ISSUBNORMAL_TESTS(T, func)                                        \
43   using LlvmLibcIsSubnormalTest = IsSubnormalTest<T>;                          \
44   TEST_F(LlvmLibcIsSubnormalTest, SpecialNumbers) {                            \
45     auto issubnormal_func = [](T x) { return func(x); };                       \
46     testSpecialNumbers(issubnormal_func);                                      \
47   }
48 
49 #endif // LLVM_LIBC_TEST_INCLUDE_MATH_ISSUBNORMAL_H
50