[AMDGPU] Replace unsigned with Register in SIMachineScheduler. NFC
[llvm-project.git] / libc / test / src / math / FMinTest.h
blob51c21ae56a7742dfe3ff975153beed34c94f0dc2
1 //===-- Utility class to test fmin[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_FMINTEST_H
10 #define LLVM_LIBC_TEST_SRC_MATH_FMINTEST_H
12 #include "src/__support/FPUtil/FPBits.h"
13 #include "test/UnitTest/FEnvSafeTest.h"
14 #include "test/UnitTest/FPMatcher.h"
15 #include "test/UnitTest/Test.h"
16 #include "utils/MPFRWrapper/MPFRUtils.h"
18 #include "hdr/math_macros.h"
20 namespace mpfr = LIBC_NAMESPACE::testing::mpfr;
22 template <typename T>
23 class FMinTest : public LIBC_NAMESPACE::testing::FEnvSafeTest {
25 DECLARE_SPECIAL_CONSTANTS(T)
27 public:
28 typedef T (*FMinFunc)(T, T);
30 void testNaN(FMinFunc func) {
31 EXPECT_FP_EQ(inf, func(aNaN, inf));
32 EXPECT_FP_EQ(neg_inf, func(neg_inf, aNaN));
33 EXPECT_FP_EQ(0.0, func(aNaN, 0.0));
34 EXPECT_FP_EQ(-0.0, func(-0.0, aNaN));
35 EXPECT_FP_EQ(T(-1.2345), func(aNaN, T(-1.2345)));
36 EXPECT_FP_EQ(T(1.2345), func(T(1.2345), aNaN));
37 EXPECT_FP_EQ(aNaN, func(aNaN, aNaN));
40 void testInfArg(FMinFunc func) {
41 EXPECT_FP_EQ(neg_inf, func(neg_inf, inf));
42 EXPECT_FP_EQ(0.0, func(inf, 0.0));
43 EXPECT_FP_EQ(-0.0, func(-0.0, inf));
44 EXPECT_FP_EQ(T(1.2345), func(inf, T(1.2345)));
45 EXPECT_FP_EQ(T(-1.2345), func(T(-1.2345), inf));
48 void testNegInfArg(FMinFunc func) {
49 EXPECT_FP_EQ(neg_inf, func(inf, neg_inf));
50 EXPECT_FP_EQ(neg_inf, func(neg_inf, 0.0));
51 EXPECT_FP_EQ(neg_inf, func(-0.0, neg_inf));
52 EXPECT_FP_EQ(neg_inf, func(neg_inf, T(-1.2345)));
53 EXPECT_FP_EQ(neg_inf, func(T(1.2345), neg_inf));
56 void testBothZero(FMinFunc func) {
57 EXPECT_FP_EQ(0.0, func(0.0, 0.0));
58 EXPECT_FP_EQ(-0.0, func(-0.0, 0.0));
59 EXPECT_FP_EQ(-0.0, func(0.0, -0.0));
60 EXPECT_FP_EQ(-0.0, func(-0.0, -0.0));
63 void testRange(FMinFunc func) {
64 constexpr StorageType COUNT = 100'001;
65 constexpr StorageType STEP = STORAGE_MAX / COUNT;
66 for (StorageType i = 0, v = 0, w = STORAGE_MAX; i <= COUNT;
67 ++i, v += STEP, w -= STEP) {
68 T x = FPBits(v).get_val(), y = FPBits(w).get_val();
69 if (FPBits(v).is_nan() || FPBits(v).is_inf())
70 continue;
71 if (FPBits(w).is_nan() || FPBits(w).is_inf())
72 continue;
73 if ((x == 0) && (y == 0))
74 continue;
76 if (x > y) {
77 EXPECT_FP_EQ(y, func(x, y));
78 } else {
79 EXPECT_FP_EQ(x, func(x, y));
85 #define LIST_FMIN_TESTS(T, func) \
86 using LlvmLibcFMinTest = FMinTest<T>; \
87 TEST_F(LlvmLibcFMinTest, NaN) { testNaN(&func); } \
88 TEST_F(LlvmLibcFMinTest, InfArg) { testInfArg(&func); } \
89 TEST_F(LlvmLibcFMinTest, NegInfArg) { testNegInfArg(&func); } \
90 TEST_F(LlvmLibcFMinTest, BothZero) { testBothZero(&func); } \
91 TEST_F(LlvmLibcFMinTest, Range) { testRange(&func); }
93 #endif // LLVM_LIBC_TEST_SRC_MATH_FMINTEST_H