62 lines · cpp
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-exception6//7//===----------------------------------------------------------------------===//8 9// test numeric_limits10 11// digits1012 13#include <limits>14#include <cfloat>15 16#include "test_macros.h"17 18template <class T, int expected>19void20test()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 32int 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 -> 439#if TEST_STD_VER > 17 && defined(__cpp_char8_t)40 test<char8_t, 2>();41#endif42 test<char16_t, 4>();43 test<char32_t, 9>();44 test<short, 4>();45 test<unsigned short, 4>();46 test<int, 9>();47 test<unsigned int, 9>();48 test<long, sizeof(long) == 4 ? 9 : 18>();49 test<unsigned long, sizeof(long) == 4 ? 9 : 19>();50 test<long long, 18>();51 test<unsigned long long, 19>();52#ifndef TEST_HAS_NO_INT12853 test<__int128_t, 38>();54 test<__uint128_t, 38>();55#endif56 test<float, FLT_DIG>();57 test<double, DBL_DIG>();58 test<long double, LDBL_DIG>();59 60 return 0;61}62