• 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 // digits10
13 
14 #include <limits>
15 #include <cfloat>
16 
17 template <class T, int expected>
18 void
test()19 test()
20 {
21     static_assert(std::numeric_limits<T>::digits10 == expected, "digits10 test 1");
22     static_assert(std::numeric_limits<T>::is_bounded, "digits10 test 5");
23     static_assert(std::numeric_limits<const T>::digits10 == expected, "digits10 test 2");
24     static_assert(std::numeric_limits<const T>::is_bounded, "digits10 test 6");
25     static_assert(std::numeric_limits<volatile T>::digits10 == expected, "digits10 test 3");
26     static_assert(std::numeric_limits<volatile T>::is_bounded, "digits10 test 7");
27     static_assert(std::numeric_limits<const volatile T>::digits10 == expected, "digits10 test 4");
28     static_assert(std::numeric_limits<const volatile T>::is_bounded, "digits10 test 8");
29 }
30 
main()31 int main()
32 {
33     test<bool, 0>();
34     test<char, 2>();
35     test<signed char, 2>();
36     test<unsigned char, 2>();
37     test<wchar_t, 5*sizeof(wchar_t)/2-1>();  // 4 -> 9 and 2 -> 4
38 #ifndef _LIBCPP_HAS_NO_UNICODE_CHARS
39     test<char16_t, 4>();
40     test<char32_t, 9>();
41 #endif  // _LIBCPP_HAS_NO_UNICODE_CHARS
42     test<short, 4>();
43     test<unsigned short, 4>();
44     test<int, 9>();
45     test<unsigned int, 9>();
46     test<long, sizeof(long) == 4 ? 9 : 18>();
47     test<unsigned long, sizeof(long) == 4 ? 9 : 19>();
48     test<long long, 18>();
49     test<unsigned long long, 19>();
50 #ifndef _LIBCPP_HAS_NO_INT128
51     test<__int128_t, 38>();
52     test<__uint128_t, 38>();
53 #endif
54     test<float, FLT_DIG>();
55     test<double, DBL_DIG>();
56     test<long double, LDBL_DIG>();
57 }
58