STLdoc
STLdocumentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Macros | Functions
numeric_traits.h File Reference
#include <bits/cpp_type_traits.h>
#include <ext/type_traits.h>

Go to the source code of this file.

Macros

#define __glibcxx_signed(_Tp)   ((_Tp)(-1) < 0)
 
#define __glibcxx_digits(_Tp)   (sizeof(_Tp) * __CHAR_BIT__ - __glibcxx_signed(_Tp))
 
#define __glibcxx_min(_Tp)   (__glibcxx_signed(_Tp) ? (_Tp)1 << __glibcxx_digits(_Tp) : (_Tp)0)
 
#define __glibcxx_max(_Tp)
 
#define __glibcxx_floating(_Tp, _Fval, _Dval, _LDval)
 
#define __glibcxx_max_digits10(_Tp)
 
#define __glibcxx_digits10(_Tp)   __glibcxx_floating(_Tp, __FLT_DIG__, __DBL_DIG__, __LDBL_DIG__)
 
#define __glibcxx_max_exponent10(_Tp)
 

Functions

namespace __gnu_cxx _GLIBCXX_VISIBILITY (default)
 

Detailed Description

This file is a GNU extension to the Standard C++ Library.

Macro Definition Documentation

#define __glibcxx_digits (   _Tp)    (sizeof(_Tp) * __CHAR_BIT__ - __glibcxx_signed(_Tp))
#define __glibcxx_digits10 (   _Tp)    __glibcxx_floating(_Tp, __FLT_DIG__, __DBL_DIG__, __LDBL_DIG__)
#define __glibcxx_floating (   _Tp,
  _Fval,
  _Dval,
  _LDval 
)
Value:
(std::__are_same<_Tp, float>::__value ? _Fval \
: std::__are_same<_Tp, double>::__value ? _Dval : _LDval)
#define __glibcxx_max (   _Tp)
Value:
(((((_Tp)1 << (__glibcxx_digits(_Tp) - 1)) - 1) << 1) + 1) : ~(_Tp)0)
#define __glibcxx_signed(_Tp)
#define __glibcxx_digits(_Tp)
#define __glibcxx_max_digits10 (   _Tp)
Value:
(2 + __glibcxx_floating(_Tp, __FLT_MANT_DIG__, __DBL_MANT_DIG__, \
__LDBL_MANT_DIG__) * 643L / 2136)
#define __glibcxx_floating(_Tp, _Fval, _Dval, _LDval)
#define __glibcxx_max_exponent10 (   _Tp)
Value:
__glibcxx_floating(_Tp, __FLT_MAX_10_EXP__, __DBL_MAX_10_EXP__, \
__LDBL_MAX_10_EXP__)
#define __glibcxx_floating(_Tp, _Fval, _Dval, _LDval)
#define __glibcxx_min (   _Tp)    (__glibcxx_signed(_Tp) ? (_Tp)1 << __glibcxx_digits(_Tp) : (_Tp)0)
#define __glibcxx_signed (   _Tp)    ((_Tp)(-1) < 0)

Function Documentation

namespace __gnu_cxx _GLIBCXX_VISIBILITY ( default  )
38 {
39 _GLIBCXX_BEGIN_NAMESPACE_VERSION
40 
41  // Compile time constants for builtin types.
42  // Sadly std::numeric_limits member functions cannot be used for this.
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  // Only integers for initialization of member constant.
58  static const _Value __min = __glibcxx_min(_Value);
59  static const _Value __max = __glibcxx_max(_Value);
60 
61  // NB: these two also available in std::numeric_limits as compile
62  // time constants, but <limits> is big and we avoid including it.
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  // Only floating point types. See N1822.
103  static const int __max_digits10 = __glibcxx_max_digits10(_Value);
104 
105  // See above comment...
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 } // namespace
#define __glibcxx_max_exponent10(_Tp)
#define __glibcxx_min(_Tp)
#define __glibcxx_signed(_Tp)
#define __glibcxx_max(_Tp)
#define __glibcxx_digits10(_Tp)
#define __glibcxx_max_digits10(_Tp)
#define __glibcxx_digits(_Tp)