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