[OptTable] Fix typo VALUE => VALUES (NFCI) (#121523)
[llvm-project.git] / libc / test / src / math / FAbsTest.h
blob7b4ea93e4db9940046b0d4f0e18cf25f9f81cac7
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 //===----------------------------------------------------------------------===//
9 #ifndef LLVM_LIBC_TEST_SRC_MATH_FABSTEST_H
10 #define LLVM_LIBC_TEST_SRC_MATH_FABSTEST_H
12 #include "test/UnitTest/FEnvSafeTest.h"
13 #include "test/UnitTest/FPMatcher.h"
14 #include "test/UnitTest/Test.h"
15 #include "utils/MPFRWrapper/MPFRUtils.h"
17 #include "hdr/math_macros.h"
19 namespace mpfr = LIBC_NAMESPACE::testing::mpfr;
21 template <typename T>
22 class FAbsTest : public LIBC_NAMESPACE::testing::FEnvSafeTest {
24 DECLARE_SPECIAL_CONSTANTS(T)
26 public:
27 typedef T (*FabsFunc)(T);
29 void testSpecialNumbers(FabsFunc func) {
30 EXPECT_FP_EQ(aNaN, func(aNaN));
32 EXPECT_FP_EQ(inf, func(inf));
33 EXPECT_FP_EQ(inf, func(neg_inf));
35 EXPECT_FP_EQ(zero, func(zero));
36 EXPECT_FP_EQ(zero, func(neg_zero));
39 void testRange(FabsFunc func) {
40 constexpr StorageType COUNT = 100'000;
41 constexpr StorageType STEP = STORAGE_MAX / COUNT;
42 for (StorageType i = 0, v = 0; i <= COUNT; ++i, v += STEP) {
43 T x = FPBits(v).get_val();
44 if (FPBits(v).is_nan() || FPBits(v).is_inf())
45 continue;
46 ASSERT_MPFR_MATCH(mpfr::Operation::Abs, x, func(x), 0.0);
51 #define LIST_FABS_TESTS(T, func) \
52 using LlvmLibcFAbsTest = FAbsTest<T>; \
53 TEST_F(LlvmLibcFAbsTest, SpecialNumbers) { testSpecialNumbers(&func); } \
54 TEST_F(LlvmLibcFAbsTest, Range) { testRange(&func); }
56 #endif // LLVM_LIBC_TEST_SRC_MATH_FABSTEST_H