numeric_traits.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035 #ifndef _EXT_NUMERIC_TRAITS
00036 #define _EXT_NUMERIC_TRAITS 1
00037
00038 #pragma GCC system_header
00039
00040 #include <bits/cpp_type_traits.h>
00041 #include <ext/type_traits.h>
00042
00043 _GLIBCXX_BEGIN_NAMESPACE(__gnu_cxx)
00044
00045
00046
00047 #define __glibcxx_signed(_Tp) ((_Tp)(-1) < 0)
00048 #define __glibcxx_digits(_Tp) \
00049 (sizeof(_Tp) * __CHAR_BIT__ - __glibcxx_signed(_Tp))
00050
00051 #define __glibcxx_min(_Tp) \
00052 (__glibcxx_signed(_Tp) ? (_Tp)1 << __glibcxx_digits(_Tp) : (_Tp)0)
00053
00054 #define __glibcxx_max(_Tp) \
00055 (__glibcxx_signed(_Tp) ? \
00056 (((((_Tp)1 << (__glibcxx_digits(_Tp) - 1)) - 1) << 1) + 1) : ~(_Tp)0)
00057
00058 template<typename _Value>
00059 struct __numeric_traits_integer
00060 {
00061
00062 static const _Value __min = __glibcxx_min(_Value);
00063 static const _Value __max = __glibcxx_max(_Value);
00064
00065
00066
00067 static const bool __is_signed = __glibcxx_signed(_Value);
00068 static const int __digits = __glibcxx_digits(_Value);
00069 };
00070
00071 template<typename _Value>
00072 const _Value __numeric_traits_integer<_Value>::__min;
00073
00074 template<typename _Value>
00075 const _Value __numeric_traits_integer<_Value>::__max;
00076
00077 template<typename _Value>
00078 const bool __numeric_traits_integer<_Value>::__is_signed;
00079
00080 template<typename _Value>
00081 const int __numeric_traits_integer<_Value>::__digits;
00082
00083 #undef __glibcxx_signed
00084 #undef __glibcxx_digits
00085 #undef __glibcxx_min
00086 #undef __glibcxx_max
00087
00088 #define __glibcxx_floating(_Tp, _Fval, _Dval, _LDval) \
00089 (std::__are_same<_Tp, float>::__value ? _Fval \
00090 : std::__are_same<_Tp, double>::__value ? _Dval : _LDval)
00091
00092 #define __glibcxx_max_digits10(_Tp) \
00093 (2 + __glibcxx_floating(_Tp, __FLT_MANT_DIG__, __DBL_MANT_DIG__, \
00094 __LDBL_MANT_DIG__) * 3010 / 10000)
00095
00096 #define __glibcxx_digits10(_Tp) \
00097 __glibcxx_floating(_Tp, __FLT_DIG__, __DBL_DIG__, __LDBL_DIG__)
00098
00099 #define __glibcxx_max_exponent10(_Tp) \
00100 __glibcxx_floating(_Tp, __FLT_MAX_10_EXP__, __DBL_MAX_10_EXP__, \
00101 __LDBL_MAX_10_EXP__)
00102
00103 template<typename _Value>
00104 struct __numeric_traits_floating
00105 {
00106
00107 static const int __max_digits10 = __glibcxx_max_digits10(_Value);
00108
00109
00110 static const bool __is_signed = true;
00111 static const int __digits10 = __glibcxx_digits10(_Value);
00112 static const int __max_exponent10 = __glibcxx_max_exponent10(_Value);
00113 };
00114
00115 template<typename _Value>
00116 const int __numeric_traits_floating<_Value>::__max_digits10;
00117
00118 template<typename _Value>
00119 const bool __numeric_traits_floating<_Value>::__is_signed;
00120
00121 template<typename _Value>
00122 const int __numeric_traits_floating<_Value>::__digits10;
00123
00124 template<typename _Value>
00125 const int __numeric_traits_floating<_Value>::__max_exponent10;
00126
00127 template<typename _Value>
00128 struct __numeric_traits
00129 : public __conditional_type<std::__is_integer<_Value>::__value,
00130 __numeric_traits_integer<_Value>,
00131 __numeric_traits_floating<_Value> >::__type
00132 { };
00133
00134 _GLIBCXX_END_NAMESPACE
00135
00136 #undef __glibcxx_floating
00137 #undef __glibcxx_max_digits10
00138 #undef __glibcxx_digits10
00139 #undef __glibcxx_max_exponent10
00140
00141 #endif