1 | //===-- Utility class to test fabs[f|l] -------------------------*- 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_SRC_MATH_SMOKE_FABSTEST_H |
10 | #define LLVM_LIBC_TEST_SRC_MATH_SMOKE_FABSTEST_H |
11 | |
12 | #include "test/UnitTest/FEnvSafeTest.h" |
13 | #include "test/UnitTest/FPMatcher.h" |
14 | #include "test/UnitTest/Test.h" |
15 | |
16 | #include "hdr/math_macros.h" |
17 | |
18 | template <typename T> |
19 | class FAbsTest : public LIBC_NAMESPACE::testing::FEnvSafeTest { |
20 | |
21 | DECLARE_SPECIAL_CONSTANTS(T) |
22 | |
23 | public: |
24 | typedef T (*FabsFunc)(T); |
25 | |
26 | void testSpecialNumbers(FabsFunc func) { |
27 | EXPECT_FP_EQ_ALL_ROUNDING(aNaN, func(aNaN)); |
28 | |
29 | EXPECT_FP_EQ_ALL_ROUNDING(inf, func(inf)); |
30 | EXPECT_FP_EQ_ALL_ROUNDING(inf, func(neg_inf)); |
31 | |
32 | EXPECT_FP_EQ_ALL_ROUNDING(zero, func(zero)); |
33 | EXPECT_FP_EQ_ALL_ROUNDING(zero, func(neg_zero)); |
34 | |
35 | EXPECT_FP_EQ_ALL_ROUNDING(T(1), func(T(1))); |
36 | EXPECT_FP_EQ_ALL_ROUNDING(T(1), func(T(-1))); |
37 | } |
38 | }; |
39 | |
40 | #define LIST_FABS_TESTS(T, func) \ |
41 | using LlvmLibcFAbsTest = FAbsTest<T>; \ |
42 | TEST_F(LlvmLibcFAbsTest, SpecialNumbers) { testSpecialNumbers(&func); } |
43 | |
44 | #endif // LLVM_LIBC_TEST_SRC_MATH_SMOKE_FABSTEST_H |
45 | |