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