| 1 | |
| 2 | |
| 3 | |
| 4 | |
| 5 | |
| 6 | |
| 7 | |
| 8 | |
| 9 | |
| 10 | |
| 11 | |
| 12 | |
| 13 | |
| 14 | |
| 15 | |
| 16 | |
| 17 | |
| 18 | |
| 19 | |
| 20 | |
| 21 | |
| 22 | |
| 23 | |
| 24 | |
| 25 | |
| 26 | |
| 27 | |
| 28 | |
| 29 | #ifndef _EXT_NUMERIC_TRAITS |
| 30 | #define _EXT_NUMERIC_TRAITS 1 |
| 31 | |
| 32 | #pragma GCC system_header |
| 33 | |
| 34 | #include <bits/cpp_type_traits.h> |
| 35 | #include <ext/type_traits.h> |
| 36 | |
| 37 | namespace __gnu_cxx _GLIBCXX_VISIBILITY(default) |
| 38 | { |
| 39 | _GLIBCXX_BEGIN_NAMESPACE_VERSION |
| 40 | |
| 41 | |
| 42 | |
| 43 | #define __glibcxx_signed(_Tp) ((_Tp)(-1) < 0) |
| 44 | #define __glibcxx_digits(_Tp) \ |
| 45 | (sizeof(_Tp) * __CHAR_BIT__ - __glibcxx_signed(_Tp)) |
| 46 | |
| 47 | #define __glibcxx_min(_Tp) \ |
| 48 | (__glibcxx_signed(_Tp) ? (_Tp)1 << __glibcxx_digits(_Tp) : (_Tp)0) |
| 49 | |
| 50 | #define __glibcxx_max(_Tp) \ |
| 51 | (__glibcxx_signed(_Tp) ? \ |
| 52 | (((((_Tp)1 << (__glibcxx_digits(_Tp) - 1)) - 1) << 1) + 1) : ~(_Tp)0) |
| 53 | |
| 54 | template<typename _Value> |
| 55 | struct __numeric_traits_integer |
| 56 | { |
| 57 | |
| 58 | static const _Value __min = __glibcxx_min(_Value); |
| 59 | static const _Value __max = __glibcxx_max(_Value); |
| 60 | |
| 61 | |
| 62 | |
| 63 | static const bool __is_signed = __glibcxx_signed(_Value); |
| 64 | static const int __digits = __glibcxx_digits(_Value); |
| 65 | }; |
| 66 | |
| 67 | template<typename _Value> |
| 68 | const _Value __numeric_traits_integer<_Value>::__min; |
| 69 | |
| 70 | template<typename _Value> |
| 71 | const _Value __numeric_traits_integer<_Value>::__max; |
| 72 | |
| 73 | template<typename _Value> |
| 74 | const bool __numeric_traits_integer<_Value>::__is_signed; |
| 75 | |
| 76 | template<typename _Value> |
| 77 | const int __numeric_traits_integer<_Value>::__digits; |
| 78 | |
| 79 | #undef __glibcxx_signed |
| 80 | #undef __glibcxx_digits |
| 81 | #undef __glibcxx_min |
| 82 | #undef __glibcxx_max |
| 83 | |
| 84 | #define __glibcxx_floating(_Tp, _Fval, _Dval, _LDval) \ |
| 85 | (std::__are_same<_Tp, float>::__value ? _Fval \ |
| 86 | : std::__are_same<_Tp, double>::__value ? _Dval : _LDval) |
| 87 | |
| 88 | #define __glibcxx_max_digits10(_Tp) \ |
| 89 | (2 + __glibcxx_floating(_Tp, __FLT_MANT_DIG__, __DBL_MANT_DIG__, \ |
| 90 | __LDBL_MANT_DIG__) * 643L / 2136) |
| 91 | |
| 92 | #define __glibcxx_digits10(_Tp) \ |
| 93 | __glibcxx_floating(_Tp, __FLT_DIG__, __DBL_DIG__, __LDBL_DIG__) |
| 94 | |
| 95 | #define __glibcxx_max_exponent10(_Tp) \ |
| 96 | __glibcxx_floating(_Tp, __FLT_MAX_10_EXP__, __DBL_MAX_10_EXP__, \ |
| 97 | __LDBL_MAX_10_EXP__) |
| 98 | |
| 99 | template<typename _Value> |
| 100 | struct __numeric_traits_floating |
| 101 | { |
| 102 | |
| 103 | static const int __max_digits10 = __glibcxx_max_digits10(_Value); |
| 104 | |
| 105 | |
| 106 | static const bool __is_signed = true; |
| 107 | static const int __digits10 = __glibcxx_digits10(_Value); |
| 108 | static const int __max_exponent10 = __glibcxx_max_exponent10(_Value); |
| 109 | }; |
| 110 | |
| 111 | template<typename _Value> |
| 112 | const int __numeric_traits_floating<_Value>::__max_digits10; |
| 113 | |
| 114 | template<typename _Value> |
| 115 | const bool __numeric_traits_floating<_Value>::__is_signed; |
| 116 | |
| 117 | template<typename _Value> |
| 118 | const int __numeric_traits_floating<_Value>::__digits10; |
| 119 | |
| 120 | template<typename _Value> |
| 121 | const int __numeric_traits_floating<_Value>::__max_exponent10; |
| 122 | |
| 123 | template<typename _Value> |
| 124 | struct __numeric_traits |
| 125 | : public __conditional_type<std::__is_integer<_Value>::__value, |
| 126 | __numeric_traits_integer<_Value>, |
| 127 | __numeric_traits_floating<_Value> >::__type |
| 128 | { }; |
| 129 | |
| 130 | _GLIBCXX_END_NAMESPACE_VERSION |
| 131 | } |
| 132 | |
| 133 | #undef __glibcxx_floating |
| 134 | #undef __glibcxx_max_digits10 |
| 135 | #undef __glibcxx_digits10 |
| 136 | #undef __glibcxx_max_exponent10 |
| 137 | |
| 138 | #endif |
| 139 | |