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