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 4 5 constexpr double NaN = __builtin_nan(""); 6 constexpr double Inf = __builtin_inf(); 7 constexpr double NegInf = -__builtin_inf(); 8 9 #define FMAX_TEST_SIMPLE(T, FUNC) \ 10 static_assert(T(6.7890) == FUNC(T(1.2345), T(6.7890))); \ 11 static_assert(T(6.7890) == FUNC(T(6.7890), T(1.2345))); 12 13 #define FMAX_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))); 21 22 #define FMAX_TEST_INF(T, FUNC) \ 23 static_assert(Inf == FUNC(NegInf, Inf)); \ 24 static_assert(Inf == FUNC(Inf, 0.0)); \ 25 static_assert(Inf == FUNC(-0.0, Inf)); \ 26 static_assert(Inf == FUNC(Inf, T(1.2345))); \ 27 static_assert(Inf == FUNC(T(-1.2345), Inf)); 28 29 #define FMAX_TEST_NEG_INF(T, FUNC) \ 30 static_assert(Inf == FUNC(Inf, NegInf)); \ 31 static_assert(0.0 == FUNC(NegInf, 0.0)); \ 32 static_assert(-0.0 == FUNC(-0.0, NegInf)); \ 33 static_assert(T(-1.2345) == FUNC(NegInf, T(-1.2345))); \ 34 static_assert(T(1.2345) == FUNC(T(1.2345), NegInf)); 35 36 #define FMAX_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); 41 42 #define LIST_FMAX_TESTS(T, FUNC) \ 43 FMAX_TEST_SIMPLE(T, FUNC) \ 44 FMAX_TEST_NAN(T, FUNC) \ 45 FMAX_TEST_INF(T, FUNC) \ 46 FMAX_TEST_NEG_INF(T, FUNC) \ 47 FMAX_TEST_BOTH_ZERO(T, FUNC) 48 49 LIST_FMAX_TESTS(double, __builtin_fmax) 50 LIST_FMAX_TESTS(float, __builtin_fmaxf) 51 LIST_FMAX_TESTS((long double), __builtin_fmaxl) 52 LIST_FMAX_TESTS(__fp16, __builtin_fmaxf16) 53 #ifdef __FLOAT128__ 54 LIST_FMAX_TESTS(__float128, __builtin_fmaxf128) 55 #endif 56