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 // infinity() 13 14 #include <limits> 15 #include <cfloat> 16 #include <cassert> 17 18 #include "test_macros.h" 19 20 template <class T> 21 void test(T expected)22test(T expected) 23 { 24 assert(std::numeric_limits<T>::infinity() == expected); 25 assert(std::numeric_limits<const T>::infinity() == expected); 26 assert(std::numeric_limits<volatile T>::infinity() == expected); 27 assert(std::numeric_limits<const volatile T>::infinity() == expected); 28 } 29 30 extern float zero; 31 main()32int main() 33 { 34 test<bool>(false); 35 test<char>(0); 36 test<signed char>(0); 37 test<unsigned char>(0); 38 test<wchar_t>(0); 39 #if TEST_STD_VER > 17 && defined(__cpp_char8_t) 40 test<char8_t>(0); 41 #endif 42 #ifndef _LIBCPP_HAS_NO_UNICODE_CHARS 43 test<char16_t>(0); 44 test<char32_t>(0); 45 #endif // _LIBCPP_HAS_NO_UNICODE_CHARS 46 test<short>(0); 47 test<unsigned short>(0); 48 test<int>(0); 49 test<unsigned int>(0); 50 test<long>(0); 51 test<unsigned long>(0); 52 test<long long>(0); 53 test<unsigned long long>(0); 54 #ifndef _LIBCPP_HAS_NO_INT128 55 test<__int128_t>(0); 56 test<__uint128_t>(0); 57 #endif 58 test<float>(1.f/zero); 59 test<double>(1./zero); 60 test<long double>(1./zero); 61 } 62 63 float zero = 0; 64