1 //===----------------------------------------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 // test numeric_limits
10 
11 // max_digits10
12 
13 #include <limits>
14 #include <cfloat>
15 
16 #include "test_macros.h"
17 
18 template <class T, int expected>
19 void
test()20 test()
21 {
22     static_assert(std::numeric_limits<T>::max_digits10 == expected, "max_digits10 test 1");
23     static_assert(std::numeric_limits<const T>::max_digits10 == expected, "max_digits10 test 2");
24     static_assert(std::numeric_limits<volatile T>::max_digits10 == expected, "max_digits10 test 3");
25     static_assert(std::numeric_limits<const volatile T>::max_digits10 == expected, "max_digits10 test 4");
26 }
27 
main(int,char **)28 int main(int, char**)
29 {
30     test<bool, 0>();
31     test<char, 0>();
32     test<signed char, 0>();
33     test<unsigned char, 0>();
34     test<wchar_t, 0>();
35 #if TEST_STD_VER > 17 && defined(__cpp_char8_t)
36     test<char8_t, 0>();
37 #endif
38 #ifndef _LIBCPP_HAS_NO_UNICODE_CHARS
39     test<char16_t, 0>();
40     test<char32_t, 0>();
41 #endif  // _LIBCPP_HAS_NO_UNICODE_CHARS
42     test<short, 0>();
43     test<unsigned short, 0>();
44     test<int, 0>();
45     test<unsigned int, 0>();
46     test<long, 0>();
47     test<unsigned long, 0>();
48     test<long long, 0>();
49     test<unsigned long long, 0>();
50 #ifndef _LIBCPP_HAS_NO_INT128
51     test<__int128_t, 0>();
52     test<__uint128_t, 0>();
53 #endif
54     test<float, 2+(FLT_MANT_DIG * 30103)/100000>();
55     test<double, 2+(DBL_MANT_DIG * 30103)/100000>();
56     test<long double, 2+(LDBL_MANT_DIG * 30103)/100000>();
57 
58   return 0;
59 }
60