digits10.pass.cpp 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. //===----------------------------------------------------------------------===//
  2. //
  3. // The LLVM Compiler Infrastructure
  4. //
  5. // This file is distributed under the University of Illinois Open Source
  6. // License. See LICENSE.TXT for details.
  7. //
  8. //===----------------------------------------------------------------------===//
  9. // test numeric_limits
  10. // digits10
  11. #include <limits>
  12. #include <cfloat>
  13. template <class T, int expected>
  14. void
  15. test()
  16. {
  17. static_assert(std::numeric_limits<T>::digits10 == expected, "digits10 test 1");
  18. static_assert(std::numeric_limits<T>::is_bounded, "digits10 test 5");
  19. static_assert(std::numeric_limits<const T>::digits10 == expected, "digits10 test 2");
  20. static_assert(std::numeric_limits<const T>::is_bounded, "digits10 test 6");
  21. static_assert(std::numeric_limits<volatile T>::digits10 == expected, "digits10 test 3");
  22. static_assert(std::numeric_limits<volatile T>::is_bounded, "digits10 test 7");
  23. static_assert(std::numeric_limits<const volatile T>::digits10 == expected, "digits10 test 4");
  24. static_assert(std::numeric_limits<const volatile T>::is_bounded, "digits10 test 8");
  25. }
  26. int main()
  27. {
  28. test<bool, 0>();
  29. test<char, 2>();
  30. test<signed char, 2>();
  31. test<unsigned char, 2>();
  32. test<wchar_t, 9>();
  33. #ifndef _LIBCPP_HAS_NO_UNICODE_CHARS
  34. test<char16_t, 4>();
  35. test<char32_t, 9>();
  36. #endif // _LIBCPP_HAS_NO_UNICODE_CHARS
  37. test<short, 4>();
  38. test<unsigned short, 4>();
  39. test<int, 9>();
  40. test<unsigned int, 9>();
  41. test<long, sizeof(long) == 4 ? 9 : 18>();
  42. test<unsigned long, sizeof(long) == 4 ? 9 : 19>();
  43. test<long long, 18>();
  44. test<unsigned long long, 19>();
  45. test<float, FLT_DIG>();
  46. test<double, DBL_DIG>();
  47. test<long double, LDBL_DIG>();
  48. }