[flang] Accept polymorphic component element in storage_size
[llvm-project.git] / libc / test / src / math / FMinTest.h
blobe02a5ae939af865d41fa82e7eb4179e47627457b
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 #include "test/UnitTest/FPMatcher.h"
10 #include "test/UnitTest/Test.h"
11 #include "utils/MPFRWrapper/MPFRUtils.h"
13 #include <math.h>
15 namespace mpfr = __llvm_libc::testing::mpfr;
17 template <typename T> class FMinTest : public __llvm_libc::testing::Test {
19 DECLARE_SPECIAL_CONSTANTS(T)
21 public:
22 typedef T (*FMinFunc)(T, T);
24 void testNaN(FMinFunc func) {
25 EXPECT_FP_EQ(inf, func(aNaN, inf));
26 EXPECT_FP_EQ(neg_inf, func(neg_inf, aNaN));
27 EXPECT_FP_EQ(0.0, func(aNaN, 0.0));
28 EXPECT_FP_EQ(-0.0, func(-0.0, aNaN));
29 EXPECT_FP_EQ(T(-1.2345), func(aNaN, T(-1.2345)));
30 EXPECT_FP_EQ(T(1.2345), func(T(1.2345), aNaN));
31 EXPECT_FP_EQ(aNaN, func(aNaN, aNaN));
34 void testInfArg(FMinFunc func) {
35 EXPECT_FP_EQ(neg_inf, func(neg_inf, inf));
36 EXPECT_FP_EQ(0.0, func(inf, 0.0));
37 EXPECT_FP_EQ(-0.0, func(-0.0, inf));
38 EXPECT_FP_EQ(T(1.2345), func(inf, T(1.2345)));
39 EXPECT_FP_EQ(T(-1.2345), func(T(-1.2345), inf));
42 void testNegInfArg(FMinFunc func) {
43 EXPECT_FP_EQ(neg_inf, func(inf, neg_inf));
44 EXPECT_FP_EQ(neg_inf, func(neg_inf, 0.0));
45 EXPECT_FP_EQ(neg_inf, func(-0.0, neg_inf));
46 EXPECT_FP_EQ(neg_inf, func(neg_inf, T(-1.2345)));
47 EXPECT_FP_EQ(neg_inf, func(T(1.2345), neg_inf));
50 void testBothZero(FMinFunc func) {
51 EXPECT_FP_EQ(0.0, func(0.0, 0.0));
52 EXPECT_FP_EQ(-0.0, func(-0.0, 0.0));
53 EXPECT_FP_EQ(-0.0, func(0.0, -0.0));
54 EXPECT_FP_EQ(-0.0, func(-0.0, -0.0));
57 void testRange(FMinFunc func) {
58 constexpr UIntType COUNT = 10000001;
59 constexpr UIntType STEP = UIntType(-1) / COUNT;
60 for (UIntType i = 0, v = 0, w = UIntType(-1); i <= COUNT;
61 ++i, v += STEP, w -= STEP) {
62 T x = T(FPBits(v)), y = T(FPBits(w));
63 if (isnan(x) || isinf(x))
64 continue;
65 if (isnan(y) || isinf(y))
66 continue;
67 if ((x == 0) && (y == 0))
68 continue;
70 if (x > y) {
71 EXPECT_FP_EQ(y, func(x, y));
72 } else {
73 EXPECT_FP_EQ(x, func(x, y));
79 #define LIST_FMIN_TESTS(T, func) \
80 using LlvmLibcFMinTest = FMinTest<T>; \
81 TEST_F(LlvmLibcFMinTest, NaN) { testNaN(&func); } \
82 TEST_F(LlvmLibcFMinTest, InfArg) { testInfArg(&func); } \
83 TEST_F(LlvmLibcFMinTest, NegInfArg) { testNegInfArg(&func); } \
84 TEST_F(LlvmLibcFMinTest, BothZero) { testBothZero(&func); } \
85 TEST_F(LlvmLibcFMinTest, Range) { testRange(&func); }