29 #ifndef _EXT_NUMERIC_TRAITS
30 #define _EXT_NUMERIC_TRAITS 1
32 #ifdef _GLIBCXX_SYSHDR
33 #pragma GCC system_header
39 namespace __gnu_cxx _GLIBCXX_VISIBILITY(default)
41 _GLIBCXX_BEGIN_NAMESPACE_VERSION
52 template<
typename _Tp>
53 struct __is_integer_nonstrict
54 :
public std::__is_integer<_Tp>
56 using std::__is_integer<_Tp>::__value;
59 enum { __width = __value ?
sizeof(_Tp) * __CHAR_BIT__ : 0 };
62 template<
typename _Value>
63 struct __numeric_traits_integer
65 #if __cplusplus >= 201103L
66 static_assert(__is_integer_nonstrict<_Value>::__value,
67 "invalid specialization");
72 static const bool __is_signed = (_Value)(-1) < 0;
73 static const int __digits
74 = __is_integer_nonstrict<_Value>::__width - __is_signed;
77 static const _Value __max = __is_signed
78 ? (((((_Value)1 << (__digits - 1)) - 1) << 1) + 1)
80 static const _Value __min = __is_signed ? -__max - 1 : (_Value)0;
83 template<
typename _Value>
84 const _Value __numeric_traits_integer<_Value>::__min;
86 template<
typename _Value>
87 const _Value __numeric_traits_integer<_Value>::__max;
89 template<
typename _Value>
90 const bool __numeric_traits_integer<_Value>::__is_signed;
92 template<
typename _Value>
93 const int __numeric_traits_integer<_Value>::__digits;
97 #define _GLIBCXX_INT_N_TRAITS(T, WIDTH) \
99 template<> struct __is_integer_nonstrict<T> \
101 enum { __value = 1 }; \
102 typedef std::__true_type __type; \
103 enum { __width = WIDTH }; \
106 template<> struct __is_integer_nonstrict<unsigned T> \
108 enum { __value = 1 }; \
109 typedef std::__true_type __type; \
110 enum { __width = WIDTH }; \
116 #if defined __GLIBCXX_TYPE_INT_N_0 && __GLIBCXX_BITSIZE_INT_N_0 % __CHAR_BIT__
117 _GLIBCXX_INT_N_TRAITS(__GLIBCXX_TYPE_INT_N_0, __GLIBCXX_BITSIZE_INT_N_0)
119 #if defined __GLIBCXX_TYPE_INT_N_1 && __GLIBCXX_BITSIZE_INT_N_1 % __CHAR_BIT__
120 _GLIBCXX_INT_N_TRAITS(__GLIBCXX_TYPE_INT_N_1, __GLIBCXX_BITSIZE_INT_N_1)
122 #if defined __GLIBCXX_TYPE_INT_N_2 && __GLIBCXX_BITSIZE_INT_N_2 % __CHAR_BIT__
123 _GLIBCXX_INT_N_TRAITS(__GLIBCXX_TYPE_INT_N_2, __GLIBCXX_BITSIZE_INT_N_2)
125 #if defined __GLIBCXX_TYPE_INT_N_3 && __GLIBCXX_BITSIZE_INT_N_3 % __CHAR_BIT__
126 _GLIBCXX_INT_N_TRAITS(__GLIBCXX_TYPE_INT_N_3, __GLIBCXX_BITSIZE_INT_N_3)
129 #if defined __STRICT_ANSI__ && defined __SIZEOF_INT128__
132 _GLIBCXX_INT_N_TRAITS(__int128, 128)
135 #undef _GLIBCXX_INT_N_TRAITS
137 #if __cplusplus >= 201103L
139 template<
typename _Tp>
143 #define __glibcxx_floating(_Tp, _Fval, _Dval, _LDval) \
144 (std::__are_same<_Tp, float>::__value ? _Fval \
145 : std::__are_same<_Tp, double>::__value ? _Dval : _LDval)
147 #define __glibcxx_max_digits10(_Tp) \
148 (2 + __glibcxx_floating(_Tp, __FLT_MANT_DIG__, __DBL_MANT_DIG__, \
149 __LDBL_MANT_DIG__) * 643L / 2136)
151 #define __glibcxx_digits10(_Tp) \
152 __glibcxx_floating(_Tp, __FLT_DIG__, __DBL_DIG__, __LDBL_DIG__)
154 #define __glibcxx_max_exponent10(_Tp) \
155 __glibcxx_floating(_Tp, __FLT_MAX_10_EXP__, __DBL_MAX_10_EXP__, \
159 template<
typename _Value>
160 struct __numeric_traits_floating
163 static const int __max_digits10 = __glibcxx_max_digits10(_Value);
166 static const bool __is_signed =
true;
167 static const int __digits10 = __glibcxx_digits10(_Value);
168 static const int __max_exponent10 = __glibcxx_max_exponent10(_Value);
171 template<
typename _Value>
172 const int __numeric_traits_floating<_Value>::__max_digits10;
174 template<
typename _Value>
175 const bool __numeric_traits_floating<_Value>::__is_signed;
177 template<
typename _Value>
178 const int __numeric_traits_floating<_Value>::__digits10;
180 template<
typename _Value>
181 const int __numeric_traits_floating<_Value>::__max_exponent10;
183 #undef __glibcxx_floating
184 #undef __glibcxx_max_digits10
185 #undef __glibcxx_digits10
186 #undef __glibcxx_max_exponent10
188 template<
typename _Value>
189 struct __numeric_traits
190 :
public __numeric_traits_integer<_Value>
194 struct __numeric_traits<float>
195 :
public __numeric_traits_floating<float>
199 struct __numeric_traits<double>
200 :
public __numeric_traits_floating<double>
204 struct __numeric_traits<long double>
205 :
public __numeric_traits_floating<long double>
208 #ifdef _GLIBCXX_LONG_DOUBLE_ALT128_COMPAT
209 # if defined __LONG_DOUBLE_IEEE128__
212 struct __numeric_traits_floating<__ibm128>
214 static const int __max_digits10 = 33;
215 static const bool __is_signed =
true;
216 static const int __digits10 = 31;
217 static const int __max_exponent10 = 308;
220 struct __numeric_traits<__ibm128>
221 :
public __numeric_traits_floating<__ibm128>
223 # elif defined __LONG_DOUBLE_IBM128__
226 struct __numeric_traits_floating<__ieee128>
228 static const int __max_digits10 = 36;
229 static const bool __is_signed =
true;
230 static const int __digits10 = 33;
231 static const int __max_exponent10 = 4932;
234 struct __numeric_traits<__ieee128>
235 :
public __numeric_traits_floating<__ieee128>
240 _GLIBCXX_END_NAMESPACE_VERSION
GNU extensions for public use.
__numeric_traits_integer< _Tp > __int_traits
Convenience alias for __numeric_traits<integer-type>.