1 //===----------------------------------------------------------------------===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is dual licensed under the MIT and the University of Illinois Open
6 // Source Licenses. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 
10 // test numeric_limits
11 
12 // lowest()
13 
14 #include <limits>
15 #include <climits>
16 #include <cwchar>
17 #include <cfloat>
18 #include <cassert>
19 
20 #include "test_macros.h"
21 
22 template <class T>
23 void
test(T expected)24 test(T expected)
25 {
26     assert(std::numeric_limits<T>::lowest() == expected);
27     assert(std::numeric_limits<T>::is_bounded);
28     assert(std::numeric_limits<const T>::lowest() == expected);
29     assert(std::numeric_limits<const T>::is_bounded);
30     assert(std::numeric_limits<volatile T>::lowest() == expected);
31     assert(std::numeric_limits<volatile T>::is_bounded);
32     assert(std::numeric_limits<const volatile T>::lowest() == expected);
33     assert(std::numeric_limits<const volatile T>::is_bounded);
34 }
35 
main()36 int main()
37 {
38     test<bool>(false);
39     test<char>(CHAR_MIN);
40     test<signed char>(SCHAR_MIN);
41     test<unsigned char>(0);
42     test<wchar_t>(WCHAR_MIN);
43 #if TEST_STD_VER > 17 && defined(__cpp_char8_t)
44     test<char8_t>(0);
45 #endif
46 #ifndef _LIBCPP_HAS_NO_UNICODE_CHARS
47     test<char16_t>(0);
48     test<char32_t>(0);
49 #endif  // _LIBCPP_HAS_NO_UNICODE_CHARS
50     test<short>(SHRT_MIN);
51     test<unsigned short>(0);
52     test<int>(INT_MIN);
53     test<unsigned int>(0);
54     test<long>(LONG_MIN);
55     test<unsigned long>(0);
56     test<long long>(LLONG_MIN);
57     test<unsigned long long>(0);
58 #ifndef _LIBCPP_HAS_NO_INT128
59     test<__int128_t>(-__int128_t(__uint128_t(-1)/2) - 1);
60     test<__uint128_t>(0);
61 #endif
62     test<float>(-FLT_MAX);
63     test<double>(-DBL_MAX);
64     test<long double>(-LDBL_MAX);
65 }
66