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 // max() 12 13 #include <limits> 14 #include <climits> 15 #include <cfloat> 16 #include <cassert> 17 18 #include "test_macros.h" 19 20 #ifndef TEST_HAS_NO_WIDE_CHARACTERS 21 # include <cwchar> 22 #endif 23 24 template <class T> 25 void test(T expected)26test(T expected) 27 { 28 assert(std::numeric_limits<T>::max() == expected); 29 assert(std::numeric_limits<T>::is_bounded); 30 assert(std::numeric_limits<const T>::max() == expected); 31 assert(std::numeric_limits<const T>::is_bounded); 32 assert(std::numeric_limits<volatile T>::max() == expected); 33 assert(std::numeric_limits<volatile T>::is_bounded); 34 assert(std::numeric_limits<const volatile T>::max() == expected); 35 assert(std::numeric_limits<const volatile T>::is_bounded); 36 } 37 main(int,char **)38int main(int, char**) 39 { 40 test<bool>(true); 41 test<char>(CHAR_MAX); 42 test<signed char>(SCHAR_MAX); 43 test<unsigned char>(UCHAR_MAX); 44 #ifndef TEST_HAS_NO_WIDE_CHARACTERS 45 test<wchar_t>(WCHAR_MAX); 46 #endif 47 #if TEST_STD_VER > 17 && defined(__cpp_char8_t) 48 test<char8_t>(UCHAR_MAX); // ?? 49 #endif 50 test<char16_t>(USHRT_MAX); 51 test<char32_t>(UINT_MAX); 52 test<short>(SHRT_MAX); 53 test<unsigned short>(USHRT_MAX); 54 test<int>(INT_MAX); 55 test<unsigned int>(UINT_MAX); 56 test<long>(LONG_MAX); 57 test<unsigned long>(ULONG_MAX); 58 test<long long>(LLONG_MAX); 59 test<unsigned long long>(ULLONG_MAX); 60 #ifndef TEST_HAS_NO_INT128 61 test<__int128_t>(__int128_t(__uint128_t(-1)/2)); 62 test<__uint128_t>(__uint128_t(-1)); 63 #endif 64 test<float>(FLT_MAX); 65 test<double>(DBL_MAX); 66 test<long double>(LDBL_MAX); 67 68 return 0; 69 } 70