Revert "[libc] Use best-fit binary trie to make malloc logarithmic" (#117065)
[llvm-project.git] / libcxx / test / std / numerics / c.math / isfinite.pass.cpp
blob3d5be616343343e86278e3ba776ac4234ca350e2
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 isfinite(floating-point-type x); // constexpr since C++23
11 // We don't control the implementation on windows
12 // UNSUPPORTED: windows
14 #include <cassert>
15 #include <cmath>
16 #include <limits>
18 #include "test_macros.h"
19 #include "type_algorithms.h"
21 struct TestFloat {
22 template <class T>
23 static TEST_CONSTEXPR_CXX23 bool test() {
24 assert(std::isfinite(std::numeric_limits<T>::max()));
25 assert(!std::isfinite(std::numeric_limits<T>::infinity()));
26 assert(std::isfinite(std::numeric_limits<T>::min()));
27 assert(std::isfinite(std::numeric_limits<T>::denorm_min()));
28 assert(std::isfinite(std::numeric_limits<T>::lowest()));
29 assert(!std::isfinite(-std::numeric_limits<T>::infinity()));
30 assert(std::isfinite(T(0)));
31 assert(!std::isfinite(std::numeric_limits<T>::quiet_NaN()));
32 assert(!std::isfinite(std::numeric_limits<T>::signaling_NaN()));
34 return true;
37 template <class T>
38 TEST_CONSTEXPR_CXX23 void operator()() {
39 test<T>();
40 #if TEST_STD_VER >= 23
41 static_assert(test<T>());
42 #endif
46 struct TestInt {
47 template <class T>
48 static TEST_CONSTEXPR_CXX23 bool test() {
49 assert(std::isfinite(std::numeric_limits<T>::max()));
50 assert(std::isfinite(std::numeric_limits<T>::lowest()));
51 assert(std::isfinite(T(0)));
53 return true;
56 template <class T>
57 TEST_CONSTEXPR_CXX23 void operator()() {
58 test<T>();
59 #if TEST_STD_VER >= 23
60 static_assert(test<T>());
61 #endif
65 template <typename T>
66 struct ConvertibleTo {
67 operator T() const { return T(); }
70 int main(int, char**) {
71 types::for_each(types::floating_point_types(), TestFloat());
72 types::for_each(types::integral_types(), TestInt());
74 // Make sure we can call `std::isfinite` with convertible types
76 assert(std::isfinite(ConvertibleTo<float>()));
77 assert(std::isfinite(ConvertibleTo<double>()));
78 assert(std::isfinite(ConvertibleTo<long double>()));
81 return 0;