Home | History | Annotate | Download | only in numeric.limits.members
      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 template <class T, int expected>
     18 void
     19 test()
     20 {
     21     static_assert(std::numeric_limits<T>::digits == expected, "digits test 1");
     22     static_assert(std::numeric_limits<const T>::digits == expected, "digits test 2");
     23     static_assert(std::numeric_limits<volatile T>::digits == expected, "digits test 3");
     24     static_assert(std::numeric_limits<const volatile T>::digits == expected, "digits test 4");
     25 }
     26 
     27 int main()
     28 {
     29     test<bool, 1>();
     30     test<char, std::numeric_limits<char>::is_signed ? 7 : 8>();
     31     test<signed char, 7>();
     32     test<unsigned char, 8>();
     33     test<wchar_t, std::numeric_limits<wchar_t>::is_signed ? sizeof(wchar_t)*8-1 : sizeof(wchar_t)*8>();
     34 #ifndef _LIBCPP_HAS_NO_UNICODE_CHARS
     35     test<char16_t, 16>();
     36     test<char32_t, 32>();
     37 #endif  // _LIBCPP_HAS_NO_UNICODE_CHARS
     38     test<short, 15>();
     39     test<unsigned short, 16>();
     40     test<int, 31>();
     41     test<unsigned int, 32>();
     42     test<long, sizeof(long) == 4 ? 31 : 63>();
     43     test<unsigned long, sizeof(long) == 4 ? 32 : 64>();
     44     test<long long, 63>();
     45     test<unsigned long long, 64>();
     46 #ifndef _LIBCPP_HAS_NO_INT128
     47     test<__int128_t, 127>();
     48     test<__uint128_t, 128>();
     49 #endif
     50     test<float, FLT_MANT_DIG>();
     51     test<double, DBL_MANT_DIG>();
     52     test<long double, LDBL_MANT_DIG>();
     53 }
     54