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 isfinite(floating-point-type x); // constexpr since C++23
11 // We don't control the implementation on windows
12 // UNSUPPORTED: windows
18 #include "test_macros.h"
19 #include "type_algorithms.h"
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()));
38 TEST_CONSTEXPR_CXX23
void operator()() {
40 #if TEST_STD_VER >= 23
41 static_assert(test
<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)));
57 TEST_CONSTEXPR_CXX23
void operator()() {
59 #if TEST_STD_VER >= 23
60 static_assert(test
<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>()));