infinity.pass.cpp 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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. // infinity()
  11. #include <limits>
  12. #include <cfloat>
  13. #include <cassert>
  14. template <class T>
  15. void
  16. test(T expected)
  17. {
  18. assert(std::numeric_limits<T>::infinity() == expected);
  19. assert(std::numeric_limits<const T>::infinity() == expected);
  20. assert(std::numeric_limits<volatile T>::infinity() == expected);
  21. assert(std::numeric_limits<const volatile T>::infinity() == expected);
  22. }
  23. extern float zero;
  24. int main()
  25. {
  26. test<bool>(false);
  27. test<char>(0);
  28. test<signed char>(0);
  29. test<unsigned char>(0);
  30. test<wchar_t>(0);
  31. #ifndef _LIBCPP_HAS_NO_UNICODE_CHARS
  32. test<char16_t>(0);
  33. test<char32_t>(0);
  34. #endif // _LIBCPP_HAS_NO_UNICODE_CHARS
  35. test<short>(0);
  36. test<unsigned short>(0);
  37. test<int>(0);
  38. test<unsigned int>(0);
  39. test<long>(0);
  40. test<unsigned long>(0);
  41. test<long long>(0);
  42. test<unsigned long long>(0);
  43. test<float>(1./zero);
  44. test<double>(1./zero);
  45. test<long double>(1./zero);
  46. }
  47. float zero = 0;