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 #include <limits> 10 11 #include "test_macros.h" 12 13 /* 14 <limits>: 15 numeric_limits 16 is_specialized 17 digits 18 digits10 19 max_digits10 20 is_signed 21 is_integer 22 is_exact 23 radix 24 min_exponent 25 min_exponent10 26 max_exponent 27 max_exponent10 28 has_infinity 29 has_quiet_NaN 30 has_signaling_NaN 31 has_denorm 32 has_denorm_loss 33 is_iec559 34 is_bounded 35 is_modulo 36 traps 37 tinyness_before 38 round_style 39 */ 40 41 template <class T> test(const T &)42void test(const T &) {} 43 44 #define TEST_NUMERIC_LIMITS(type) \ 45 test(std::numeric_limits<type>::is_specialized); \ 46 test(std::numeric_limits<type>::digits); \ 47 test(std::numeric_limits<type>::digits10); \ 48 test(std::numeric_limits<type>::max_digits10); \ 49 test(std::numeric_limits<type>::is_signed); \ 50 test(std::numeric_limits<type>::is_integer); \ 51 test(std::numeric_limits<type>::is_exact); \ 52 test(std::numeric_limits<type>::radix); \ 53 test(std::numeric_limits<type>::min_exponent); \ 54 test(std::numeric_limits<type>::min_exponent10); \ 55 test(std::numeric_limits<type>::max_exponent); \ 56 test(std::numeric_limits<type>::max_exponent10); \ 57 test(std::numeric_limits<type>::has_infinity); \ 58 test(std::numeric_limits<type>::has_quiet_NaN); \ 59 test(std::numeric_limits<type>::has_signaling_NaN); \ 60 test(std::numeric_limits<type>::has_denorm); \ 61 test(std::numeric_limits<type>::has_denorm_loss); \ 62 test(std::numeric_limits<type>::is_iec559); \ 63 test(std::numeric_limits<type>::is_bounded); \ 64 test(std::numeric_limits<type>::is_modulo); \ 65 test(std::numeric_limits<type>::traps); \ 66 test(std::numeric_limits<type>::tinyness_before); \ 67 test(std::numeric_limits<type>::round_style); 68 69 struct other {}; 70 main(int,char **)71int main(int, char**) 72 { 73 // bool 74 TEST_NUMERIC_LIMITS(bool) 75 TEST_NUMERIC_LIMITS(const bool) 76 TEST_NUMERIC_LIMITS(volatile bool) 77 TEST_NUMERIC_LIMITS(const volatile bool) 78 79 // char 80 TEST_NUMERIC_LIMITS(char) 81 TEST_NUMERIC_LIMITS(const char) 82 TEST_NUMERIC_LIMITS(volatile char) 83 TEST_NUMERIC_LIMITS(const volatile char) 84 85 // signed char 86 TEST_NUMERIC_LIMITS(signed char) 87 TEST_NUMERIC_LIMITS(const signed char) 88 TEST_NUMERIC_LIMITS(volatile signed char) 89 TEST_NUMERIC_LIMITS(const volatile signed char) 90 91 // unsigned char 92 TEST_NUMERIC_LIMITS(unsigned char) 93 TEST_NUMERIC_LIMITS(const unsigned char) 94 TEST_NUMERIC_LIMITS(volatile unsigned char) 95 TEST_NUMERIC_LIMITS(const volatile unsigned char) 96 97 // wchar_t 98 TEST_NUMERIC_LIMITS(wchar_t) 99 TEST_NUMERIC_LIMITS(const wchar_t) 100 TEST_NUMERIC_LIMITS(volatile wchar_t) 101 TEST_NUMERIC_LIMITS(const volatile wchar_t) 102 103 #if TEST_STD_VER > 17 && defined(__cpp_char8_t) 104 // char8_t 105 TEST_NUMERIC_LIMITS(char8_t) 106 TEST_NUMERIC_LIMITS(const char8_t) 107 TEST_NUMERIC_LIMITS(volatile char8_t) 108 TEST_NUMERIC_LIMITS(const volatile char8_t) 109 #endif 110 111 // char16_t 112 TEST_NUMERIC_LIMITS(char16_t) 113 TEST_NUMERIC_LIMITS(const char16_t) 114 TEST_NUMERIC_LIMITS(volatile char16_t) 115 TEST_NUMERIC_LIMITS(const volatile char16_t) 116 117 // char32_t 118 TEST_NUMERIC_LIMITS(char32_t) 119 TEST_NUMERIC_LIMITS(const char32_t) 120 TEST_NUMERIC_LIMITS(volatile char32_t) 121 TEST_NUMERIC_LIMITS(const volatile char32_t) 122 123 // short 124 TEST_NUMERIC_LIMITS(short) 125 TEST_NUMERIC_LIMITS(const short) 126 TEST_NUMERIC_LIMITS(volatile short) 127 TEST_NUMERIC_LIMITS(const volatile short) 128 129 // int 130 TEST_NUMERIC_LIMITS(int) 131 TEST_NUMERIC_LIMITS(const int) 132 TEST_NUMERIC_LIMITS(volatile int) 133 TEST_NUMERIC_LIMITS(const volatile int) 134 135 // long 136 TEST_NUMERIC_LIMITS(long) 137 TEST_NUMERIC_LIMITS(const long) 138 TEST_NUMERIC_LIMITS(volatile long) 139 TEST_NUMERIC_LIMITS(const volatile long) 140 141 #ifndef TEST_HAS_NO_INT128 142 TEST_NUMERIC_LIMITS(__int128_t) 143 TEST_NUMERIC_LIMITS(const __int128_t) 144 TEST_NUMERIC_LIMITS(volatile __int128_t) 145 TEST_NUMERIC_LIMITS(const volatile __int128_t) 146 #endif 147 148 // long long 149 TEST_NUMERIC_LIMITS(long long) 150 TEST_NUMERIC_LIMITS(const long long) 151 TEST_NUMERIC_LIMITS(volatile long long) 152 TEST_NUMERIC_LIMITS(const volatile long long) 153 154 // unsigned short 155 TEST_NUMERIC_LIMITS(unsigned short) 156 TEST_NUMERIC_LIMITS(const unsigned short) 157 TEST_NUMERIC_LIMITS(volatile unsigned short) 158 TEST_NUMERIC_LIMITS(const volatile unsigned short) 159 160 // unsigned int 161 TEST_NUMERIC_LIMITS(unsigned int) 162 TEST_NUMERIC_LIMITS(const unsigned int) 163 TEST_NUMERIC_LIMITS(volatile unsigned int) 164 TEST_NUMERIC_LIMITS(const volatile unsigned int) 165 166 // unsigned long 167 TEST_NUMERIC_LIMITS(unsigned long) 168 TEST_NUMERIC_LIMITS(const unsigned long) 169 TEST_NUMERIC_LIMITS(volatile unsigned long) 170 TEST_NUMERIC_LIMITS(const volatile unsigned long) 171 172 // unsigned long long 173 TEST_NUMERIC_LIMITS(unsigned long long) 174 TEST_NUMERIC_LIMITS(const unsigned long long) 175 TEST_NUMERIC_LIMITS(volatile unsigned long long) 176 TEST_NUMERIC_LIMITS(const volatile unsigned long long) 177 178 #ifndef TEST_HAS_NO_INT128 179 TEST_NUMERIC_LIMITS(__uint128_t) 180 TEST_NUMERIC_LIMITS(const __uint128_t) 181 TEST_NUMERIC_LIMITS(volatile __uint128_t) 182 TEST_NUMERIC_LIMITS(const volatile __uint128_t) 183 #endif 184 185 // float 186 TEST_NUMERIC_LIMITS(float) 187 TEST_NUMERIC_LIMITS(const float) 188 TEST_NUMERIC_LIMITS(volatile float) 189 TEST_NUMERIC_LIMITS(const volatile float) 190 191 // double 192 TEST_NUMERIC_LIMITS(double) 193 TEST_NUMERIC_LIMITS(const double) 194 TEST_NUMERIC_LIMITS(volatile double) 195 TEST_NUMERIC_LIMITS(const volatile double) 196 197 // long double 198 TEST_NUMERIC_LIMITS(long double) 199 TEST_NUMERIC_LIMITS(const long double) 200 TEST_NUMERIC_LIMITS(volatile long double) 201 TEST_NUMERIC_LIMITS(const volatile long double) 202 203 // other 204 TEST_NUMERIC_LIMITS(other) 205 TEST_NUMERIC_LIMITS(const other) 206 TEST_NUMERIC_LIMITS(volatile other) 207 TEST_NUMERIC_LIMITS(const volatile other) 208 209 return 0; 210 } 211