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