29 #ifndef _EXT_NUMERIC_TRAITS 30 #define _EXT_NUMERIC_TRAITS 1 32 #pragma GCC system_header 37 namespace __gnu_cxx _GLIBCXX_VISIBILITY(default)
39 _GLIBCXX_BEGIN_NAMESPACE_VERSION
43 #define __glibcxx_signed(_Tp) ((_Tp)(-1) < 0) 44 #define __glibcxx_digits(_Tp) \ 45 (sizeof(_Tp) * __CHAR_BIT__ - __glibcxx_signed(_Tp)) 47 #define __glibcxx_min(_Tp) \ 48 (__glibcxx_signed(_Tp) ? -__glibcxx_max(_Tp) - 1 : (_Tp)0) 50 #define __glibcxx_max(_Tp) \ 51 (__glibcxx_signed(_Tp) ? \ 52 (((((_Tp)1 << (__glibcxx_digits(_Tp) - 1)) - 1) << 1) + 1) : ~(_Tp)0) 54 template<
typename _Value>
55 struct __numeric_traits_integer
57 #if __cplusplus >= 201103L 58 static_assert(std::__is_integer<_Value>::__value,
59 "invalid specialization");
63 static const _Value __min = __glibcxx_min(_Value);
64 static const _Value __max = __glibcxx_max(_Value);
68 static const bool __is_signed = __glibcxx_signed(_Value);
69 static const int __digits = __glibcxx_digits(_Value);
72 template<
typename _Value>
73 const _Value __numeric_traits_integer<_Value>::__min;
75 template<
typename _Value>
76 const _Value __numeric_traits_integer<_Value>::__max;
78 template<
typename _Value>
79 const bool __numeric_traits_integer<_Value>::__is_signed;
81 template<
typename _Value>
82 const int __numeric_traits_integer<_Value>::__digits;
84 #if __cplusplus >= 201103L 85 template<
typename _Tp>
86 using __int_traits = __numeric_traits_integer<_Tp>;
89 #undef __glibcxx_signed 90 #undef __glibcxx_digits 94 #define __glibcxx_floating(_Tp, _Fval, _Dval, _LDval) \ 95 (std::__are_same<_Tp, float>::__value ? _Fval \ 96 : std::__are_same<_Tp, double>::__value ? _Dval : _LDval) 98 #define __glibcxx_max_digits10(_Tp) \ 99 (2 + __glibcxx_floating(_Tp, __FLT_MANT_DIG__, __DBL_MANT_DIG__, \ 100 __LDBL_MANT_DIG__) * 643L / 2136) 102 #define __glibcxx_digits10(_Tp) \ 103 __glibcxx_floating(_Tp, __FLT_DIG__, __DBL_DIG__, __LDBL_DIG__) 105 #define __glibcxx_max_exponent10(_Tp) \ 106 __glibcxx_floating(_Tp, __FLT_MAX_10_EXP__, __DBL_MAX_10_EXP__, \ 109 template<
typename _Value>
110 struct __numeric_traits_floating
113 static const int __max_digits10 = __glibcxx_max_digits10(_Value);
116 static const bool __is_signed =
true;
117 static const int __digits10 = __glibcxx_digits10(_Value);
118 static const int __max_exponent10 = __glibcxx_max_exponent10(_Value);
121 template<
typename _Value>
122 const int __numeric_traits_floating<_Value>::__max_digits10;
124 template<
typename _Value>
125 const bool __numeric_traits_floating<_Value>::__is_signed;
127 template<
typename _Value>
128 const int __numeric_traits_floating<_Value>::__digits10;
130 template<
typename _Value>
131 const int __numeric_traits_floating<_Value>::__max_exponent10;
133 template<
typename _Value>
134 struct __numeric_traits
135 :
public __conditional_type<std::__is_integer<_Value>::__value,
136 __numeric_traits_integer<_Value>,
137 __numeric_traits_floating<_Value> >::__type
140 _GLIBCXX_END_NAMESPACE_VERSION
143 #undef __glibcxx_floating 144 #undef __glibcxx_max_digits10 145 #undef __glibcxx_digits10 146 #undef __glibcxx_max_exponent10
GNU extensions for public use.