1 //===----------------------------------------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 // test numeric_limits
10 
11 // round_error()
12 
13 #include <limits>
14 #include <cfloat>
15 #include <cassert>
16 
17 #include "test_macros.h"
18 
19 template <class T>
20 void
test(T expected)21 test(T expected)
22 {
23     assert(std::numeric_limits<T>::round_error() == expected);
24     assert(std::numeric_limits<const T>::round_error() == expected);
25     assert(std::numeric_limits<volatile T>::round_error() == expected);
26     assert(std::numeric_limits<const volatile T>::round_error() == expected);
27 }
28 
main(int,char **)29 int main(int, char**)
30 {
31     test<bool>(false);
32     test<char>(0);
33     test<signed char>(0);
34     test<unsigned char>(0);
35     test<wchar_t>(0);
36 #if TEST_STD_VER > 17 && defined(__cpp_char8_t)
37     test<char8_t>(0);
38 #endif
39 #ifndef _LIBCPP_HAS_NO_UNICODE_CHARS
40     test<char16_t>(0);
41     test<char32_t>(0);
42 #endif  // _LIBCPP_HAS_NO_UNICODE_CHARS
43     test<short>(0);
44     test<unsigned short>(0);
45     test<int>(0);
46     test<unsigned int>(0);
47     test<long>(0);
48     test<unsigned long>(0);
49     test<long long>(0);
50     test<unsigned long long>(0);
51 #ifndef _LIBCPP_HAS_NO_INT128
52     test<__int128_t>(0);
53     test<__uint128_t>(0);
54 #endif
55     test<float>(0.5);
56     test<double>(0.5);
57     test<long double>(0.5);
58 
59   return 0;
60 }
61