1 //===-- Utility class to test the fpclassify macro -------------*- C++ -*-===//
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
7 //===----------------------------------------------------------------------===//
9 #ifndef LLVM_LIBC_TEST_INCLUDE_MATH_FPCLASSIFY_H
10 #define LLVM_LIBC_TEST_INCLUDE_MATH_FPCLASSIFY_H
12 #include "test/UnitTest/FPMatcher.h"
13 #include "test/UnitTest/Test.h"
15 #include "include/llvm-libc-macros/math-function-macros.h"
18 class FpClassifyTest
: public LIBC_NAMESPACE::testing::Test
{
19 DECLARE_SPECIAL_CONSTANTS(T
)
22 typedef int (*FpClassifyFunc
)(T
);
24 void testSpecialNumbers(FpClassifyFunc func
) {
25 EXPECT_EQ(func(aNaN
), FP_NAN
);
26 EXPECT_EQ(func(neg_aNaN
), FP_NAN
);
27 EXPECT_EQ(func(sNaN
), FP_NAN
);
28 EXPECT_EQ(func(neg_sNaN
), FP_NAN
);
29 EXPECT_EQ(func(inf
), FP_INFINITE
);
30 EXPECT_EQ(func(neg_inf
), FP_INFINITE
);
31 EXPECT_EQ(func(min_normal
), FP_NORMAL
);
32 EXPECT_EQ(func(max_normal
), FP_NORMAL
);
33 EXPECT_EQ(func(neg_max_normal
), FP_NORMAL
);
34 EXPECT_EQ(func(min_denormal
), FP_SUBNORMAL
);
35 EXPECT_EQ(func(neg_min_denormal
), FP_SUBNORMAL
);
36 EXPECT_EQ(func(max_denormal
), FP_SUBNORMAL
);
37 EXPECT_EQ(func(zero
), FP_ZERO
);
38 EXPECT_EQ(func(neg_zero
), FP_ZERO
);
42 #define LIST_FPCLASSIFY_TESTS(T, func) \
43 using LlvmLibcFpClassifyTest = FpClassifyTest<T>; \
44 TEST_F(LlvmLibcFpClassifyTest, SpecialNumbers) { \
45 auto fpclassify_func = [](T x) { return func(x); }; \
46 testSpecialNumbers(fpclassify_func); \
49 #endif // LLVM_LIBC_TEST_INCLUDE_MATH_FPCLASSIFY_H