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 // digits
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>::digits == expected, "digits test 1");
24 static_assert(std::numeric_limits<const T>::digits == expected, "digits test 2");
25 static_assert(std::numeric_limits<volatile T>::digits == expected, "digits test 3");
26 static_assert(std::numeric_limits<const volatile T>::digits == expected, "digits test 4");
27 }
28
main()29 int main()
30 {
31 test<bool, 1>();
32 test<char, std::numeric_limits<char>::is_signed ? 7 : 8>();
33 test<signed char, 7>();
34 test<unsigned char, 8>();
35 test<wchar_t, std::numeric_limits<wchar_t>::is_signed ? sizeof(wchar_t)*8-1 : sizeof(wchar_t)*8>();
36 #if TEST_STD_VER > 17 && defined(__cpp_char8_t)
37 test<char8_t, 8>();
38 #endif
39 #ifndef _LIBCPP_HAS_NO_UNICODE_CHARS
40 test<char16_t, 16>();
41 test<char32_t, 32>();
42 #endif // _LIBCPP_HAS_NO_UNICODE_CHARS
43 test<short, 15>();
44 test<unsigned short, 16>();
45 test<int, 31>();
46 test<unsigned int, 32>();
47 test<long, sizeof(long) == 4 ? 31 : 63>();
48 test<unsigned long, sizeof(long) == 4 ? 32 : 64>();
49 test<long long, 63>();
50 test<unsigned long long, 64>();
51 #ifndef _LIBCPP_HAS_NO_INT128
52 test<__int128_t, 127>();
53 test<__uint128_t, 128>();
54 #endif
55 test<float, FLT_MANT_DIG>();
56 test<double, DBL_MANT_DIG>();
57 test<long double, LDBL_MANT_DIG>();
58 }
59