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