1 //===----------------------------------------------------------------------===//
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
7 //===----------------------------------------------------------------------===//
9 // bool signbit(floating-point-type x); // constexpr since C++23
11 // We don't control the implementation on windows
12 // UNSUPPORTED: windows
14 // These compilers don't support constexpr `__builtin_signbit` yet.
15 // UNSUPPORTED: clang-17, clang-18, clang-19, apple-clang-15, apple-clang-16
21 #include "test_macros.h"
22 #include "type_algorithms.h"
26 static TEST_CONSTEXPR_CXX23
bool test() {
27 assert(!std::signbit(T(0)));
28 assert(!std::signbit(std::numeric_limits
<T
>::min()));
29 assert(!std::signbit(std::numeric_limits
<T
>::denorm_min()));
30 assert(!std::signbit(std::numeric_limits
<T
>::max()));
31 assert(!std::signbit(std::numeric_limits
<T
>::infinity()));
32 assert(!std::signbit(std::numeric_limits
<T
>::quiet_NaN()));
33 assert(!std::signbit(std::numeric_limits
<T
>::signaling_NaN()));
34 assert(std::signbit(-T(0)));
35 assert(std::signbit(-std::numeric_limits
<T
>::infinity()));
36 assert(std::signbit(std::numeric_limits
<T
>::lowest()));
42 TEST_CONSTEXPR_CXX23
void operator()() {
44 #if TEST_STD_VER >= 23
45 static_assert(test
<T
>());
52 static TEST_CONSTEXPR_CXX23
bool test() {
53 assert(!std::signbit(std::numeric_limits
<T
>::max()));
54 assert(!std::signbit(T(0)));
55 if (std::is_unsigned
<T
>::value
) {
56 assert(!std::signbit(std::numeric_limits
<T
>::lowest()));
58 assert(std::signbit(std::numeric_limits
<T
>::lowest()));
65 TEST_CONSTEXPR_CXX23
void operator()() {
67 #if TEST_STD_VER >= 23
68 static_assert(test
<T
>());
74 struct ConvertibleTo
{
75 operator T() const { return T(); }
78 int main(int, char**) {
79 types::for_each(types::floating_point_types(), TestFloat());
80 types::for_each(types::integral_types(), TestInt());
82 // Make sure we can call `std::signbit` with convertible types. This checks
83 // whether overloads for all cv-unqualified floating-point types are working
86 assert(!std::signbit(ConvertibleTo
<float>()));
87 assert(!std::signbit(ConvertibleTo
<double>()));
88 assert(!std::signbit(ConvertibleTo
<long double>()));