round_style.pass.cpp (2063B)
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 // round_style 13 14 #include <limits> 15 16 #include "test_macros.h" 17 18 template <class T, std::float_round_style expected> 19 void 20 test() 21 { 22 static_assert(std::numeric_limits<T>::round_style == expected, "round_style test 1"); 23 static_assert(std::numeric_limits<const T>::round_style == expected, "round_style test 2"); 24 static_assert(std::numeric_limits<volatile T>::round_style == expected, "round_style test 3"); 25 static_assert(std::numeric_limits<const volatile T>::round_style == expected, "round_style test 4"); 26 } 27 28 int main() 29 { 30 test<bool, std::round_toward_zero>(); 31 test<char, std::round_toward_zero>(); 32 test<signed char, std::round_toward_zero>(); 33 test<unsigned char, std::round_toward_zero>(); 34 test<wchar_t, std::round_toward_zero>(); 35 #if TEST_STD_VER > 17 && defined(__cpp_char8_t) 36 test<char8_t, std::round_toward_zero>(); 37 #endif 38 #ifndef _LIBCPP_HAS_NO_UNICODE_CHARS 39 test<char16_t, std::round_toward_zero>(); 40 test<char32_t, std::round_toward_zero>(); 41 #endif // _LIBCPP_HAS_NO_UNICODE_CHARS 42 test<short, std::round_toward_zero>(); 43 test<unsigned short, std::round_toward_zero>(); 44 test<int, std::round_toward_zero>(); 45 test<unsigned int, std::round_toward_zero>(); 46 test<long, std::round_toward_zero>(); 47 test<unsigned long, std::round_toward_zero>(); 48 test<long long, std::round_toward_zero>(); 49 test<unsigned long long, std::round_toward_zero>(); 50 #ifndef _LIBCPP_HAS_NO_INT128 51 test<__int128_t, std::round_toward_zero>(); 52 test<__uint128_t, std::round_toward_zero>(); 53 #endif 54 test<float, std::round_to_nearest>(); 55 test<double, std::round_to_nearest>(); 56 test<long double, std::round_to_nearest>(); 57 }