Embedded Template Library  1.0
integral_limits.h
Go to the documentation of this file.
1 
3 /******************************************************************************
4 The MIT License(MIT)
5 
6 Embedded Template Library.
7 https://github.com/ETLCPP/etl
8 https://www.etlcpp.com
9 
10 Copyright(c) 2014 jwellbelove
11 
12 Permission is hereby granted, free of charge, to any person obtaining a copy
13 of this software and associated documentation files(the "Software"), to deal
14 in the Software without restriction, including without limitation the rights
15 to use, copy, modify, merge, publish, distribute, sublicense, and / or sell
16 copies of the Software, and to permit persons to whom the Software is
17 furnished to do so, subject to the following conditions :
18 
19 The above copyright notice and this permission notice shall be included in all
20 copies or substantial portions of the Software.
21 
22 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
23 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
24 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE
25 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
26 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
27 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
28 SOFTWARE.
29 ******************************************************************************/
30 
31 #ifndef ETL_INTEGRAL_LIMITS_INCLUDED
32 #define ETL_INTEGRAL_LIMITS_INCLUDED
33 
34 #include <stddef.h>
35 #include <limits.h>
36 
37 #include "platform.h"
38 #include "type_traits.h"
39 
40 #include "private/minmax_push.h"
41 
42 //*****************************************************************************
46 //*****************************************************************************
47 
48 namespace etl
49 {
50  //***************************************************************************
52  //***************************************************************************
53  template <typename T>
55 
56  //***************************************************************************
58  //***************************************************************************
59  template <>
60  struct integral_limits<void>
61  {
62  static const int min = 0;
63  static const int max = 0;
64  static const int bits = 0;
65  static const bool is_signed = false;
66  };
67 
68  //***************************************************************************
70  //***************************************************************************
71  template <>
72  struct integral_limits<signed char>
73  {
74  static const signed char min = SCHAR_MIN;
75  static const signed char max = SCHAR_MAX;
76  static const int bits = CHAR_BIT;
78  };
79 
80  //***************************************************************************
82  //***************************************************************************
83  template <>
84  struct integral_limits<unsigned char>
85  {
86  static const unsigned char min = 0;
87  static const unsigned char max = UCHAR_MAX;
88  static const int bits = CHAR_BIT;
90  };
91 
92  //***************************************************************************
94  //***************************************************************************
95  template <>
96  struct integral_limits<char>
97  {
98  static const char min = (etl::is_signed<char>::value) ? SCHAR_MIN : 0;
99  static const char max = (etl::is_signed<char>::value) ? SCHAR_MAX : char(UCHAR_MAX);
100  static const int bits = CHAR_BIT;
101  static const bool is_signed = etl::is_signed<char>::value;
102  };
103 
104  //***************************************************************************
106  //***************************************************************************
107  template <>
108  struct integral_limits<short>
109  {
110  static const short min = SHRT_MIN;
111  static const short max = SHRT_MAX;
112  static const int bits = CHAR_BIT * (sizeof(short) / sizeof(char));
113  static const bool is_signed = etl::is_signed<short>::value;
114  };
115 
116  //***************************************************************************
118  //***************************************************************************
119  template <>
120  struct integral_limits<unsigned short>
121  {
122  static const unsigned short min = 0;
123  static const unsigned short max = USHRT_MAX;
124  static const int bits = CHAR_BIT * (sizeof(unsigned short) / sizeof(char));
126  };
127 
128  //***************************************************************************
130  //***************************************************************************
131  template <>
132  struct integral_limits<int>
133  {
134  static const int min = INT_MIN;
135  static const int max = INT_MAX;
136  static const int bits = CHAR_BIT * (sizeof(int) / sizeof(char));
137  static const bool is_signed = etl::is_signed<int>::value;
138  };
139 
140  //***************************************************************************
142  //***************************************************************************
143  template <>
144  struct integral_limits<unsigned int>
145  {
146  static const unsigned int min = 0;
147  static const unsigned int max = UINT_MAX;
148  static const int bits = CHAR_BIT * (sizeof(unsigned int) / sizeof(char));
150  };
151 
152  //***************************************************************************
154  //***************************************************************************
155  template <>
156  struct integral_limits<long>
157  {
158  static const long min = LONG_MIN;
159  static const long max = LONG_MAX;
160  static const int bits = CHAR_BIT * (sizeof(long) / sizeof(char));
161  static const bool is_signed = etl::is_signed<long>::value;
162  };
163 
164  //***************************************************************************
166  //***************************************************************************
167  template <>
168  struct integral_limits<unsigned long>
169  {
170  static const unsigned long min = 0;
171  static const unsigned long max = ULONG_MAX;
172  static const int bits = CHAR_BIT * (sizeof(unsigned long) / sizeof(char));
174  };
175 
176 #ifndef LLONG_MAX
177 #define LLONG_MAX 9223372036854775807LL
178 #endif
179 
180 #ifndef LLONG_MIN
181 #define LLONG_MIN (-LLONG_MAX - 1LL)
182 #endif
183 
184 #ifndef ULLONG_MAX
185 #define ULLONG_MAX 18446744073709551615ULL
186 #endif
187 
188  //***************************************************************************
190  //***************************************************************************
191  template <>
192  struct integral_limits<long long>
193  {
194  static const long long min = LLONG_MIN;
195  static const long long max = LLONG_MAX;
196  static const int bits = CHAR_BIT * (sizeof(long long) / sizeof(char));
197  static const bool is_signed = etl::is_signed<long long>::value;
198  };
199 
200  //***************************************************************************
202  //***************************************************************************
203  template <>
204  struct integral_limits<unsigned long long>
205  {
206  static const unsigned long long min = 0;
207  static const unsigned long long max = ULLONG_MAX;
208  static const int bits = CHAR_BIT * (sizeof(unsigned long long) / sizeof(char));
210  };
211 }
212 
213 #include "private/minmax_pop.h"
214 
215 #endif
Definition: integral_limits.h:54
is_signed
Definition: type_traits_generator.h:951
Definition: absolute.h:37