• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 // epsilon()
13 
14 #include <limits>
15 #include <cfloat>
16 #include <cassert>
17 
18 template <class T>
19 void
test(T expected)20 test(T expected)
21 {
22     assert(std::numeric_limits<T>::epsilon() == expected);
23     assert(std::numeric_limits<const T>::epsilon() == expected);
24     assert(std::numeric_limits<volatile T>::epsilon() == expected);
25     assert(std::numeric_limits<const volatile T>::epsilon() == expected);
26 }
27 
main()28 int main()
29 {
30     test<bool>(false);
31     test<char>(0);
32     test<signed char>(0);
33     test<unsigned char>(0);
34     test<wchar_t>(0);
35 #ifndef _LIBCPP_HAS_NO_UNICODE_CHARS
36     test<char16_t>(0);
37     test<char32_t>(0);
38 #endif  // _LIBCPP_HAS_NO_UNICODE_CHARS
39     test<short>(0);
40     test<unsigned short>(0);
41     test<int>(0);
42     test<unsigned int>(0);
43     test<long>(0);
44     test<unsigned long>(0);
45     test<long long>(0);
46     test<unsigned long long>(0);
47 #ifndef _LIBCPP_HAS_NO_INT128
48     test<__int128_t>(0);
49     test<__uint128_t>(0);
50 #endif
51     test<float>(FLT_EPSILON);
52     test<double>(DBL_EPSILON);
53     test<long double>(LDBL_EPSILON);
54 }
55