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 // test numeric_limits
10 
11 // max()
12 
13 #include <limits>
14 #include <climits>
15 #include <cwchar>
16 #include <cfloat>
17 #include <cassert>
18 
19 #include "test_macros.h"
20 
21 template <class T>
22 void
23 test(T expected)
24 {
25     assert(std::numeric_limits<T>::max() == expected);
26     assert(std::numeric_limits<T>::is_bounded);
27     assert(std::numeric_limits<const T>::max() == expected);
28     assert(std::numeric_limits<const T>::is_bounded);
29     assert(std::numeric_limits<volatile T>::max() == expected);
30     assert(std::numeric_limits<volatile T>::is_bounded);
31     assert(std::numeric_limits<const volatile T>::max() == expected);
32     assert(std::numeric_limits<const volatile T>::is_bounded);
33 }
34 
35 int main(int, char**)
36 {
37     test<bool>(true);
38     test<char>(CHAR_MAX);
39     test<signed char>(SCHAR_MAX);
40     test<unsigned char>(UCHAR_MAX);
41     test<wchar_t>(WCHAR_MAX);
42 #if TEST_STD_VER > 17 && defined(__cpp_char8_t)
43     test<char8_t>(UCHAR_MAX); // ??
44 #endif
45 #ifndef _LIBCPP_HAS_NO_UNICODE_CHARS
46     test<char16_t>(USHRT_MAX);
47     test<char32_t>(UINT_MAX);
48 #endif  // _LIBCPP_HAS_NO_UNICODE_CHARS
49     test<short>(SHRT_MAX);
50     test<unsigned short>(USHRT_MAX);
51     test<int>(INT_MAX);
52     test<unsigned int>(UINT_MAX);
53     test<long>(LONG_MAX);
54     test<unsigned long>(ULONG_MAX);
55     test<long long>(LLONG_MAX);
56     test<unsigned long long>(ULLONG_MAX);
57 #ifndef _LIBCPP_HAS_NO_INT128
58     test<__int128_t>(__int128_t(__uint128_t(-1)/2));
59     test<__uint128_t>(__uint128_t(-1));
60 #endif
61     test<float>(FLT_MAX);
62     test<double>(DBL_MAX);
63     test<long double>(LDBL_MAX);
64 
65   return 0;
66 }
67