29#ifndef _EXT_NUMERIC_TRAITS
30#define _EXT_NUMERIC_TRAITS 1
32#pragma GCC system_header
37namespace __gnu_cxx _GLIBCXX_VISIBILITY(default)
39_GLIBCXX_BEGIN_NAMESPACE_VERSION
50 template<
typename _Tp>
51 struct __is_integer_nonstrict
52 :
public std::__is_integer<_Tp>
54 using std::__is_integer<_Tp>::__value;
57 enum { __width = __value ?
sizeof(_Tp) * __CHAR_BIT__ : 0 };
60 template<
typename _Value>
61 struct __numeric_traits_integer
63#if __cplusplus >= 201103L
64 static_assert(__is_integer_nonstrict<_Value>::__value,
65 "invalid specialization");
70 static const bool __is_signed = (_Value)(-1) < 0;
71 static const int __digits
72 = __is_integer_nonstrict<_Value>::__width - __is_signed;
75 static const _Value __max = __is_signed
76 ? (((((_Value)1 << (__digits - 1)) - 1) << 1) + 1)
78 static const _Value __min = __is_signed ? -__max - 1 : (_Value)0;
81 template<
typename _Value>
82 const _Value __numeric_traits_integer<_Value>::__min;
84 template<
typename _Value>
85 const _Value __numeric_traits_integer<_Value>::__max;
87 template<
typename _Value>
88 const bool __numeric_traits_integer<_Value>::__is_signed;
90 template<
typename _Value>
91 const int __numeric_traits_integer<_Value>::__digits;
95#define _GLIBCXX_INT_N_TRAITS(T, WIDTH) \
96 template<> struct __is_integer_nonstrict<T> \
98 enum { __value = 1 }; \
99 typedef std::__true_type __type; \
100 enum { __width = WIDTH }; \
102 template<> struct __is_integer_nonstrict<unsigned T> \
104 enum { __value = 1 }; \
105 typedef std::__true_type __type; \
106 enum { __width = WIDTH }; \
112#if defined __GLIBCXX_TYPE_INT_N_0 && __GLIBCXX_BITSIZE_INT_N_0 % __CHAR_BIT__
113 _GLIBCXX_INT_N_TRAITS(__GLIBCXX_TYPE_INT_N_0, __GLIBCXX_BITSIZE_INT_N_0)
115#if defined __GLIBCXX_TYPE_INT_N_1 && __GLIBCXX_BITSIZE_INT_N_1 % __CHAR_BIT__
116 _GLIBCXX_INT_N_TRAITS(__GLIBCXX_TYPE_INT_N_1, __GLIBCXX_BITSIZE_INT_N_1)
118#if defined __GLIBCXX_TYPE_INT_N_2 && __GLIBCXX_BITSIZE_INT_N_2 % __CHAR_BIT__
119 _GLIBCXX_INT_N_TRAITS(__GLIBCXX_TYPE_INT_N_2, __GLIBCXX_BITSIZE_INT_N_2)
121#if defined __GLIBCXX_TYPE_INT_N_3 && __GLIBCXX_BITSIZE_INT_N_3 % __CHAR_BIT__
122 _GLIBCXX_INT_N_TRAITS(__GLIBCXX_TYPE_INT_N_3, __GLIBCXX_BITSIZE_INT_N_3)
125#if defined __STRICT_ANSI__ && defined __SIZEOF_INT128__
128 _GLIBCXX_INT_N_TRAITS(__int128, 128)
131#undef _GLIBCXX_INT_N_TRAITS
133#if __cplusplus >= 201103L
135 template<
typename _Tp>
139#define __glibcxx_floating(_Tp, _Fval, _Dval, _LDval) \
140 (std::__are_same<_Tp, float>::__value ? _Fval \
141 : std::__are_same<_Tp, double>::__value ? _Dval : _LDval)
143#define __glibcxx_max_digits10(_Tp) \
144 (2 + __glibcxx_floating(_Tp, __FLT_MANT_DIG__, __DBL_MANT_DIG__, \
145 __LDBL_MANT_DIG__) * 643L / 2136)
147#define __glibcxx_digits10(_Tp) \
148 __glibcxx_floating(_Tp, __FLT_DIG__, __DBL_DIG__, __LDBL_DIG__)
150#define __glibcxx_max_exponent10(_Tp) \
151 __glibcxx_floating(_Tp, __FLT_MAX_10_EXP__, __DBL_MAX_10_EXP__, \
155 template<
typename _Value>
156 struct __numeric_traits_floating
159 static const int __max_digits10 = __glibcxx_max_digits10(_Value);
162 static const bool __is_signed =
true;
163 static const int __digits10 = __glibcxx_digits10(_Value);
164 static const int __max_exponent10 = __glibcxx_max_exponent10(_Value);
167 template<
typename _Value>
168 const int __numeric_traits_floating<_Value>::__max_digits10;
170 template<
typename _Value>
171 const bool __numeric_traits_floating<_Value>::__is_signed;
173 template<
typename _Value>
174 const int __numeric_traits_floating<_Value>::__digits10;
176 template<
typename _Value>
177 const int __numeric_traits_floating<_Value>::__max_exponent10;
179#undef __glibcxx_floating
180#undef __glibcxx_max_digits10
181#undef __glibcxx_digits10
182#undef __glibcxx_max_exponent10
184 template<
typename _Value>
185 struct __numeric_traits
186 :
public __numeric_traits_integer<_Value>
190 struct __numeric_traits<float>
191 :
public __numeric_traits_floating<float>
195 struct __numeric_traits<double>
196 :
public __numeric_traits_floating<double>
200 struct __numeric_traits<long double>
201 :
public __numeric_traits_floating<long double>
204#ifdef _GLIBCXX_LONG_DOUBLE_ALT128_COMPAT
205# if defined __LONG_DOUBLE_IEEE128__
208 struct __numeric_traits_floating<__ibm128>
210 static const int __max_digits10 = 33;
211 static const bool __is_signed =
true;
212 static const int __digits10 = 31;
213 static const int __max_exponent10 = 308;
216 struct __numeric_traits<__ibm128>
217 :
public __numeric_traits_floating<__ibm128>
219# elif defined __LONG_DOUBLE_IBM128__
222 struct __numeric_traits_floating<__ieee128>
224 static const int __max_digits10 = 36;
225 static const bool __is_signed =
true;
226 static const int __digits10 = 33;
227 static const int __max_exponent10 = 4932;
230 struct __numeric_traits<__ieee128>
231 :
public __numeric_traits_floating<__ieee128>
236_GLIBCXX_END_NAMESPACE_VERSION
GNU extensions for public use.
__numeric_traits_integer< _Tp > __int_traits
Convenience alias for __numeric_traits<integer-type>.