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 // lowest()
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>::lowest() == expected);
26     assert(std::numeric_limits<T>::is_bounded);
27     assert(std::numeric_limits<const T>::lowest() == expected);
28     assert(std::numeric_limits<const T>::is_bounded);
29     assert(std::numeric_limits<volatile T>::lowest() == expected);
30     assert(std::numeric_limits<volatile T>::is_bounded);
31     assert(std::numeric_limits<const volatile T>::lowest() == expected);
32     assert(std::numeric_limits<const volatile T>::is_bounded);
33 }
34 
35 int main(int, char**)
36 {
37     test<bool>(false);
38     test<char>(CHAR_MIN);
39     test<signed char>(SCHAR_MIN);
40     test<unsigned char>(0);
41     test<wchar_t>(WCHAR_MIN);
42 #if TEST_STD_VER > 17 && defined(__cpp_char8_t)
43     test<char8_t>(0);
44 #endif
45 #ifndef _LIBCPP_HAS_NO_UNICODE_CHARS
46     test<char16_t>(0);
47     test<char32_t>(0);
48 #endif
49     test<short>(SHRT_MIN);
50     test<unsigned short>(0);
51     test<int>(INT_MIN);
52     test<unsigned int>(0);
53     test<long>(LONG_MIN);
54     test<unsigned long>(0);
55     test<long long>(LLONG_MIN);
56     test<unsigned long long>(0);
57 #ifndef _LIBCPP_HAS_NO_INT128
58     test<__int128_t>(-__int128_t(__uint128_t(-1)/2) - 1);
59     test<__uint128_t>(0);
60 #endif
61     test<float>(-FLT_MAX);
62     test<double>(-DBL_MAX);
63     test<long double>(-LDBL_MAX);
64 
65   return 0;
66 }
67