• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 // min()
13 
14 #include <limits>
15 #include <climits>
16 #include <cwchar>
17 #include <cfloat>
18 #include <cassert>
19 
20 template <class T>
21 void
test(T expected)22 test(T expected)
23 {
24     assert(std::numeric_limits<T>::min() == expected);
25     assert(std::numeric_limits<T>::is_bounded || !std::numeric_limits<T>::is_signed);
26     assert(std::numeric_limits<const T>::min() == expected);
27     assert(std::numeric_limits<const T>::is_bounded || !std::numeric_limits<const T>::is_signed);
28     assert(std::numeric_limits<volatile T>::min() == expected);
29     assert(std::numeric_limits<volatile T>::is_bounded || !std::numeric_limits<volatile T>::is_signed);
30     assert(std::numeric_limits<const volatile T>::min() == expected);
31     assert(std::numeric_limits<const volatile T>::is_bounded || !std::numeric_limits<const volatile T>::is_signed);
32 }
33 
main()34 int main()
35 {
36     test<bool>(false);
37     test<char>(CHAR_MIN);
38     test<signed char>(SCHAR_MIN);
39     test<unsigned char>(0);
40     test<wchar_t>(WCHAR_MIN);
41 #ifndef _LIBCPP_HAS_NO_UNICODE_CHARS
42     test<char16_t>(0);
43     test<char32_t>(0);
44 #endif  // _LIBCPP_HAS_NO_UNICODE_CHARS
45     test<short>(SHRT_MIN);
46     test<unsigned short>(0);
47     test<int>(INT_MIN);
48     test<unsigned int>(0);
49     test<long>(LONG_MIN);
50     test<unsigned long>(0);
51     test<long long>(LLONG_MIN);
52     test<unsigned long long>(0);
53 #ifndef _LIBCPP_HAS_NO_INT128
54     test<__int128_t>(-__int128_t(__uint128_t(-1)/2) - 1);
55     test<__uint128_t>(0);
56 #endif
57     test<float>(FLT_MIN);
58     test<double>(DBL_MIN);
59     test<long double>(LDBL_MIN);
60 }
61