| 1 | // -*- C++ -*- |
| 2 | //===----------------------------------------------------------------------===// |
| 3 | // |
| 4 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 5 | // See https://llvm.org/LICENSE.txt for license information. |
| 6 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | |
| 10 | #ifndef _LIBCPP_LIMITS |
| 11 | #define _LIBCPP_LIMITS |
| 12 | |
| 13 | /* |
| 14 | limits synopsis |
| 15 | |
| 16 | namespace std |
| 17 | { |
| 18 | |
| 19 | template<class T> |
| 20 | class numeric_limits |
| 21 | { |
| 22 | public: |
| 23 | static constexpr bool is_specialized = false; |
| 24 | static constexpr T min() noexcept; |
| 25 | static constexpr T max() noexcept; |
| 26 | static constexpr T lowest() noexcept; |
| 27 | |
| 28 | static constexpr int digits = 0; |
| 29 | static constexpr int digits10 = 0; |
| 30 | static constexpr int max_digits10 = 0; |
| 31 | static constexpr bool is_signed = false; |
| 32 | static constexpr bool is_integer = false; |
| 33 | static constexpr bool is_exact = false; |
| 34 | static constexpr int radix = 0; |
| 35 | static constexpr T epsilon() noexcept; |
| 36 | static constexpr T round_error() noexcept; |
| 37 | |
| 38 | static constexpr int min_exponent = 0; |
| 39 | static constexpr int min_exponent10 = 0; |
| 40 | static constexpr int max_exponent = 0; |
| 41 | static constexpr int max_exponent10 = 0; |
| 42 | |
| 43 | static constexpr bool has_infinity = false; |
| 44 | static constexpr bool has_quiet_NaN = false; |
| 45 | static constexpr bool has_signaling_NaN = false; |
| 46 | static constexpr float_denorm_style has_denorm = denorm_absent; // deprecated in C++23 |
| 47 | static constexpr bool has_denorm_loss = false; // deprecated in C++23 |
| 48 | static constexpr T infinity() noexcept; |
| 49 | static constexpr T quiet_NaN() noexcept; |
| 50 | static constexpr T signaling_NaN() noexcept; |
| 51 | static constexpr T denorm_min() noexcept; |
| 52 | |
| 53 | static constexpr bool is_iec559 = false; |
| 54 | static constexpr bool is_bounded = false; |
| 55 | static constexpr bool is_modulo = false; |
| 56 | |
| 57 | static constexpr bool traps = false; |
| 58 | static constexpr bool tinyness_before = false; |
| 59 | static constexpr float_round_style round_style = round_toward_zero; |
| 60 | }; |
| 61 | |
| 62 | enum float_round_style |
| 63 | { |
| 64 | round_indeterminate = -1, |
| 65 | round_toward_zero = 0, |
| 66 | round_to_nearest = 1, |
| 67 | round_toward_infinity = 2, |
| 68 | round_toward_neg_infinity = 3 |
| 69 | }; |
| 70 | |
| 71 | enum float_denorm_style // deprecated in C++23 |
| 72 | { |
| 73 | denorm_indeterminate = -1, |
| 74 | denorm_absent = 0, |
| 75 | denorm_present = 1 |
| 76 | }; |
| 77 | |
| 78 | template<> class numeric_limits<cv bool>; |
| 79 | |
| 80 | template<> class numeric_limits<cv char>; |
| 81 | template<> class numeric_limits<cv signed char>; |
| 82 | template<> class numeric_limits<cv unsigned char>; |
| 83 | template<> class numeric_limits<cv wchar_t>; |
| 84 | template<> class numeric_limits<cv char8_t>; // C++20 |
| 85 | template<> class numeric_limits<cv char16_t>; |
| 86 | template<> class numeric_limits<cv char32_t>; |
| 87 | |
| 88 | template<> class numeric_limits<cv short>; |
| 89 | template<> class numeric_limits<cv int>; |
| 90 | template<> class numeric_limits<cv long>; |
| 91 | template<> class numeric_limits<cv long long>; |
| 92 | template<> class numeric_limits<cv unsigned short>; |
| 93 | template<> class numeric_limits<cv unsigned int>; |
| 94 | template<> class numeric_limits<cv unsigned long>; |
| 95 | template<> class numeric_limits<cv unsigned long long>; |
| 96 | |
| 97 | template<> class numeric_limits<cv float>; |
| 98 | template<> class numeric_limits<cv double>; |
| 99 | template<> class numeric_limits<cv long double>; |
| 100 | |
| 101 | } // std |
| 102 | |
| 103 | */ |
| 104 | |
| 105 | #if __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS) |
| 106 | # include <__cxx03/limits> |
| 107 | #else |
| 108 | # include <__config> |
| 109 | # include <__type_traits/is_arithmetic.h> |
| 110 | # include <__type_traits/is_same.h> |
| 111 | # include <__type_traits/make_unsigned.h> |
| 112 | |
| 113 | # if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) |
| 114 | # pragma GCC system_header |
| 115 | # endif |
| 116 | |
| 117 | _LIBCPP_PUSH_MACROS |
| 118 | # include <__undef_macros> |
| 119 | # include <version> |
| 120 | |
| 121 | _LIBCPP_BEGIN_NAMESPACE_STD |
| 122 | |
| 123 | enum float_round_style { |
| 124 | round_indeterminate = -1, |
| 125 | round_toward_zero = 0, |
| 126 | round_to_nearest = 1, |
| 127 | round_toward_infinity = 2, |
| 128 | round_toward_neg_infinity = 3 |
| 129 | }; |
| 130 | |
| 131 | enum _LIBCPP_DEPRECATED_IN_CXX23 float_denorm_style { |
| 132 | denorm_indeterminate = -1, |
| 133 | denorm_absent = 0, |
| 134 | denorm_present = 1 |
| 135 | }; |
| 136 | |
| 137 | template <class _Tp, bool = is_arithmetic<_Tp>::value> |
| 138 | class __libcpp_numeric_limits { |
| 139 | protected: |
| 140 | typedef _Tp type; |
| 141 | |
| 142 | static _LIBCPP_CONSTEXPR const bool is_specialized = false; |
| 143 | [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR type min() _NOEXCEPT { return type(); } |
| 144 | [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR type max() _NOEXCEPT { return type(); } |
| 145 | [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR type lowest() _NOEXCEPT { return type(); } |
| 146 | |
| 147 | static _LIBCPP_CONSTEXPR const int digits = 0; |
| 148 | static _LIBCPP_CONSTEXPR const int digits10 = 0; |
| 149 | static _LIBCPP_CONSTEXPR const int max_digits10 = 0; |
| 150 | static _LIBCPP_CONSTEXPR const bool is_signed = false; |
| 151 | static _LIBCPP_CONSTEXPR const bool is_integer = false; |
| 152 | static _LIBCPP_CONSTEXPR const bool is_exact = false; |
| 153 | static _LIBCPP_CONSTEXPR const int radix = 0; |
| 154 | [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR type epsilon() _NOEXCEPT { return type(); } |
| 155 | [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR type round_error() _NOEXCEPT { return type(); } |
| 156 | |
| 157 | static _LIBCPP_CONSTEXPR const int min_exponent = 0; |
| 158 | static _LIBCPP_CONSTEXPR const int min_exponent10 = 0; |
| 159 | static _LIBCPP_CONSTEXPR const int max_exponent = 0; |
| 160 | static _LIBCPP_CONSTEXPR const int max_exponent10 = 0; |
| 161 | |
| 162 | static _LIBCPP_CONSTEXPR const bool has_infinity = false; |
| 163 | static _LIBCPP_CONSTEXPR const bool has_quiet_NaN = false; |
| 164 | static _LIBCPP_CONSTEXPR const bool has_signaling_NaN = false; |
| 165 | static _LIBCPP_DEPRECATED_IN_CXX23 _LIBCPP_CONSTEXPR const float_denorm_style has_denorm = denorm_absent; |
| 166 | static _LIBCPP_DEPRECATED_IN_CXX23 _LIBCPP_CONSTEXPR const bool has_denorm_loss = false; |
| 167 | [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR type infinity() _NOEXCEPT { return type(); } |
| 168 | [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR type quiet_NaN() _NOEXCEPT { return type(); } |
| 169 | [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR type signaling_NaN() _NOEXCEPT { return type(); } |
| 170 | [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR type denorm_min() _NOEXCEPT { return type(); } |
| 171 | |
| 172 | static _LIBCPP_CONSTEXPR const bool is_iec559 = false; |
| 173 | static _LIBCPP_CONSTEXPR const bool is_bounded = false; |
| 174 | static _LIBCPP_CONSTEXPR const bool is_modulo = false; |
| 175 | |
| 176 | static _LIBCPP_CONSTEXPR const bool traps = false; |
| 177 | static _LIBCPP_CONSTEXPR const bool tinyness_before = false; |
| 178 | static _LIBCPP_CONSTEXPR const float_round_style round_style = round_toward_zero; |
| 179 | }; |
| 180 | |
| 181 | template <class _Tp> |
| 182 | class __libcpp_numeric_limits<_Tp, true> { |
| 183 | protected: |
| 184 | typedef _Tp type; |
| 185 | |
| 186 | static _LIBCPP_CONSTEXPR const bool is_specialized = true; |
| 187 | |
| 188 | static _LIBCPP_CONSTEXPR const bool is_signed = type(-1) < type(0); |
| 189 | // Number of value bits in type. Works for any integer type, including |
| 190 | // _BitInt(N), whose sizeof(type) * CHAR_BIT may include padding. |
| 191 | static _LIBCPP_CONSTEXPR const int digits = |
| 192 | __builtin_popcountg(static_cast<__make_unsigned_t<type> >(~__make_unsigned_t<type>(0))) - is_signed; |
| 193 | // digits10 = floor(digits * log10(2)). 1936274/6432163 is a continued-fraction |
| 194 | // convergent of log10(2) and matches floor(digits * log10(2)) exactly for every |
| 195 | // digits in [1, 8388608], i.e. up to __BITINT_MAXWIDTH__ on x86. |
| 196 | // TODO: switch to __builtin_log10 once it becomes constexpr. |
| 197 | static _LIBCPP_CONSTEXPR const int digits10 = static_cast<int>((digits * 1936274LL) / 6432163); |
| 198 | static _LIBCPP_CONSTEXPR const int max_digits10 = 0; |
| 199 | static _LIBCPP_CONSTEXPR const type __min = is_signed ? _Tp(_Tp(1) << digits) : 0; |
| 200 | static _LIBCPP_CONSTEXPR const type __max = is_signed ? type(type(~0) ^ __min) : type(~0); |
| 201 | [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR type min() _NOEXCEPT { return __min; } |
| 202 | [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR type max() _NOEXCEPT { return __max; } |
| 203 | [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR type lowest() _NOEXCEPT { return min(); } |
| 204 | |
| 205 | static _LIBCPP_CONSTEXPR const bool is_integer = true; |
| 206 | static _LIBCPP_CONSTEXPR const bool is_exact = true; |
| 207 | static _LIBCPP_CONSTEXPR const int radix = 2; |
| 208 | [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR type epsilon() _NOEXCEPT { return type(0); } |
| 209 | [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR type round_error() _NOEXCEPT { return type(0); } |
| 210 | |
| 211 | static _LIBCPP_CONSTEXPR const int min_exponent = 0; |
| 212 | static _LIBCPP_CONSTEXPR const int min_exponent10 = 0; |
| 213 | static _LIBCPP_CONSTEXPR const int max_exponent = 0; |
| 214 | static _LIBCPP_CONSTEXPR const int max_exponent10 = 0; |
| 215 | |
| 216 | static _LIBCPP_CONSTEXPR const bool has_infinity = false; |
| 217 | static _LIBCPP_CONSTEXPR const bool has_quiet_NaN = false; |
| 218 | static _LIBCPP_CONSTEXPR const bool has_signaling_NaN = false; |
| 219 | static _LIBCPP_DEPRECATED_IN_CXX23 _LIBCPP_CONSTEXPR const float_denorm_style has_denorm = denorm_absent; |
| 220 | static _LIBCPP_DEPRECATED_IN_CXX23 _LIBCPP_CONSTEXPR const bool has_denorm_loss = false; |
| 221 | [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR type infinity() _NOEXCEPT { return type(0); } |
| 222 | [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR type quiet_NaN() _NOEXCEPT { return type(0); } |
| 223 | [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR type signaling_NaN() _NOEXCEPT { return type(0); } |
| 224 | [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR type denorm_min() _NOEXCEPT { return type(0); } |
| 225 | |
| 226 | static _LIBCPP_CONSTEXPR const bool is_iec559 = false; |
| 227 | static _LIBCPP_CONSTEXPR const bool is_bounded = true; |
| 228 | static _LIBCPP_CONSTEXPR const bool is_modulo = !is_signed; |
| 229 | |
| 230 | # if defined(__i386__) || defined(__x86_64__) || defined(__wasm__) |
| 231 | static _LIBCPP_CONSTEXPR const bool traps = is_same<decltype(+_Tp(0)), _Tp>::value; |
| 232 | # else |
| 233 | static _LIBCPP_CONSTEXPR const bool traps = false; |
| 234 | # endif |
| 235 | static _LIBCPP_CONSTEXPR const bool tinyness_before = false; |
| 236 | static _LIBCPP_CONSTEXPR const float_round_style round_style = round_toward_zero; |
| 237 | }; |
| 238 | |
| 239 | template <> |
| 240 | class __libcpp_numeric_limits<bool, true> { |
| 241 | protected: |
| 242 | typedef bool type; |
| 243 | |
| 244 | static _LIBCPP_CONSTEXPR const bool is_specialized = true; |
| 245 | |
| 246 | static _LIBCPP_CONSTEXPR const bool is_signed = false; |
| 247 | static _LIBCPP_CONSTEXPR const int digits = 1; |
| 248 | static _LIBCPP_CONSTEXPR const int digits10 = 0; |
| 249 | static _LIBCPP_CONSTEXPR const int max_digits10 = 0; |
| 250 | [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR type min() _NOEXCEPT { return false; } |
| 251 | [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR type max() _NOEXCEPT { return true; } |
| 252 | [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR type lowest() _NOEXCEPT { return min(); } |
| 253 | |
| 254 | static _LIBCPP_CONSTEXPR const bool is_integer = true; |
| 255 | static _LIBCPP_CONSTEXPR const bool is_exact = true; |
| 256 | static _LIBCPP_CONSTEXPR const int radix = 2; |
| 257 | [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR type epsilon() _NOEXCEPT { return type(0); } |
| 258 | [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR type round_error() _NOEXCEPT { return type(0); } |
| 259 | |
| 260 | static _LIBCPP_CONSTEXPR const int min_exponent = 0; |
| 261 | static _LIBCPP_CONSTEXPR const int min_exponent10 = 0; |
| 262 | static _LIBCPP_CONSTEXPR const int max_exponent = 0; |
| 263 | static _LIBCPP_CONSTEXPR const int max_exponent10 = 0; |
| 264 | |
| 265 | static _LIBCPP_CONSTEXPR const bool has_infinity = false; |
| 266 | static _LIBCPP_CONSTEXPR const bool has_quiet_NaN = false; |
| 267 | static _LIBCPP_CONSTEXPR const bool has_signaling_NaN = false; |
| 268 | static _LIBCPP_DEPRECATED_IN_CXX23 _LIBCPP_CONSTEXPR const float_denorm_style has_denorm = denorm_absent; |
| 269 | static _LIBCPP_DEPRECATED_IN_CXX23 _LIBCPP_CONSTEXPR const bool has_denorm_loss = false; |
| 270 | [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR type infinity() _NOEXCEPT { return type(0); } |
| 271 | [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR type quiet_NaN() _NOEXCEPT { return type(0); } |
| 272 | [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR type signaling_NaN() _NOEXCEPT { return type(0); } |
| 273 | [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR type denorm_min() _NOEXCEPT { return type(0); } |
| 274 | |
| 275 | static _LIBCPP_CONSTEXPR const bool is_iec559 = false; |
| 276 | static _LIBCPP_CONSTEXPR const bool is_bounded = true; |
| 277 | static _LIBCPP_CONSTEXPR const bool is_modulo = false; |
| 278 | |
| 279 | static _LIBCPP_CONSTEXPR const bool traps = false; |
| 280 | static _LIBCPP_CONSTEXPR const bool tinyness_before = false; |
| 281 | static _LIBCPP_CONSTEXPR const float_round_style round_style = round_toward_zero; |
| 282 | }; |
| 283 | |
| 284 | template <> |
| 285 | class __libcpp_numeric_limits<float, true> { |
| 286 | protected: |
| 287 | typedef float type; |
| 288 | |
| 289 | static _LIBCPP_CONSTEXPR const bool is_specialized = true; |
| 290 | |
| 291 | static _LIBCPP_CONSTEXPR const bool is_signed = true; |
| 292 | static _LIBCPP_CONSTEXPR const int digits = __FLT_MANT_DIG__; |
| 293 | static _LIBCPP_CONSTEXPR const int digits10 = __FLT_DIG__; |
| 294 | static _LIBCPP_CONSTEXPR const int max_digits10 = 2 + (digits * 30103l) / 100000l; |
| 295 | [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR type min() _NOEXCEPT { return __FLT_MIN__; } |
| 296 | [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR type max() _NOEXCEPT { return __FLT_MAX__; } |
| 297 | [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR type lowest() _NOEXCEPT { return -max(); } |
| 298 | |
| 299 | static _LIBCPP_CONSTEXPR const bool is_integer = false; |
| 300 | static _LIBCPP_CONSTEXPR const bool is_exact = false; |
| 301 | static _LIBCPP_CONSTEXPR const int radix = __FLT_RADIX__; |
| 302 | [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR type epsilon() _NOEXCEPT { return __FLT_EPSILON__; } |
| 303 | [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR type round_error() _NOEXCEPT { return 0.5F; } |
| 304 | |
| 305 | static _LIBCPP_CONSTEXPR const int min_exponent = __FLT_MIN_EXP__; |
| 306 | static _LIBCPP_CONSTEXPR const int min_exponent10 = __FLT_MIN_10_EXP__; |
| 307 | static _LIBCPP_CONSTEXPR const int max_exponent = __FLT_MAX_EXP__; |
| 308 | static _LIBCPP_CONSTEXPR const int max_exponent10 = __FLT_MAX_10_EXP__; |
| 309 | |
| 310 | static _LIBCPP_CONSTEXPR const bool has_infinity = true; |
| 311 | static _LIBCPP_CONSTEXPR const bool has_quiet_NaN = true; |
| 312 | static _LIBCPP_CONSTEXPR const bool has_signaling_NaN = true; |
| 313 | static _LIBCPP_DEPRECATED_IN_CXX23 _LIBCPP_CONSTEXPR const float_denorm_style has_denorm = denorm_present; |
| 314 | static _LIBCPP_DEPRECATED_IN_CXX23 _LIBCPP_CONSTEXPR const bool has_denorm_loss = false; |
| 315 | [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR type infinity() _NOEXCEPT { |
| 316 | return __builtin_huge_valf(); |
| 317 | } |
| 318 | [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR type quiet_NaN() _NOEXCEPT { |
| 319 | return __builtin_nanf("" ); |
| 320 | } |
| 321 | [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR type signaling_NaN() _NOEXCEPT { |
| 322 | return __builtin_nansf("" ); |
| 323 | } |
| 324 | [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR type denorm_min() _NOEXCEPT { |
| 325 | return __FLT_DENORM_MIN__; |
| 326 | } |
| 327 | |
| 328 | static _LIBCPP_CONSTEXPR const bool is_iec559 = true; |
| 329 | static _LIBCPP_CONSTEXPR const bool is_bounded = true; |
| 330 | static _LIBCPP_CONSTEXPR const bool is_modulo = false; |
| 331 | |
| 332 | static _LIBCPP_CONSTEXPR const bool traps = false; |
| 333 | # if (defined(__arm__) || defined(__aarch64__)) |
| 334 | static _LIBCPP_CONSTEXPR const bool tinyness_before = true; |
| 335 | # else |
| 336 | static _LIBCPP_CONSTEXPR const bool tinyness_before = false; |
| 337 | # endif |
| 338 | static _LIBCPP_CONSTEXPR const float_round_style round_style = round_to_nearest; |
| 339 | }; |
| 340 | |
| 341 | template <> |
| 342 | class __libcpp_numeric_limits<double, true> { |
| 343 | protected: |
| 344 | typedef double type; |
| 345 | |
| 346 | static _LIBCPP_CONSTEXPR const bool is_specialized = true; |
| 347 | |
| 348 | static _LIBCPP_CONSTEXPR const bool is_signed = true; |
| 349 | static _LIBCPP_CONSTEXPR const int digits = __DBL_MANT_DIG__; |
| 350 | static _LIBCPP_CONSTEXPR const int digits10 = __DBL_DIG__; |
| 351 | static _LIBCPP_CONSTEXPR const int max_digits10 = 2 + (digits * 30103l) / 100000l; |
| 352 | [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR type min() _NOEXCEPT { return __DBL_MIN__; } |
| 353 | [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR type max() _NOEXCEPT { return __DBL_MAX__; } |
| 354 | [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR type lowest() _NOEXCEPT { return -max(); } |
| 355 | |
| 356 | static _LIBCPP_CONSTEXPR const bool is_integer = false; |
| 357 | static _LIBCPP_CONSTEXPR const bool is_exact = false; |
| 358 | static _LIBCPP_CONSTEXPR const int radix = __FLT_RADIX__; |
| 359 | [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR type epsilon() _NOEXCEPT { return __DBL_EPSILON__; } |
| 360 | [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR type round_error() _NOEXCEPT { return 0.5; } |
| 361 | |
| 362 | static _LIBCPP_CONSTEXPR const int min_exponent = __DBL_MIN_EXP__; |
| 363 | static _LIBCPP_CONSTEXPR const int min_exponent10 = __DBL_MIN_10_EXP__; |
| 364 | static _LIBCPP_CONSTEXPR const int max_exponent = __DBL_MAX_EXP__; |
| 365 | static _LIBCPP_CONSTEXPR const int max_exponent10 = __DBL_MAX_10_EXP__; |
| 366 | |
| 367 | static _LIBCPP_CONSTEXPR const bool has_infinity = true; |
| 368 | static _LIBCPP_CONSTEXPR const bool has_quiet_NaN = true; |
| 369 | static _LIBCPP_CONSTEXPR const bool has_signaling_NaN = true; |
| 370 | static _LIBCPP_DEPRECATED_IN_CXX23 _LIBCPP_CONSTEXPR const float_denorm_style has_denorm = denorm_present; |
| 371 | static _LIBCPP_DEPRECATED_IN_CXX23 _LIBCPP_CONSTEXPR const bool has_denorm_loss = false; |
| 372 | [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR type infinity() _NOEXCEPT { |
| 373 | return __builtin_huge_val(); |
| 374 | } |
| 375 | [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR type quiet_NaN() _NOEXCEPT { |
| 376 | return __builtin_nan("" ); |
| 377 | } |
| 378 | [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR type signaling_NaN() _NOEXCEPT { |
| 379 | return __builtin_nans("" ); |
| 380 | } |
| 381 | [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR type denorm_min() _NOEXCEPT { |
| 382 | return __DBL_DENORM_MIN__; |
| 383 | } |
| 384 | |
| 385 | static _LIBCPP_CONSTEXPR const bool is_iec559 = true; |
| 386 | static _LIBCPP_CONSTEXPR const bool is_bounded = true; |
| 387 | static _LIBCPP_CONSTEXPR const bool is_modulo = false; |
| 388 | |
| 389 | static _LIBCPP_CONSTEXPR const bool traps = false; |
| 390 | # if (defined(__arm__) || defined(__aarch64__)) |
| 391 | static _LIBCPP_CONSTEXPR const bool tinyness_before = true; |
| 392 | # else |
| 393 | static _LIBCPP_CONSTEXPR const bool tinyness_before = false; |
| 394 | # endif |
| 395 | static _LIBCPP_CONSTEXPR const float_round_style round_style = round_to_nearest; |
| 396 | }; |
| 397 | |
| 398 | template <> |
| 399 | class __libcpp_numeric_limits<long double, true> { |
| 400 | protected: |
| 401 | typedef long double type; |
| 402 | |
| 403 | static _LIBCPP_CONSTEXPR const bool is_specialized = true; |
| 404 | |
| 405 | static _LIBCPP_CONSTEXPR const bool is_signed = true; |
| 406 | static _LIBCPP_CONSTEXPR const int digits = __LDBL_MANT_DIG__; |
| 407 | static _LIBCPP_CONSTEXPR const int digits10 = __LDBL_DIG__; |
| 408 | static _LIBCPP_CONSTEXPR const int max_digits10 = 2 + (digits * 30103l) / 100000l; |
| 409 | [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR type min() _NOEXCEPT { return __LDBL_MIN__; } |
| 410 | [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR type max() _NOEXCEPT { return __LDBL_MAX__; } |
| 411 | [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR type lowest() _NOEXCEPT { return -max(); } |
| 412 | |
| 413 | static _LIBCPP_CONSTEXPR const bool is_integer = false; |
| 414 | static _LIBCPP_CONSTEXPR const bool is_exact = false; |
| 415 | static _LIBCPP_CONSTEXPR const int radix = __FLT_RADIX__; |
| 416 | [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR type epsilon() _NOEXCEPT { return __LDBL_EPSILON__; } |
| 417 | [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR type round_error() _NOEXCEPT { return 0.5L; } |
| 418 | |
| 419 | static _LIBCPP_CONSTEXPR const int min_exponent = __LDBL_MIN_EXP__; |
| 420 | static _LIBCPP_CONSTEXPR const int min_exponent10 = __LDBL_MIN_10_EXP__; |
| 421 | static _LIBCPP_CONSTEXPR const int max_exponent = __LDBL_MAX_EXP__; |
| 422 | static _LIBCPP_CONSTEXPR const int max_exponent10 = __LDBL_MAX_10_EXP__; |
| 423 | |
| 424 | static _LIBCPP_CONSTEXPR const bool has_infinity = true; |
| 425 | static _LIBCPP_CONSTEXPR const bool has_quiet_NaN = true; |
| 426 | static _LIBCPP_CONSTEXPR const bool has_signaling_NaN = true; |
| 427 | static _LIBCPP_DEPRECATED_IN_CXX23 _LIBCPP_CONSTEXPR const float_denorm_style has_denorm = denorm_present; |
| 428 | static _LIBCPP_DEPRECATED_IN_CXX23 _LIBCPP_CONSTEXPR const bool has_denorm_loss = false; |
| 429 | [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR type infinity() _NOEXCEPT { |
| 430 | return __builtin_huge_vall(); |
| 431 | } |
| 432 | [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR type quiet_NaN() _NOEXCEPT { |
| 433 | return __builtin_nanl("" ); |
| 434 | } |
| 435 | [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR type signaling_NaN() _NOEXCEPT { |
| 436 | return __builtin_nansl("" ); |
| 437 | } |
| 438 | [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR type denorm_min() _NOEXCEPT { |
| 439 | return __LDBL_DENORM_MIN__; |
| 440 | } |
| 441 | |
| 442 | # if defined(__powerpc__) && defined(__LONG_DOUBLE_IBM128__) |
| 443 | static _LIBCPP_CONSTEXPR const bool is_iec559 = false; |
| 444 | # else |
| 445 | static _LIBCPP_CONSTEXPR const bool is_iec559 = true; |
| 446 | # endif |
| 447 | static _LIBCPP_CONSTEXPR const bool is_bounded = true; |
| 448 | static _LIBCPP_CONSTEXPR const bool is_modulo = false; |
| 449 | |
| 450 | static _LIBCPP_CONSTEXPR const bool traps = false; |
| 451 | # if (defined(__arm__) || defined(__aarch64__)) |
| 452 | static _LIBCPP_CONSTEXPR const bool tinyness_before = true; |
| 453 | # else |
| 454 | static _LIBCPP_CONSTEXPR const bool tinyness_before = false; |
| 455 | # endif |
| 456 | static _LIBCPP_CONSTEXPR const float_round_style round_style = round_to_nearest; |
| 457 | }; |
| 458 | |
| 459 | template <class _Tp> |
| 460 | class numeric_limits : private __libcpp_numeric_limits<_Tp> { |
| 461 | typedef __libcpp_numeric_limits<_Tp> __base; |
| 462 | typedef typename __base::type type; |
| 463 | |
| 464 | public: |
| 465 | static inline _LIBCPP_CONSTEXPR const bool is_specialized = __base::is_specialized; |
| 466 | [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR type min() _NOEXCEPT { return __base::min(); } |
| 467 | [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR type max() _NOEXCEPT { return __base::max(); } |
| 468 | [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR type lowest() _NOEXCEPT { return __base::lowest(); } |
| 469 | |
| 470 | static inline _LIBCPP_CONSTEXPR const int digits = __base::digits; |
| 471 | static inline _LIBCPP_CONSTEXPR const int digits10 = __base::digits10; |
| 472 | static inline _LIBCPP_CONSTEXPR const int max_digits10 = __base::max_digits10; |
| 473 | static inline _LIBCPP_CONSTEXPR const bool is_signed = __base::is_signed; |
| 474 | static inline _LIBCPP_CONSTEXPR const bool is_integer = __base::is_integer; |
| 475 | static inline _LIBCPP_CONSTEXPR const bool is_exact = __base::is_exact; |
| 476 | static inline _LIBCPP_CONSTEXPR const int radix = __base::radix; |
| 477 | [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR type epsilon() _NOEXCEPT { |
| 478 | return __base::epsilon(); |
| 479 | } |
| 480 | [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR type round_error() _NOEXCEPT { |
| 481 | return __base::round_error(); |
| 482 | } |
| 483 | |
| 484 | static inline _LIBCPP_CONSTEXPR const int min_exponent = __base::min_exponent; |
| 485 | static inline _LIBCPP_CONSTEXPR const int min_exponent10 = __base::min_exponent10; |
| 486 | static inline _LIBCPP_CONSTEXPR const int max_exponent = __base::max_exponent; |
| 487 | static inline _LIBCPP_CONSTEXPR const int max_exponent10 = __base::max_exponent10; |
| 488 | |
| 489 | static inline _LIBCPP_CONSTEXPR const bool has_infinity = __base::has_infinity; |
| 490 | static inline _LIBCPP_CONSTEXPR const bool has_quiet_NaN = __base::has_quiet_NaN; |
| 491 | static inline _LIBCPP_CONSTEXPR const bool has_signaling_NaN = __base::has_signaling_NaN; |
| 492 | _LIBCPP_SUPPRESS_DEPRECATED_PUSH |
| 493 | static inline _LIBCPP_DEPRECATED_IN_CXX23 _LIBCPP_CONSTEXPR const float_denorm_style has_denorm = __base::has_denorm; |
| 494 | static inline _LIBCPP_DEPRECATED_IN_CXX23 _LIBCPP_CONSTEXPR const bool has_denorm_loss = __base::has_denorm_loss; |
| 495 | _LIBCPP_SUPPRESS_DEPRECATED_POP |
| 496 | [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR type infinity() _NOEXCEPT { |
| 497 | return __base::infinity(); |
| 498 | } |
| 499 | [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR type quiet_NaN() _NOEXCEPT { |
| 500 | return __base::quiet_NaN(); |
| 501 | } |
| 502 | [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR type signaling_NaN() _NOEXCEPT { |
| 503 | return __base::signaling_NaN(); |
| 504 | } |
| 505 | [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR type denorm_min() _NOEXCEPT { |
| 506 | return __base::denorm_min(); |
| 507 | } |
| 508 | |
| 509 | static inline _LIBCPP_CONSTEXPR const bool is_iec559 = __base::is_iec559; |
| 510 | static inline _LIBCPP_CONSTEXPR const bool is_bounded = __base::is_bounded; |
| 511 | static inline _LIBCPP_CONSTEXPR const bool is_modulo = __base::is_modulo; |
| 512 | |
| 513 | static inline _LIBCPP_CONSTEXPR const bool traps = __base::traps; |
| 514 | static inline _LIBCPP_CONSTEXPR const bool tinyness_before = __base::tinyness_before; |
| 515 | static inline _LIBCPP_CONSTEXPR const float_round_style round_style = __base::round_style; |
| 516 | }; |
| 517 | |
| 518 | template <class _Tp> |
| 519 | class numeric_limits<const _Tp> : public numeric_limits<_Tp> {}; |
| 520 | |
| 521 | template <class _Tp> |
| 522 | class numeric_limits<volatile _Tp> : public numeric_limits<_Tp> {}; |
| 523 | |
| 524 | template <class _Tp> |
| 525 | class numeric_limits<const volatile _Tp> : public numeric_limits<_Tp> {}; |
| 526 | |
| 527 | _LIBCPP_END_NAMESPACE_STD |
| 528 | |
| 529 | _LIBCPP_POP_MACROS |
| 530 | |
| 531 | # if defined(_LIBCPP_KEEP_TRANSITIVE_INCLUDES_LLVM23) && _LIBCPP_STD_VER <= 20 |
| 532 | # include <type_traits> |
| 533 | # endif |
| 534 | #endif // __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS) |
| 535 | |
| 536 | #endif // _LIBCPP_LIMITS |
| 537 | |