Revert "[libc] Use best-fit binary trie to make malloc logarithmic" (#117065)
[llvm-project.git] / libcxx / test / std / numerics / c.math / signbit.pass.cpp
bloba8a566f7de64346ea71b50c20f2bd12db2c9af0a
1 //===----------------------------------------------------------------------===//
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 // 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
17 #include <cassert>
18 #include <cmath>
19 #include <limits>
21 #include "test_macros.h"
22 #include "type_algorithms.h"
24 struct TestFloat {
25 template <class T>
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()));
38 return true;
41 template <class T>
42 TEST_CONSTEXPR_CXX23 void operator()() {
43 test<T>();
44 #if TEST_STD_VER >= 23
45 static_assert(test<T>());
46 #endif
50 struct TestInt {
51 template <class 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()));
57 } else {
58 assert(std::signbit(std::numeric_limits<T>::lowest()));
61 return true;
64 template <class T>
65 TEST_CONSTEXPR_CXX23 void operator()() {
66 test<T>();
67 #if TEST_STD_VER >= 23
68 static_assert(test<T>());
69 #endif
73 template <typename 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
84 // as expected.
86 assert(!std::signbit(ConvertibleTo<float>()));
87 assert(!std::signbit(ConvertibleTo<double>()));
88 assert(!std::signbit(ConvertibleTo<long double>()));
90 return 0;