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_signed.h> |
111 | |
112 | # if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) |
113 | # pragma GCC system_header |
114 | # endif |
115 | |
116 | _LIBCPP_PUSH_MACROS |
117 | # include <__undef_macros> |
118 | # include <version> |
119 | |
120 | _LIBCPP_BEGIN_NAMESPACE_STD |
121 | |
122 | enum float_round_style { |
123 | round_indeterminate = -1, |
124 | round_toward_zero = 0, |
125 | round_to_nearest = 1, |
126 | round_toward_infinity = 2, |
127 | round_toward_neg_infinity = 3 |
128 | }; |
129 | |
130 | enum _LIBCPP_DEPRECATED_IN_CXX23 float_denorm_style { |
131 | denorm_indeterminate = -1, |
132 | denorm_absent = 0, |
133 | denorm_present = 1 |
134 | }; |
135 | |
136 | template <class _Tp, bool = is_arithmetic<_Tp>::value> |
137 | class __libcpp_numeric_limits { |
138 | protected: |
139 | typedef _Tp type; |
140 | |
141 | static _LIBCPP_CONSTEXPR const bool is_specialized = false; |
142 | [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR type min() _NOEXCEPT { return type(); } |
143 | [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR type max() _NOEXCEPT { return type(); } |
144 | [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR type lowest() _NOEXCEPT { return type(); } |
145 | |
146 | static _LIBCPP_CONSTEXPR const int digits = 0; |
147 | static _LIBCPP_CONSTEXPR const int digits10 = 0; |
148 | static _LIBCPP_CONSTEXPR const int max_digits10 = 0; |
149 | static _LIBCPP_CONSTEXPR const bool is_signed = false; |
150 | static _LIBCPP_CONSTEXPR const bool is_integer = false; |
151 | static _LIBCPP_CONSTEXPR const bool is_exact = false; |
152 | static _LIBCPP_CONSTEXPR const int radix = 0; |
153 | [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR type epsilon() _NOEXCEPT { return type(); } |
154 | [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR type round_error() _NOEXCEPT { return type(); } |
155 | |
156 | static _LIBCPP_CONSTEXPR const int min_exponent = 0; |
157 | static _LIBCPP_CONSTEXPR const int min_exponent10 = 0; |
158 | static _LIBCPP_CONSTEXPR const int max_exponent = 0; |
159 | static _LIBCPP_CONSTEXPR const int max_exponent10 = 0; |
160 | |
161 | static _LIBCPP_CONSTEXPR const bool has_infinity = false; |
162 | static _LIBCPP_CONSTEXPR const bool has_quiet_NaN = false; |
163 | static _LIBCPP_CONSTEXPR const bool has_signaling_NaN = false; |
164 | static _LIBCPP_DEPRECATED_IN_CXX23 _LIBCPP_CONSTEXPR const float_denorm_style has_denorm = denorm_absent; |
165 | static _LIBCPP_DEPRECATED_IN_CXX23 _LIBCPP_CONSTEXPR const bool has_denorm_loss = false; |
166 | [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR type infinity() _NOEXCEPT { return type(); } |
167 | [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR type quiet_NaN() _NOEXCEPT { return type(); } |
168 | [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR type signaling_NaN() _NOEXCEPT { return type(); } |
169 | [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR type denorm_min() _NOEXCEPT { return type(); } |
170 | |
171 | static _LIBCPP_CONSTEXPR const bool is_iec559 = false; |
172 | static _LIBCPP_CONSTEXPR const bool is_bounded = false; |
173 | static _LIBCPP_CONSTEXPR const bool is_modulo = false; |
174 | |
175 | static _LIBCPP_CONSTEXPR const bool traps = false; |
176 | static _LIBCPP_CONSTEXPR const bool tinyness_before = false; |
177 | static _LIBCPP_CONSTEXPR const float_round_style round_style = round_toward_zero; |
178 | }; |
179 | |
180 | template <class _Tp> |
181 | class __libcpp_numeric_limits<_Tp, true> { |
182 | protected: |
183 | typedef _Tp type; |
184 | |
185 | static _LIBCPP_CONSTEXPR const bool is_specialized = true; |
186 | |
187 | static _LIBCPP_CONSTEXPR const bool is_signed = type(-1) < type(0); |
188 | static _LIBCPP_CONSTEXPR const int digits = static_cast<int>(sizeof(type) * __CHAR_BIT__ - is_signed); |
189 | static _LIBCPP_CONSTEXPR const int digits10 = digits * 3 / 10; |
190 | static _LIBCPP_CONSTEXPR const int max_digits10 = 0; |
191 | static _LIBCPP_CONSTEXPR const type __min = is_signed ? _Tp(_Tp(1) << digits) : 0; |
192 | static _LIBCPP_CONSTEXPR const type __max = is_signed ? type(type(~0) ^ __min) : type(~0); |
193 | [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR type min() _NOEXCEPT { return __min; } |
194 | [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR type max() _NOEXCEPT { return __max; } |
195 | [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR type lowest() _NOEXCEPT { return min(); } |
196 | |
197 | static _LIBCPP_CONSTEXPR const bool is_integer = true; |
198 | static _LIBCPP_CONSTEXPR const bool is_exact = true; |
199 | static _LIBCPP_CONSTEXPR const int radix = 2; |
200 | [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR type epsilon() _NOEXCEPT { return type(0); } |
201 | [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR type round_error() _NOEXCEPT { return type(0); } |
202 | |
203 | static _LIBCPP_CONSTEXPR const int min_exponent = 0; |
204 | static _LIBCPP_CONSTEXPR const int min_exponent10 = 0; |
205 | static _LIBCPP_CONSTEXPR const int max_exponent = 0; |
206 | static _LIBCPP_CONSTEXPR const int max_exponent10 = 0; |
207 | |
208 | static _LIBCPP_CONSTEXPR const bool has_infinity = false; |
209 | static _LIBCPP_CONSTEXPR const bool has_quiet_NaN = false; |
210 | static _LIBCPP_CONSTEXPR const bool has_signaling_NaN = false; |
211 | static _LIBCPP_DEPRECATED_IN_CXX23 _LIBCPP_CONSTEXPR const float_denorm_style has_denorm = denorm_absent; |
212 | static _LIBCPP_DEPRECATED_IN_CXX23 _LIBCPP_CONSTEXPR const bool has_denorm_loss = false; |
213 | [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR type infinity() _NOEXCEPT { return type(0); } |
214 | [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR type quiet_NaN() _NOEXCEPT { return type(0); } |
215 | [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR type signaling_NaN() _NOEXCEPT { return type(0); } |
216 | [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR type denorm_min() _NOEXCEPT { return type(0); } |
217 | |
218 | static _LIBCPP_CONSTEXPR const bool is_iec559 = false; |
219 | static _LIBCPP_CONSTEXPR const bool is_bounded = true; |
220 | static _LIBCPP_CONSTEXPR const bool is_modulo = !std::is_signed<_Tp>::value; |
221 | |
222 | # if defined(__i386__) || defined(__x86_64__) || defined(__pnacl__) || defined(__wasm__) |
223 | static _LIBCPP_CONSTEXPR const bool traps = true; |
224 | # else |
225 | static _LIBCPP_CONSTEXPR const bool traps = false; |
226 | # endif |
227 | static _LIBCPP_CONSTEXPR const bool tinyness_before = false; |
228 | static _LIBCPP_CONSTEXPR const float_round_style round_style = round_toward_zero; |
229 | }; |
230 | |
231 | template <> |
232 | class __libcpp_numeric_limits<bool, true> { |
233 | protected: |
234 | typedef bool type; |
235 | |
236 | static _LIBCPP_CONSTEXPR const bool is_specialized = true; |
237 | |
238 | static _LIBCPP_CONSTEXPR const bool is_signed = false; |
239 | static _LIBCPP_CONSTEXPR const int digits = 1; |
240 | static _LIBCPP_CONSTEXPR const int digits10 = 0; |
241 | static _LIBCPP_CONSTEXPR const int max_digits10 = 0; |
242 | [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR type min() _NOEXCEPT { return false; } |
243 | [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR type max() _NOEXCEPT { return true; } |
244 | [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR type lowest() _NOEXCEPT { return min(); } |
245 | |
246 | static _LIBCPP_CONSTEXPR const bool is_integer = true; |
247 | static _LIBCPP_CONSTEXPR const bool is_exact = true; |
248 | static _LIBCPP_CONSTEXPR const int radix = 2; |
249 | [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR type epsilon() _NOEXCEPT { return type(0); } |
250 | [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR type round_error() _NOEXCEPT { return type(0); } |
251 | |
252 | static _LIBCPP_CONSTEXPR const int min_exponent = 0; |
253 | static _LIBCPP_CONSTEXPR const int min_exponent10 = 0; |
254 | static _LIBCPP_CONSTEXPR const int max_exponent = 0; |
255 | static _LIBCPP_CONSTEXPR const int max_exponent10 = 0; |
256 | |
257 | static _LIBCPP_CONSTEXPR const bool has_infinity = false; |
258 | static _LIBCPP_CONSTEXPR const bool has_quiet_NaN = false; |
259 | static _LIBCPP_CONSTEXPR const bool has_signaling_NaN = false; |
260 | static _LIBCPP_DEPRECATED_IN_CXX23 _LIBCPP_CONSTEXPR const float_denorm_style has_denorm = denorm_absent; |
261 | static _LIBCPP_DEPRECATED_IN_CXX23 _LIBCPP_CONSTEXPR const bool has_denorm_loss = false; |
262 | [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR type infinity() _NOEXCEPT { return type(0); } |
263 | [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR type quiet_NaN() _NOEXCEPT { return type(0); } |
264 | [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR type signaling_NaN() _NOEXCEPT { return type(0); } |
265 | [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR type denorm_min() _NOEXCEPT { return type(0); } |
266 | |
267 | static _LIBCPP_CONSTEXPR const bool is_iec559 = false; |
268 | static _LIBCPP_CONSTEXPR const bool is_bounded = true; |
269 | static _LIBCPP_CONSTEXPR const bool is_modulo = false; |
270 | |
271 | static _LIBCPP_CONSTEXPR const bool traps = false; |
272 | static _LIBCPP_CONSTEXPR const bool tinyness_before = false; |
273 | static _LIBCPP_CONSTEXPR const float_round_style round_style = round_toward_zero; |
274 | }; |
275 | |
276 | template <> |
277 | class __libcpp_numeric_limits<float, true> { |
278 | protected: |
279 | typedef float type; |
280 | |
281 | static _LIBCPP_CONSTEXPR const bool is_specialized = true; |
282 | |
283 | static _LIBCPP_CONSTEXPR const bool is_signed = true; |
284 | static _LIBCPP_CONSTEXPR const int digits = __FLT_MANT_DIG__; |
285 | static _LIBCPP_CONSTEXPR const int digits10 = __FLT_DIG__; |
286 | static _LIBCPP_CONSTEXPR const int max_digits10 = 2 + (digits * 30103l) / 100000l; |
287 | [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR type min() _NOEXCEPT { return __FLT_MIN__; } |
288 | [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR type max() _NOEXCEPT { return __FLT_MAX__; } |
289 | [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR type lowest() _NOEXCEPT { return -max(); } |
290 | |
291 | static _LIBCPP_CONSTEXPR const bool is_integer = false; |
292 | static _LIBCPP_CONSTEXPR const bool is_exact = false; |
293 | static _LIBCPP_CONSTEXPR const int radix = __FLT_RADIX__; |
294 | [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR type epsilon() _NOEXCEPT { return __FLT_EPSILON__; } |
295 | [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR type round_error() _NOEXCEPT { return 0.5F; } |
296 | |
297 | static _LIBCPP_CONSTEXPR const int min_exponent = __FLT_MIN_EXP__; |
298 | static _LIBCPP_CONSTEXPR const int min_exponent10 = __FLT_MIN_10_EXP__; |
299 | static _LIBCPP_CONSTEXPR const int max_exponent = __FLT_MAX_EXP__; |
300 | static _LIBCPP_CONSTEXPR const int max_exponent10 = __FLT_MAX_10_EXP__; |
301 | |
302 | static _LIBCPP_CONSTEXPR const bool has_infinity = true; |
303 | static _LIBCPP_CONSTEXPR const bool has_quiet_NaN = true; |
304 | static _LIBCPP_CONSTEXPR const bool has_signaling_NaN = true; |
305 | static _LIBCPP_DEPRECATED_IN_CXX23 _LIBCPP_CONSTEXPR const float_denorm_style has_denorm = denorm_present; |
306 | static _LIBCPP_DEPRECATED_IN_CXX23 _LIBCPP_CONSTEXPR const bool has_denorm_loss = false; |
307 | [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR type infinity() _NOEXCEPT { |
308 | return __builtin_huge_valf(); |
309 | } |
310 | [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR type quiet_NaN() _NOEXCEPT { |
311 | return __builtin_nanf("" ); |
312 | } |
313 | [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR type signaling_NaN() _NOEXCEPT { |
314 | return __builtin_nansf("" ); |
315 | } |
316 | [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR type denorm_min() _NOEXCEPT { |
317 | return __FLT_DENORM_MIN__; |
318 | } |
319 | |
320 | static _LIBCPP_CONSTEXPR const bool is_iec559 = true; |
321 | static _LIBCPP_CONSTEXPR const bool is_bounded = true; |
322 | static _LIBCPP_CONSTEXPR const bool is_modulo = false; |
323 | |
324 | static _LIBCPP_CONSTEXPR const bool traps = false; |
325 | # if (defined(__arm__) || defined(__aarch64__)) |
326 | static _LIBCPP_CONSTEXPR const bool tinyness_before = true; |
327 | # else |
328 | static _LIBCPP_CONSTEXPR const bool tinyness_before = false; |
329 | # endif |
330 | static _LIBCPP_CONSTEXPR const float_round_style round_style = round_to_nearest; |
331 | }; |
332 | |
333 | template <> |
334 | class __libcpp_numeric_limits<double, true> { |
335 | protected: |
336 | typedef double type; |
337 | |
338 | static _LIBCPP_CONSTEXPR const bool is_specialized = true; |
339 | |
340 | static _LIBCPP_CONSTEXPR const bool is_signed = true; |
341 | static _LIBCPP_CONSTEXPR const int digits = __DBL_MANT_DIG__; |
342 | static _LIBCPP_CONSTEXPR const int digits10 = __DBL_DIG__; |
343 | static _LIBCPP_CONSTEXPR const int max_digits10 = 2 + (digits * 30103l) / 100000l; |
344 | [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR type min() _NOEXCEPT { return __DBL_MIN__; } |
345 | [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR type max() _NOEXCEPT { return __DBL_MAX__; } |
346 | [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR type lowest() _NOEXCEPT { return -max(); } |
347 | |
348 | static _LIBCPP_CONSTEXPR const bool is_integer = false; |
349 | static _LIBCPP_CONSTEXPR const bool is_exact = false; |
350 | static _LIBCPP_CONSTEXPR const int radix = __FLT_RADIX__; |
351 | [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR type epsilon() _NOEXCEPT { return __DBL_EPSILON__; } |
352 | [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR type round_error() _NOEXCEPT { return 0.5; } |
353 | |
354 | static _LIBCPP_CONSTEXPR const int min_exponent = __DBL_MIN_EXP__; |
355 | static _LIBCPP_CONSTEXPR const int min_exponent10 = __DBL_MIN_10_EXP__; |
356 | static _LIBCPP_CONSTEXPR const int max_exponent = __DBL_MAX_EXP__; |
357 | static _LIBCPP_CONSTEXPR const int max_exponent10 = __DBL_MAX_10_EXP__; |
358 | |
359 | static _LIBCPP_CONSTEXPR const bool has_infinity = true; |
360 | static _LIBCPP_CONSTEXPR const bool has_quiet_NaN = true; |
361 | static _LIBCPP_CONSTEXPR const bool has_signaling_NaN = true; |
362 | static _LIBCPP_DEPRECATED_IN_CXX23 _LIBCPP_CONSTEXPR const float_denorm_style has_denorm = denorm_present; |
363 | static _LIBCPP_DEPRECATED_IN_CXX23 _LIBCPP_CONSTEXPR const bool has_denorm_loss = false; |
364 | [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR type infinity() _NOEXCEPT { |
365 | return __builtin_huge_val(); |
366 | } |
367 | [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR type quiet_NaN() _NOEXCEPT { |
368 | return __builtin_nan("" ); |
369 | } |
370 | [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR type signaling_NaN() _NOEXCEPT { |
371 | return __builtin_nans("" ); |
372 | } |
373 | [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR type denorm_min() _NOEXCEPT { |
374 | return __DBL_DENORM_MIN__; |
375 | } |
376 | |
377 | static _LIBCPP_CONSTEXPR const bool is_iec559 = true; |
378 | static _LIBCPP_CONSTEXPR const bool is_bounded = true; |
379 | static _LIBCPP_CONSTEXPR const bool is_modulo = false; |
380 | |
381 | static _LIBCPP_CONSTEXPR const bool traps = false; |
382 | # if (defined(__arm__) || defined(__aarch64__)) |
383 | static _LIBCPP_CONSTEXPR const bool tinyness_before = true; |
384 | # else |
385 | static _LIBCPP_CONSTEXPR const bool tinyness_before = false; |
386 | # endif |
387 | static _LIBCPP_CONSTEXPR const float_round_style round_style = round_to_nearest; |
388 | }; |
389 | |
390 | template <> |
391 | class __libcpp_numeric_limits<long double, true> { |
392 | protected: |
393 | typedef long double type; |
394 | |
395 | static _LIBCPP_CONSTEXPR const bool is_specialized = true; |
396 | |
397 | static _LIBCPP_CONSTEXPR const bool is_signed = true; |
398 | static _LIBCPP_CONSTEXPR const int digits = __LDBL_MANT_DIG__; |
399 | static _LIBCPP_CONSTEXPR const int digits10 = __LDBL_DIG__; |
400 | static _LIBCPP_CONSTEXPR const int max_digits10 = 2 + (digits * 30103l) / 100000l; |
401 | [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR type min() _NOEXCEPT { return __LDBL_MIN__; } |
402 | [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR type max() _NOEXCEPT { return __LDBL_MAX__; } |
403 | [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR type lowest() _NOEXCEPT { return -max(); } |
404 | |
405 | static _LIBCPP_CONSTEXPR const bool is_integer = false; |
406 | static _LIBCPP_CONSTEXPR const bool is_exact = false; |
407 | static _LIBCPP_CONSTEXPR const int radix = __FLT_RADIX__; |
408 | [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR type epsilon() _NOEXCEPT { return __LDBL_EPSILON__; } |
409 | [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR type round_error() _NOEXCEPT { return 0.5L; } |
410 | |
411 | static _LIBCPP_CONSTEXPR const int min_exponent = __LDBL_MIN_EXP__; |
412 | static _LIBCPP_CONSTEXPR const int min_exponent10 = __LDBL_MIN_10_EXP__; |
413 | static _LIBCPP_CONSTEXPR const int max_exponent = __LDBL_MAX_EXP__; |
414 | static _LIBCPP_CONSTEXPR const int max_exponent10 = __LDBL_MAX_10_EXP__; |
415 | |
416 | static _LIBCPP_CONSTEXPR const bool has_infinity = true; |
417 | static _LIBCPP_CONSTEXPR const bool has_quiet_NaN = true; |
418 | static _LIBCPP_CONSTEXPR const bool has_signaling_NaN = true; |
419 | static _LIBCPP_DEPRECATED_IN_CXX23 _LIBCPP_CONSTEXPR const float_denorm_style has_denorm = denorm_present; |
420 | static _LIBCPP_DEPRECATED_IN_CXX23 _LIBCPP_CONSTEXPR const bool has_denorm_loss = false; |
421 | [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR type infinity() _NOEXCEPT { |
422 | return __builtin_huge_vall(); |
423 | } |
424 | [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR type quiet_NaN() _NOEXCEPT { |
425 | return __builtin_nanl("" ); |
426 | } |
427 | [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR type signaling_NaN() _NOEXCEPT { |
428 | return __builtin_nansl("" ); |
429 | } |
430 | [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR type denorm_min() _NOEXCEPT { |
431 | return __LDBL_DENORM_MIN__; |
432 | } |
433 | |
434 | # if defined(__powerpc__) && defined(__LONG_DOUBLE_IBM128__) |
435 | static _LIBCPP_CONSTEXPR const bool is_iec559 = false; |
436 | # else |
437 | static _LIBCPP_CONSTEXPR const bool is_iec559 = true; |
438 | # endif |
439 | static _LIBCPP_CONSTEXPR const bool is_bounded = true; |
440 | static _LIBCPP_CONSTEXPR const bool is_modulo = false; |
441 | |
442 | static _LIBCPP_CONSTEXPR const bool traps = false; |
443 | # if (defined(__arm__) || defined(__aarch64__)) |
444 | static _LIBCPP_CONSTEXPR const bool tinyness_before = true; |
445 | # else |
446 | static _LIBCPP_CONSTEXPR const bool tinyness_before = false; |
447 | # endif |
448 | static _LIBCPP_CONSTEXPR const float_round_style round_style = round_to_nearest; |
449 | }; |
450 | |
451 | template <class _Tp> |
452 | class numeric_limits : private __libcpp_numeric_limits<_Tp> { |
453 | typedef __libcpp_numeric_limits<_Tp> __base; |
454 | typedef typename __base::type type; |
455 | |
456 | public: |
457 | static inline _LIBCPP_CONSTEXPR const bool is_specialized = __base::is_specialized; |
458 | [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR type min() _NOEXCEPT { return __base::min(); } |
459 | [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR type max() _NOEXCEPT { return __base::max(); } |
460 | [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR type lowest() _NOEXCEPT { return __base::lowest(); } |
461 | |
462 | static inline _LIBCPP_CONSTEXPR const int digits = __base::digits; |
463 | static inline _LIBCPP_CONSTEXPR const int digits10 = __base::digits10; |
464 | static inline _LIBCPP_CONSTEXPR const int max_digits10 = __base::max_digits10; |
465 | static inline _LIBCPP_CONSTEXPR const bool is_signed = __base::is_signed; |
466 | static inline _LIBCPP_CONSTEXPR const bool is_integer = __base::is_integer; |
467 | static inline _LIBCPP_CONSTEXPR const bool is_exact = __base::is_exact; |
468 | static inline _LIBCPP_CONSTEXPR const int radix = __base::radix; |
469 | [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR type epsilon() _NOEXCEPT { |
470 | return __base::epsilon(); |
471 | } |
472 | [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR type round_error() _NOEXCEPT { |
473 | return __base::round_error(); |
474 | } |
475 | |
476 | static inline _LIBCPP_CONSTEXPR const int min_exponent = __base::min_exponent; |
477 | static inline _LIBCPP_CONSTEXPR const int min_exponent10 = __base::min_exponent10; |
478 | static inline _LIBCPP_CONSTEXPR const int max_exponent = __base::max_exponent; |
479 | static inline _LIBCPP_CONSTEXPR const int max_exponent10 = __base::max_exponent10; |
480 | |
481 | static inline _LIBCPP_CONSTEXPR const bool has_infinity = __base::has_infinity; |
482 | static inline _LIBCPP_CONSTEXPR const bool has_quiet_NaN = __base::has_quiet_NaN; |
483 | static inline _LIBCPP_CONSTEXPR const bool has_signaling_NaN = __base::has_signaling_NaN; |
484 | _LIBCPP_SUPPRESS_DEPRECATED_PUSH |
485 | static inline _LIBCPP_DEPRECATED_IN_CXX23 _LIBCPP_CONSTEXPR const float_denorm_style has_denorm = __base::has_denorm; |
486 | static inline _LIBCPP_DEPRECATED_IN_CXX23 _LIBCPP_CONSTEXPR const bool has_denorm_loss = __base::has_denorm_loss; |
487 | _LIBCPP_SUPPRESS_DEPRECATED_POP |
488 | [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR type infinity() _NOEXCEPT { |
489 | return __base::infinity(); |
490 | } |
491 | [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR type quiet_NaN() _NOEXCEPT { |
492 | return __base::quiet_NaN(); |
493 | } |
494 | [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR type signaling_NaN() _NOEXCEPT { |
495 | return __base::signaling_NaN(); |
496 | } |
497 | [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR type denorm_min() _NOEXCEPT { |
498 | return __base::denorm_min(); |
499 | } |
500 | |
501 | static inline _LIBCPP_CONSTEXPR const bool is_iec559 = __base::is_iec559; |
502 | static inline _LIBCPP_CONSTEXPR const bool is_bounded = __base::is_bounded; |
503 | static inline _LIBCPP_CONSTEXPR const bool is_modulo = __base::is_modulo; |
504 | |
505 | static inline _LIBCPP_CONSTEXPR const bool traps = __base::traps; |
506 | static inline _LIBCPP_CONSTEXPR const bool tinyness_before = __base::tinyness_before; |
507 | static inline _LIBCPP_CONSTEXPR const float_round_style round_style = __base::round_style; |
508 | }; |
509 | |
510 | template <class _Tp> |
511 | class numeric_limits<const _Tp> : public numeric_limits<_Tp> {}; |
512 | |
513 | template <class _Tp> |
514 | class numeric_limits<volatile _Tp> : public numeric_limits<_Tp> {}; |
515 | |
516 | template <class _Tp> |
517 | class numeric_limits<const volatile _Tp> : public numeric_limits<_Tp> {}; |
518 | |
519 | _LIBCPP_END_NAMESPACE_STD |
520 | |
521 | _LIBCPP_POP_MACROS |
522 | |
523 | # if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20 |
524 | # include <type_traits> |
525 | # endif |
526 | #endif // __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS) |
527 | |
528 | #endif // _LIBCPP_LIMITS |
529 | |