xref: /aosp_15_r20/external/cronet/third_party/libc++/src/test/std/numerics/c.math/isfinite.pass.cpp (revision 6777b5387eb2ff775bb5750e3f5d96f37fb7352b)
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 //===----------------------------------------------------------------------===//
8 
9 // bool isfinite(floating-point-type x); // constexpr since C++23
10 
11 // We don't control the implementation on windows
12 // UNSUPPORTED: windows
13 
14 #include <cassert>
15 #include <cmath>
16 #include <limits>
17 
18 #include "test_macros.h"
19 #include "type_algorithms.h"
20 
21 struct TestFloat {
22   template <class T>
testTestFloat23   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()));
33 
34     return true;
35   }
36 
37   template <class T>
operator ()TestFloat38   TEST_CONSTEXPR_CXX23 void operator()() {
39     test<T>();
40 #if TEST_STD_VER >= 23
41     static_assert(test<T>());
42 #endif
43   }
44 };
45 
46 struct TestInt {
47   template <class T>
testTestInt48   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)));
52 
53     return true;
54   }
55 
56   template <class T>
operator ()TestInt57   TEST_CONSTEXPR_CXX23 void operator()() {
58     test<T>();
59 #if TEST_STD_VER >= 23
60     static_assert(test<T>());
61 #endif
62   }
63 };
64 
main(int,char **)65 int main(int, char**) {
66   types::for_each(types::floating_point_types(), TestFloat());
67   types::for_each(types::integral_types(), TestInt());
68 
69   return 0;
70 }
71