]> rtime.felk.cvut.cz Git - l4.git/blob - l4/pkg/libstdc++-v3/contrib/libstdc++-v3-4.3.3/include/ext/numeric_traits.h
update
[l4.git] / l4 / pkg / libstdc++-v3 / contrib / libstdc++-v3-4.3.3 / include / ext / numeric_traits.h
1 // -*- C++ -*-
2
3 // Copyright (C) 2007 Free Software Foundation, Inc.
4 //
5 // This file is part of the GNU ISO C++ Library.  This library is free
6 // software; you can redistribute it and/or modify it under the terms
7 // of the GNU General Public License as published by the Free Software
8 // Foundation; either version 2, or (at your option) any later
9 // version.
10
11 // This library is distributed in the hope that it will be useful, but
12 // WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 // General Public License for more details.
15
16 // You should have received a copy of the GNU General Public License along
17 // with this library; see the file COPYING.  If not, write to the Free
18 // Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
19 // USA.
20
21 // As a special exception, you may use this file as part of a free
22 // software library without restriction.  Specifically, if other files
23 // instantiate templates or use macros or inline functions from this
24 // file, or you compile this file and link it with other files to
25 // produce an executable, this file does not by itself cause the
26 // resulting executable to be covered by the GNU General Public
27 // License.  This exception does not however invalidate any other
28 // reasons why the executable file might be covered by the GNU General
29 // Public License.
30
31 /** @file ext/numeric_traits.h
32  *  This file is a GNU extension to the Standard C++ Library.
33  */
34
35 #ifndef _EXT_NUMERIC_TRAITS
36 #define _EXT_NUMERIC_TRAITS 1
37
38 #pragma GCC system_header
39
40 #include <bits/cpp_type_traits.h>
41 #include <ext/type_traits.h>
42
43 _GLIBCXX_BEGIN_NAMESPACE(__gnu_cxx)
44
45   // Compile time constants for builtin types.
46   // Sadly std::numeric_limits member functions cannot be used for this.
47 #define __glibcxx_signed(_Tp) ((_Tp)(-1) < 0)
48 #define __glibcxx_digits(_Tp) \
49   (sizeof(_Tp) * __CHAR_BIT__ - __glibcxx_signed(_Tp))
50
51 #define __glibcxx_min(_Tp) \
52   (__glibcxx_signed(_Tp) ? (_Tp)1 << __glibcxx_digits(_Tp) : (_Tp)0)
53
54 #define __glibcxx_max(_Tp) \
55   (__glibcxx_signed(_Tp) ? \
56    (((((_Tp)1 << (__glibcxx_digits(_Tp) - 1)) - 1) << 1) + 1) : ~(_Tp)0)
57
58   template<typename _Value>
59     struct __numeric_traits_integer
60     {
61       // Only integers for initialization of member constant.
62       static const _Value __min = __glibcxx_min(_Value);
63       static const _Value __max = __glibcxx_max(_Value);
64
65       // NB: these two also available in std::numeric_limits as compile
66       // time constants, but <limits> is big and we avoid including it.
67       static const bool __is_signed = __glibcxx_signed(_Value);
68       static const int __digits = __glibcxx_digits(_Value);      
69     };
70
71   template<typename _Value>
72     const _Value __numeric_traits_integer<_Value>::__min;
73
74   template<typename _Value>
75     const _Value __numeric_traits_integer<_Value>::__max;
76
77   template<typename _Value>
78     const bool __numeric_traits_integer<_Value>::__is_signed;
79
80   template<typename _Value>
81     const int __numeric_traits_integer<_Value>::__digits;
82
83 #undef __glibcxx_signed
84 #undef __glibcxx_digits
85 #undef __glibcxx_min
86 #undef __glibcxx_max
87
88 #define __glibcxx_floating(_Tp, _Fval, _Dval, _LDval) \
89   (std::__are_same<_Tp, float>::__value ? _Fval \
90    : std::__are_same<_Tp, double>::__value ? _Dval : _LDval)
91
92 #define __glibcxx_max_digits10(_Tp) \
93   (2 + __glibcxx_floating(_Tp, __FLT_MANT_DIG__, __DBL_MANT_DIG__, \
94                           __LDBL_MANT_DIG__) * 3010 / 10000)
95
96 #define __glibcxx_digits10(_Tp) \
97   __glibcxx_floating(_Tp, __FLT_DIG__, __DBL_DIG__, __LDBL_DIG__)
98
99 #define __glibcxx_max_exponent10(_Tp) \
100   __glibcxx_floating(_Tp, __FLT_MAX_10_EXP__, __DBL_MAX_10_EXP__, \
101                      __LDBL_MAX_10_EXP__)
102
103   template<typename _Value>
104     struct __numeric_traits_floating
105     {
106       // Only floating point types. See N1822. 
107       static const int __max_digits10 = __glibcxx_max_digits10(_Value);
108
109       // See above comment...
110       static const bool __is_signed = true;
111       static const int __digits10 = __glibcxx_digits10(_Value);
112       static const int __max_exponent10 = __glibcxx_max_exponent10(_Value);
113     };
114
115   template<typename _Value>
116     const int __numeric_traits_floating<_Value>::__max_digits10;
117
118   template<typename _Value>
119     const bool __numeric_traits_floating<_Value>::__is_signed;
120
121   template<typename _Value>
122     const int __numeric_traits_floating<_Value>::__digits10;
123
124   template<typename _Value>
125     const int __numeric_traits_floating<_Value>::__max_exponent10;
126
127   template<typename _Value>
128     struct __numeric_traits
129     : public __conditional_type<std::__is_integer<_Value>::__value,
130                                 __numeric_traits_integer<_Value>,
131                                 __numeric_traits_floating<_Value> >::__type
132     { };
133
134 _GLIBCXX_END_NAMESPACE
135
136 #undef __glibcxx_floating
137 #undef __glibcxx_max_digits10
138 #undef __glibcxx_digits10
139 #undef __glibcxx_max_exponent10
140
141 #endif