1 // RUN: %clang_cc1 -std=c++17 -fsyntax-only -verify %s
2 // RUN: %clang_cc1 -std=c++17 -fsyntax-only -verify -fexperimental-new-constant-interpreter %s
3 // expected-no-diagnostics
5 constexpr double NaN
= __builtin_nan("");
6 constexpr double SNaN
= __builtin_nans("");
7 constexpr double Inf
= __builtin_inf();
8 constexpr double NegInf
= -__builtin_inf();
10 #define FMAXIMUMNUM_TEST_SIMPLE(T, FUNC) \
11 static_assert(T(6.7890) == FUNC(T(1.2345), T(6.7890))); \
12 static_assert(T(6.7890) == FUNC(T(6.7890), T(1.2345)));
14 #define FMAXIMUMNUM_TEST_SNAN(T, FUNC) \
15 static_assert(Inf == FUNC(SNaN, Inf)); \
16 static_assert(NegInf == FUNC(NegInf, SNaN)); \
17 static_assert(0.0 == FUNC(SNaN, 0.0)); \
18 static_assert(-0.0 == FUNC(-0.0, SNaN)); \
19 static_assert(T(-1.2345) == FUNC(SNaN, T(-1.2345))); \
20 static_assert(T(1.2345) == FUNC(T(1.2345), SNaN)); \
21 static_assert(__builtin_isnan(FUNC(SNaN, SNaN))); \
22 static_assert(__builtin_isnan(FUNC(NaN, SNaN))); \
23 static_assert(!__builtin_issignaling(FUNC(SNaN, SNaN))); \
24 static_assert(!__builtin_issignaling(FUNC(NaN, SNaN)));
26 #define FMAXIMUMNUM_TEST_NAN(T, FUNC) \
27 static_assert(Inf == FUNC(NaN, Inf)); \
28 static_assert(NegInf == FUNC(NegInf, NaN)); \
29 static_assert(0.0 == FUNC(NaN, 0.0)); \
30 static_assert(-0.0 == FUNC(-0.0, NaN)); \
31 static_assert(T(-1.2345) == FUNC(NaN, T(-1.2345))); \
32 static_assert(T(1.2345) == FUNC(T(1.2345), NaN)); \
33 static_assert(__builtin_isnan(FUNC(NaN, NaN)));
35 #define FMAXIMUMNUM_TEST_INF(T, FUNC) \
36 static_assert(Inf == FUNC(NegInf, Inf)); \
37 static_assert(Inf == FUNC(Inf, 0.0)); \
38 static_assert(Inf == FUNC(-0.0, Inf)); \
39 static_assert(Inf == FUNC(Inf, T(1.2345))); \
40 static_assert(Inf == FUNC(T(-1.2345), Inf));
42 #define FMAXIMUMNUM_TEST_NEG_INF(T, FUNC) \
43 static_assert(Inf == FUNC(Inf, NegInf)); \
44 static_assert(0.0 == FUNC(NegInf, 0.0)); \
45 static_assert(-0.0 == FUNC(-0.0, NegInf)); \
46 static_assert(T(-1.2345) == FUNC(NegInf, T(-1.2345))); \
47 static_assert(T(1.2345) == FUNC(T(1.2345), NegInf));
49 #define FMAXIMUMNUM_TEST_BOTH_ZERO(T, FUNC) \
50 static_assert(__builtin_copysign(1.0, FUNC(0.0, 0.0)) == 1.0); \
51 static_assert(__builtin_copysign(1.0, FUNC(-0.0, 0.0)) == 1.0); \
52 static_assert(__builtin_copysign(1.0, FUNC(0.0, -0.0)) == 1.0); \
53 static_assert(__builtin_copysign(1.0, FUNC(-0.0, -0.0)) == -1.0);
55 #define LIST_FMAXIMUMNUM_TESTS(T, FUNC) \
56 FMAXIMUMNUM_TEST_SIMPLE(T, FUNC) \
57 FMAXIMUMNUM_TEST_NAN(T, FUNC) \
58 FMAXIMUMNUM_TEST_SNAN(T, FUNC) \
59 FMAXIMUMNUM_TEST_INF(T, FUNC) \
60 FMAXIMUMNUM_TEST_NEG_INF(T, FUNC) \
61 FMAXIMUMNUM_TEST_BOTH_ZERO(T, FUNC)
63 LIST_FMAXIMUMNUM_TESTS(double, __builtin_fmaximum_num
)
64 LIST_FMAXIMUMNUM_TESTS(float, __builtin_fmaximum_numf
)
65 LIST_FMAXIMUMNUM_TESTS((long double), __builtin_fmaximum_numl
)
66 LIST_FMAXIMUMNUM_TESTS(__fp16
, __builtin_fmaximum_numf16
)
68 LIST_FMAXIMUMNUM_TESTS(__float128
, __builtin_fmaximum_numf128
)