signaling_NaN.pass.cpp (1924B)
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 // signaling_NaN() 13 14 #include <limits> 15 #include <cmath> 16 #include <type_traits> 17 #include <cassert> 18 19 #include "test_macros.h" 20 21 template <class T> 22 void 23 test_imp(std::true_type) 24 { 25 assert(std::isnan(std::numeric_limits<T>::signaling_NaN())); 26 assert(std::isnan(std::numeric_limits<const T>::signaling_NaN())); 27 assert(std::isnan(std::numeric_limits<volatile T>::signaling_NaN())); 28 assert(std::isnan(std::numeric_limits<const volatile T>::signaling_NaN())); 29 } 30 31 template <class T> 32 void 33 test_imp(std::false_type) 34 { 35 assert(std::numeric_limits<T>::signaling_NaN() == T()); 36 assert(std::numeric_limits<const T>::signaling_NaN() == T()); 37 assert(std::numeric_limits<volatile T>::signaling_NaN() == T()); 38 assert(std::numeric_limits<const volatile T>::signaling_NaN() == T()); 39 } 40 41 template <class T> 42 inline 43 void 44 test() 45 { 46 test_imp<T>(std::is_floating_point<T>()); 47 } 48 49 int main() 50 { 51 test<bool>(); 52 test<char>(); 53 test<signed char>(); 54 test<unsigned char>(); 55 test<wchar_t>(); 56 #if TEST_STD_VER > 17 && defined(__cpp_char8_t) 57 test<char8_t>(); 58 #endif 59 #ifndef _LIBCPP_HAS_NO_UNICODE_CHARS 60 test<char16_t>(); 61 test<char32_t>(); 62 #endif // _LIBCPP_HAS_NO_UNICODE_CHARS 63 test<short>(); 64 test<unsigned short>(); 65 test<int>(); 66 test<unsigned int>(); 67 test<long>(); 68 test<unsigned long>(); 69 test<long long>(); 70 test<unsigned long long>(); 71 #ifndef _LIBCPP_HAS_NO_INT128 72 test<__int128_t>(); 73 test<__uint128_t>(); 74 #endif 75 test<float>(); 76 test<double>(); 77 test<long double>(); 78 }