25#ifndef _GLIBCXX_EXPERIMENTAL_BITS_NUMERIC_TRAITS_H
26#define _GLIBCXX_EXPERIMENTAL_BITS_NUMERIC_TRAITS_H
32template <
template <
typename>
class _Trait,
typename _Tp,
typename =
void>
35template <
template <
typename>
class _Trait,
typename _Tp>
36 struct __value_exists_impl<_Trait, _Tp,
void_t<decltype(_Trait<_Tp>::value)>>
39template <
typename _Tp,
bool = is_arithmetic_v<_Tp>>
40 struct __digits_impl {};
42template <
typename _Tp>
43 struct __digits_impl<_Tp, true>
45 static inline constexpr int value
46 =
sizeof(_Tp) * __CHAR_BIT__ - is_signed_v<_Tp>;
50 struct __digits_impl<float, true>
51 {
static inline constexpr int value = __FLT_MANT_DIG__; };
54 struct __digits_impl<double, true>
55 {
static inline constexpr int value = __DBL_MANT_DIG__; };
58 struct __digits_impl<long double, true>
59 {
static inline constexpr int value = __LDBL_MANT_DIG__; };
61template <
typename _Tp,
bool = is_arithmetic_v<_Tp>>
62 struct __digits10_impl {};
64template <
typename _Tp>
65 struct __digits10_impl<_Tp, true>
68 static inline constexpr int value = __digits_impl<_Tp>::value * 643L / 2136;
72 struct __digits10_impl<float, true>
73 {
static inline constexpr int value = __FLT_DIG__; };
76 struct __digits10_impl<double, true>
77 {
static inline constexpr int value = __DBL_DIG__; };
80 struct __digits10_impl<long double, true>
81 {
static inline constexpr int value = __LDBL_DIG__; };
83template <
typename _Tp,
bool = is_arithmetic_v<_Tp>>
84 struct __max_digits10_impl {};
86template <
typename _Tp>
87 struct __max_digits10_impl<_Tp, true>
89 static inline constexpr int value
90 = is_floating_point_v<_Tp> ? 2 + __digits_impl<_Tp>::value * 643L / 2136
91 : __digits10_impl<_Tp>::value + 1;
94template <
typename _Tp>
95 struct __max_exponent_impl {};
98 struct __max_exponent_impl<float>
99 {
static inline constexpr int value = __FLT_MAX_EXP__; };
102 struct __max_exponent_impl<double>
103 {
static inline constexpr int value = __DBL_MAX_EXP__; };
106 struct __max_exponent_impl<long double>
107 {
static inline constexpr int value = __LDBL_MAX_EXP__; };
109template <
typename _Tp>
110 struct __max_exponent10_impl {};
113 struct __max_exponent10_impl<float>
114 {
static inline constexpr int value = __FLT_MAX_10_EXP__; };
117 struct __max_exponent10_impl<double>
118 {
static inline constexpr int value = __DBL_MAX_10_EXP__; };
121 struct __max_exponent10_impl<long double>
122 {
static inline constexpr int value = __LDBL_MAX_10_EXP__; };
124template <
typename _Tp>
125 struct __min_exponent_impl {};
128 struct __min_exponent_impl<float>
129 {
static inline constexpr int value = __FLT_MIN_EXP__; };
132 struct __min_exponent_impl<double>
133 {
static inline constexpr int value = __DBL_MIN_EXP__; };
136 struct __min_exponent_impl<long double>
137 {
static inline constexpr int value = __LDBL_MIN_EXP__; };
139template <
typename _Tp>
140 struct __min_exponent10_impl {};
143 struct __min_exponent10_impl<float>
144 {
static inline constexpr int value = __FLT_MIN_10_EXP__; };
147 struct __min_exponent10_impl<double>
148 {
static inline constexpr int value = __DBL_MIN_10_EXP__; };
151 struct __min_exponent10_impl<long double>
152 {
static inline constexpr int value = __LDBL_MIN_10_EXP__; };
154template <
typename _Tp,
bool = is_arithmetic_v<_Tp>>
155 struct __radix_impl {};
157template <
typename _Tp>
158 struct __radix_impl<_Tp, true>
160 static inline constexpr int value
161 = is_floating_point_v<_Tp> ? __FLT_RADIX__ : 2;
165template <
template <
typename>
class _Trait,
typename _Tp>
166 struct __value_exists : __value_exists_impl<_Trait, _Tp> {};
168template <
template <
typename>
class _Trait,
typename _Tp>
169 inline constexpr bool __value_exists_v = __value_exists<_Trait, _Tp>::value;
171template <
template <
typename>
class _Trait,
typename _Tp,
typename _Up = _Tp>
173 __value_or(_Up __def = _Up()) noexcept
175 if constexpr (__value_exists_v<_Trait, _Tp>)
176 return static_cast<_Up
>(_Trait<_Tp>::value);
181template <
typename _Tp,
bool = is_arithmetic_v<_Tp>>
182 struct __norm_min_impl {};
184template <
typename _Tp>
185 struct __norm_min_impl<_Tp, true>
186 {
static inline constexpr _Tp value = 1; };
189 struct __norm_min_impl<float, true>
190 {
static inline constexpr float value = __FLT_MIN__; };
193 struct __norm_min_impl<double, true>
194 {
static inline constexpr double value = __DBL_MIN__; };
197 struct __norm_min_impl<long double, true>
198 {
static inline constexpr long double value = __LDBL_MIN__; };
200template <
typename _Tp>
201 struct __denorm_min_impl : __norm_min_impl<_Tp> {};
203#if __FLT_HAS_DENORM__
205 struct __denorm_min_impl<float>
206 {
static inline constexpr float value = __FLT_DENORM_MIN__; };
209#if __DBL_HAS_DENORM__
211 struct __denorm_min_impl<double>
212 {
static inline constexpr double value = __DBL_DENORM_MIN__; };
215#if __LDBL_HAS_DENORM__
217 struct __denorm_min_impl<long double>
218 {
static inline constexpr long double value = __LDBL_DENORM_MIN__; };
221template <
typename _Tp>
222 struct __epsilon_impl {};
225 struct __epsilon_impl<float>
226 {
static inline constexpr float value = __FLT_EPSILON__; };
229 struct __epsilon_impl<double>
230 {
static inline constexpr double value = __DBL_EPSILON__; };
233 struct __epsilon_impl<long double>
234 {
static inline constexpr long double value = __LDBL_EPSILON__; };
236template <
typename _Tp,
bool = is_arithmetic_v<_Tp>>
237 struct __finite_min_impl {};
239template <
typename _Tp>
240 struct __finite_min_impl<_Tp, true>
242 static inline constexpr _Tp value
243 = is_unsigned_v<_Tp> ? _Tp()
244 : -2 * (_Tp(1) << __digits_impl<_Tp>::value - 1);
248 struct __finite_min_impl<float, true>
249 {
static inline constexpr float value = -__FLT_MAX__; };
252 struct __finite_min_impl<double, true>
253 {
static inline constexpr double value = -__DBL_MAX__; };
256 struct __finite_min_impl<long double, true>
257 {
static inline constexpr long double value = -__LDBL_MAX__; };
259template <
typename _Tp,
bool = is_arithmetic_v<_Tp>>
260 struct __finite_max_impl {};
262template <
typename _Tp>
263 struct __finite_max_impl<_Tp, true>
264 {
static inline constexpr _Tp value = ~__finite_min_impl<_Tp>::value; };
267 struct __finite_max_impl<float, true>
268 {
static inline constexpr float value = __FLT_MAX__; };
271 struct __finite_max_impl<double, true>
272 {
static inline constexpr double value = __DBL_MAX__; };
275 struct __finite_max_impl<long double, true>
276 {
static inline constexpr long double value = __LDBL_MAX__; };
278template <
typename _Tp>
279 struct __infinity_impl {};
281#if __FLT_HAS_INFINITY__
283 struct __infinity_impl<float>
284 {
static inline constexpr float value = __builtin_inff(); };
287#if __DBL_HAS_INFINITY__
289 struct __infinity_impl<double>
290 {
static inline constexpr double value = __builtin_inf(); };
293#if __LDBL_HAS_INFINITY__
295 struct __infinity_impl<long double>
296 {
static inline constexpr long double value = __builtin_infl(); };
299template <
typename _Tp>
300 struct __quiet_NaN_impl {};
302#if __FLT_HAS_QUIET_NAN__
304 struct __quiet_NaN_impl<float>
305 {
static inline constexpr float value = __builtin_nanf(
""); };
308#if __DBL_HAS_QUIET_NAN__
310 struct __quiet_NaN_impl<double>
311 {
static inline constexpr double value = __builtin_nan(
""); };
314#if __LDBL_HAS_QUIET_NAN__
316 struct __quiet_NaN_impl<long double>
317 {
static inline constexpr long double value = __builtin_nanl(
""); };
320template <
typename _Tp,
bool = is_
floating_po
int_v<_Tp>>
321 struct __reciprocal_overflow_threshold_impl {};
323template <
typename _Tp>
324 struct __reciprocal_overflow_threshold_impl<_Tp, true>
328 static constexpr _Tp _S_search(_Tp __ok, _Tp __overflows)
330 const _Tp __mid = (__ok + __overflows) / 2;
335 if (__mid == __ok || __mid == __overflows)
337 else if (_Tp(1) / (__radix_impl<_Tp>::value * __mid)
338 <= __finite_max_impl<_Tp>::value / __radix_impl<_Tp>::value)
339 return _S_search(__mid, __overflows);
341 return _S_search(__ok, __mid);
344 static inline constexpr _Tp value
345 = _S_search(_Tp(1.01) / __finite_max_impl<_Tp>::value,
346 _Tp(0.99) / __finite_max_impl<_Tp>::value);
349template <
typename _Tp,
bool = is_
floating_po
int_v<_Tp>>
350 struct __round_error_impl {};
352template <
typename _Tp>
353 struct __round_error_impl<_Tp, true>
354 {
static inline constexpr _Tp value = 0.5; };
356template <
typename _Tp>
357 struct __signaling_NaN_impl {};
359#if __FLT_HAS_QUIET_NAN__
361 struct __signaling_NaN_impl<float>
362 {
static inline constexpr float value = __builtin_nansf(
""); };
365#if __DBL_HAS_QUIET_NAN__
367 struct __signaling_NaN_impl<double>
368 {
static inline constexpr double value = __builtin_nans(
""); };
371#if __LDBL_HAS_QUIET_NAN__
373 struct __signaling_NaN_impl<long double>
374 {
static inline constexpr long double value = __builtin_nansl(
""); };
378template <
typename _Tp>
379 struct __denorm_min : __denorm_min_impl<remove_cv_t<_Tp>> {};
381template <
typename _Tp>
382 struct __epsilon : __epsilon_impl<remove_cv_t<_Tp>> {};
384template <
typename _Tp>
385 struct __finite_max : __finite_max_impl<remove_cv_t<_Tp>> {};
387template <
typename _Tp>
388 struct __finite_min : __finite_min_impl<remove_cv_t<_Tp>> {};
390template <
typename _Tp>
391 struct __infinity : __infinity_impl<remove_cv_t<_Tp>> {};
393template <
typename _Tp>
394 struct __norm_min : __norm_min_impl<remove_cv_t<_Tp>> {};
396template <
typename _Tp>
397 struct __quiet_NaN : __quiet_NaN_impl<remove_cv_t<_Tp>> {};
399template <
typename _Tp>
400 struct __reciprocal_overflow_threshold
401 : __reciprocal_overflow_threshold_impl<remove_cv_t<_Tp>> {};
403template <
typename _Tp>
404 struct __round_error : __round_error_impl<remove_cv_t<_Tp>> {};
406template <
typename _Tp>
407 struct __signaling_NaN : __signaling_NaN_impl<remove_cv_t<_Tp>> {};
409template <
typename _Tp>
410 inline constexpr auto __denorm_min_v = __denorm_min<_Tp>::value;
412template <
typename _Tp>
413 inline constexpr auto __epsilon_v = __epsilon<_Tp>::value;
415template <
typename _Tp>
416 inline constexpr auto __finite_max_v = __finite_max<_Tp>::value;
418template <
typename _Tp>
419 inline constexpr auto __finite_min_v = __finite_min<_Tp>::value;
421template <
typename _Tp>
422 inline constexpr auto __infinity_v = __infinity<_Tp>::value;
424template <
typename _Tp>
425 inline constexpr auto __norm_min_v = __norm_min<_Tp>::value;
427template <
typename _Tp>
428 inline constexpr auto __quiet_NaN_v = __quiet_NaN<_Tp>::value;
430template <
typename _Tp>
431 inline constexpr auto __reciprocal_overflow_threshold_v
432 = __reciprocal_overflow_threshold<_Tp>::value;
434template <
typename _Tp>
435 inline constexpr auto __round_error_v = __round_error<_Tp>::value;
437template <
typename _Tp>
438 inline constexpr auto __signaling_NaN_v = __signaling_NaN<_Tp>::value;
441template <
typename _Tp>
442 struct __digits : __digits_impl<remove_cv_t<_Tp>> {};
444template <
typename _Tp>
445 struct __digits10 : __digits10_impl<remove_cv_t<_Tp>> {};
447template <
typename _Tp>
448 struct __max_digits10 : __max_digits10_impl<remove_cv_t<_Tp>> {};
450template <
typename _Tp>
451 struct __max_exponent : __max_exponent_impl<remove_cv_t<_Tp>> {};
453template <
typename _Tp>
454 struct __max_exponent10 : __max_exponent10_impl<remove_cv_t<_Tp>> {};
456template <
typename _Tp>
457 struct __min_exponent : __min_exponent_impl<remove_cv_t<_Tp>> {};
459template <
typename _Tp>
460 struct __min_exponent10 : __min_exponent10_impl<remove_cv_t<_Tp>> {};
462template <
typename _Tp>
463 struct __radix : __radix_impl<remove_cv_t<_Tp>> {};
465template <
typename _Tp>
466 inline constexpr auto __digits_v = __digits<_Tp>::value;
468template <
typename _Tp>
469 inline constexpr auto __digits10_v = __digits10<_Tp>::value;
471template <
typename _Tp>
472 inline constexpr auto __max_digits10_v = __max_digits10<_Tp>::value;
474template <
typename _Tp>
475 inline constexpr auto __max_exponent_v = __max_exponent<_Tp>::value;
477template <
typename _Tp>
478 inline constexpr auto __max_exponent10_v = __max_exponent10<_Tp>::value;
480template <
typename _Tp>
481 inline constexpr auto __min_exponent_v = __min_exponent<_Tp>::value;
483template <
typename _Tp>
484 inline constexpr auto __min_exponent10_v = __min_exponent10<_Tp>::value;
486template <
typename _Tp>
487 inline constexpr auto __radix_v = __radix<_Tp>::value;
491template <
typename _Tp>
492 struct __has_iec559_storage_format :
true_type {};
494template <
typename _Tp>
495 inline constexpr bool __has_iec559_storage_format_v
496 = __has_iec559_storage_format<_Tp>::value;
513template <
template <
typename>
class _Trait,
typename _Tp>
516template <
template <
typename>
class _Trait,
typename _Tp>
517 inline constexpr bool __has_iec559_behavior_v
518 = __has_iec559_behavior<_Trait, _Tp>::value;
520#if !__FINITE_MATH_ONLY__
521#if __FLT_HAS_QUIET_NAN__
523 struct __has_iec559_behavior<__quiet_NaN, float> :
true_type {};
526#if __DBL_HAS_QUIET_NAN__
528 struct __has_iec559_behavior<__quiet_NaN, double> :
true_type {};
531#if __LDBL_HAS_QUIET_NAN__
533 struct __has_iec559_behavior<__quiet_NaN, long double> :
true_type {};
536#if __FLT_HAS_INFINITY__
538 struct __has_iec559_behavior<__infinity, float> :
true_type {};
541#if __DBL_HAS_INFINITY__
543 struct __has_iec559_behavior<__infinity, double> :
true_type {};
546#if __LDBL_HAS_INFINITY__
548 struct __has_iec559_behavior<__infinity, long double> :
true_type {};
551#ifdef __SUPPORT_SNAN__
552#if __FLT_HAS_QUIET_NAN__
554 struct __has_iec559_behavior<__signaling_NaN, float> :
true_type {};
557#if __DBL_HAS_QUIET_NAN__
559 struct __has_iec559_behavior<__signaling_NaN, double> :
true_type {};
562#if __LDBL_HAS_QUIET_NAN__
564 struct __has_iec559_behavior<__signaling_NaN, long double> :
true_type {};
__bool_constant< true > true_type
The type used as a compile-time boolean with true value.
__bool_constant< false > false_type
The type used as a compile-time boolean with false value.
void void_t
A metafunction that always yields void, used for detecting valid types.
ISO C++ entities toplevel namespace is std.