epsilon.pass.cpp 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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. // epsilon()
  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>::epsilon() == expected);
  19. assert(std::numeric_limits<const T>::epsilon() == expected);
  20. assert(std::numeric_limits<volatile T>::epsilon() == expected);
  21. assert(std::numeric_limits<const volatile T>::epsilon() == expected);
  22. }
  23. int main()
  24. {
  25. test<bool>(false);
  26. test<char>(0);
  27. test<signed char>(0);
  28. test<unsigned char>(0);
  29. test<wchar_t>(0);
  30. #ifndef _LIBCPP_HAS_NO_UNICODE_CHARS
  31. test<char16_t>(0);
  32. test<char32_t>(0);
  33. #endif // _LIBCPP_HAS_NO_UNICODE_CHARS
  34. test<short>(0);
  35. test<unsigned short>(0);
  36. test<int>(0);
  37. test<unsigned int>(0);
  38. test<long>(0);
  39. test<unsigned long>(0);
  40. test<long long>(0);
  41. test<unsigned long long>(0);
  42. test<float>(FLT_EPSILON);
  43. test<double>(DBL_EPSILON);
  44. test<long double>(LDBL_EPSILON);
  45. }