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 Inf
= __builtin_inf();
7 constexpr double NegInf
= -__builtin_inf();
9 #define FMIN_TEST_SIMPLE(T, FUNC) \
10 static_assert(T(1.2345) == FUNC(T(1.2345), T(6.7890))); \
11 static_assert(T(1.2345) == FUNC(T(6.7890), T(1.2345)));
13 #define FMIN_TEST_NAN(T, FUNC) \
14 static_assert(Inf == FUNC(NaN, Inf)); \
15 static_assert(NegInf == FUNC(NegInf, NaN)); \
16 static_assert(0.0 == FUNC(NaN, 0.0)); \
17 static_assert(-0.0 == FUNC(-0.0, NaN)); \
18 static_assert(T(-1.2345) == FUNC(NaN, T(-1.2345))); \
19 static_assert(T(1.2345) == FUNC(T(1.2345), NaN)); \
20 static_assert(__builtin_isnan(FUNC(NaN, NaN)));
22 #define FMIN_TEST_INF(T, FUNC) \
23 static_assert(NegInf == FUNC(NegInf, Inf)); \
24 static_assert(0.0 == FUNC(Inf, 0.0)); \
25 static_assert(-0.0 == FUNC(-0.0, Inf)); \
26 static_assert(T(1.2345) == FUNC(Inf, T(1.2345))); \
27 static_assert(T(-1.2345) == FUNC(T(-1.2345), Inf));
29 #define FMIN_TEST_NEG_INF(T, FUNC) \
30 static_assert(NegInf == FUNC(Inf, NegInf)); \
31 static_assert(NegInf == FUNC(NegInf, 0.0)); \
32 static_assert(NegInf == FUNC(-0.0, NegInf)); \
33 static_assert(NegInf == FUNC(NegInf, T(-1.2345))); \
34 static_assert(NegInf == FUNC(T(1.2345), NegInf));
36 #define FMIN_TEST_BOTH_ZERO(T, FUNC) \
37 static_assert(__builtin_copysign(1.0, FUNC(0.0, 0.0)) == 1.0); \
38 static_assert(__builtin_copysign(1.0, FUNC(-0.0, 0.0)) == -1.0); \
39 static_assert(__builtin_copysign(1.0, FUNC(0.0, -0.0)) == -1.0); \
40 static_assert(__builtin_copysign(1.0, FUNC(-0.0, -0.0)) == -1.0);
42 #define LIST_FMIN_TESTS(T, FUNC) \
43 FMIN_TEST_SIMPLE(T, FUNC) \
44 FMIN_TEST_NAN(T, FUNC) \
45 FMIN_TEST_INF(T, FUNC) \
46 FMIN_TEST_NEG_INF(T, FUNC) \
47 FMIN_TEST_BOTH_ZERO(T, FUNC)
49 LIST_FMIN_TESTS(double, __builtin_fmin
)
50 LIST_FMIN_TESTS(float, __builtin_fminf
)
51 LIST_FMIN_TESTS((long double), __builtin_fminl
)
52 LIST_FMIN_TESTS(__fp16
, __builtin_fminf16
)
54 LIST_FMIN_TESTS(__float128
, __builtin_fminf128
)