Embedded Template Library 1.0
Loading...
Searching...
No Matches
integral_limits.h
Go to the documentation of this file.
1
2
3/******************************************************************************
4The MIT License(MIT)
5
6Embedded Template Library.
7https://github.com/ETLCPP/etl
8https://www.etlcpp.com
9
10Copyright(c) 2014 John Wellbelove
11
12Permission is hereby granted, free of charge, to any person obtaining a copy
13of this software and associated documentation files(the "Software"), to deal
14in the Software without restriction, including without limitation the rights
15to use, copy, modify, merge, publish, distribute, sublicense, and / or sell
16copies of the Software, and to permit persons to whom the Software is
17furnished to do so, subject to the following conditions :
18
19The above copyright notice and this permission notice shall be included in all
20copies or substantial portions of the Software.
21
22THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
23IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
24FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE
25AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
26LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
27OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
28SOFTWARE.
29******************************************************************************/
30
31#ifndef ETL_INTEGRAL_LIMITS_INCLUDED
32#define ETL_INTEGRAL_LIMITS_INCLUDED
33
34#include "platform.h"
35#include "type_traits.h"
36
37#include <stddef.h>
38#include <limits.h>
39
40#include "private/minmax_push.h"
41
42//*****************************************************************************
46//*****************************************************************************
47
48#ifndef LLONG_MAX
49 #define LLONG_MAX 9223372036854775807LL
50#endif
51
52#ifndef LLONG_MIN
53 #define LLONG_MIN (-LLONG_MAX - 1LL)
54#endif
55
56#ifndef ULLONG_MAX
57 #define ULLONG_MAX 18446744073709551615ULL
58#endif
59
60namespace etl
61{
62 namespace private_integral_limits
63 {
64 //*****************************************************************************
71 //*****************************************************************************
72
73 //*********************************
74 // signed char
75 template <typename T = void>
77 {
78 typedef signed char value_type;
79
80 static ETL_CONSTANT signed char min = SCHAR_MIN;
81 static ETL_CONSTANT signed char max = SCHAR_MAX;
82 static ETL_CONSTANT int bits = CHAR_BIT;
83 static ETL_CONSTANT bool is_signed = etl::is_signed<signed char>::value;
84 };
85
86 template <typename T>
87 ETL_CONSTANT signed char statics_signed_char<T>::min;
88
89 template <typename T>
90 ETL_CONSTANT signed char statics_signed_char<T>::max;
91
92 template <typename T>
93 ETL_CONSTANT int statics_signed_char<T>::bits;
94
95 template <typename T>
96 ETL_CONSTANT bool statics_signed_char<T>::is_signed;
97
98 //***********************************
99 // unsigned char
100 template <typename T = void>
102 {
103 typedef unsigned char value_type;
104
105 static ETL_CONSTANT unsigned char min = 0;
106 static ETL_CONSTANT unsigned char max = UCHAR_MAX;
107 static ETL_CONSTANT int bits = CHAR_BIT;
108 static ETL_CONSTANT bool is_signed = etl::is_signed<unsigned char>::value;
109 };
110
111 template <typename T>
112 ETL_CONSTANT unsigned char statics_unsigned_char<T>::min;
113
114 template <typename T>
115 ETL_CONSTANT unsigned char statics_unsigned_char<T>::max;
116
117 template <typename T>
118 ETL_CONSTANT int statics_unsigned_char<T>::bits;
119
120 template <typename T>
121 ETL_CONSTANT bool statics_unsigned_char<T>::is_signed;
122
123 //***********************************
124 // char
125 template <typename T = void>
127 {
128 typedef char value_type;
129
130 static ETL_CONSTANT char min = (etl::is_signed<char>::value) ? SCHAR_MIN : 0;
131 static ETL_CONSTANT char max = (etl::is_signed<char>::value) ? SCHAR_MAX : static_cast<char>(UCHAR_MAX);
132 static ETL_CONSTANT int bits = CHAR_BIT;
133 static ETL_CONSTANT bool is_signed = etl::is_signed<char>::value;
134 };
135
136 template <typename T>
137 ETL_CONSTANT char statics_char<T>::min;
138
139 template <typename T>
140 ETL_CONSTANT char statics_char<T>::max;
141
142 template <typename T>
143 ETL_CONSTANT int statics_char<T>::bits;
144
145 template <typename T>
146 ETL_CONSTANT bool statics_char<T>::is_signed;
147
148 //***********************************
149 // wchar_t
150 template <typename T = void>
152 {
153 typedef wchar_t value_type;
154
155 static ETL_CONSTANT wchar_t min = WCHAR_MIN;
156 static ETL_CONSTANT wchar_t max = WCHAR_MAX;
157 static ETL_CONSTANT int bits = CHAR_BIT * sizeof(wchar_t);
158 static ETL_CONSTANT bool is_signed = etl::is_signed<wchar_t>::value;
159 };
160
161 template <typename T>
162 ETL_CONSTANT wchar_t statics_wchar_t<T>::min;
163
164 template <typename T>
165 ETL_CONSTANT wchar_t statics_wchar_t<T>::max;
166
167 template <typename T>
168 ETL_CONSTANT int statics_wchar_t<T>::bits;
169
170 template <typename T>
171 ETL_CONSTANT bool statics_wchar_t<T>::is_signed;
172
173 //***********************************
174 // short
175#if defined(ETL_COMPILER_MICROSOFT)
176 #pragma warning(push)
177 #pragma warning(disable : 4309)
178#endif
179
180 template <typename T = void>
182 {
183 typedef short value_type;
184
185 static ETL_CONSTANT short min = SHRT_MIN;
186 static ETL_CONSTANT short max = SHRT_MAX;
187 static ETL_CONSTANT int bits = CHAR_BIT * (sizeof(short) / sizeof(char));
188 static ETL_CONSTANT bool is_signed = etl::is_signed<short>::value;
189 };
190
191 template <typename T>
192 ETL_CONSTANT short statics_short<T>::min;
193
194 template <typename T>
195 ETL_CONSTANT short statics_short<T>::max;
196
197 template <typename T>
198 ETL_CONSTANT int statics_short<T>::bits;
199
200 template <typename T>
201 ETL_CONSTANT bool statics_short<T>::is_signed;
202
203#if defined(ETL_COMPILER_MICROSOFT)
204 #pragma warning(pop)
205#endif
206
207 //***********************************
208 // unsigned short
209 template <typename T = void>
211 {
212 typedef unsigned short value_type;
213
214 static ETL_CONSTANT unsigned short min = 0;
215 static ETL_CONSTANT unsigned short max = USHRT_MAX;
216 static ETL_CONSTANT int bits = CHAR_BIT * (sizeof(unsigned short) / sizeof(char));
217 static ETL_CONSTANT bool is_signed = etl::is_signed<unsigned short>::value;
218 };
219
220 template <typename T>
221 ETL_CONSTANT unsigned short statics_unsigned_short<T>::min;
222
223 template <typename T>
224 ETL_CONSTANT unsigned short statics_unsigned_short<T>::max;
225
226 template <typename T>
227 ETL_CONSTANT int statics_unsigned_short<T>::bits;
228
229 template <typename T>
230 ETL_CONSTANT bool statics_unsigned_short<T>::is_signed;
231
232 //***********************************
233 // int
234 template <typename T = void>
236 {
237 typedef int value_type;
238
239 static ETL_CONSTANT int min = INT_MIN;
240 static ETL_CONSTANT int max = INT_MAX;
241 static ETL_CONSTANT int bits = CHAR_BIT * (sizeof(int) / sizeof(char));
242 static ETL_CONSTANT bool is_signed = etl::is_signed<int>::value;
243 };
244
245 template <typename T>
246 ETL_CONSTANT int statics_int<T>::min;
247
248 template <typename T>
249 ETL_CONSTANT int statics_int<T>::max;
250
251 template <typename T>
252 ETL_CONSTANT int statics_int<T>::bits;
253
254 template <typename T>
255 ETL_CONSTANT bool statics_int<T>::is_signed;
256
257 //***********************************
258 // unsigned int
259 template <typename T = void>
261 {
262 typedef unsigned int value_type;
263
264 static ETL_CONSTANT unsigned int min = 0;
265 static ETL_CONSTANT unsigned int max = UINT_MAX;
266 static ETL_CONSTANT int bits = CHAR_BIT * (sizeof(unsigned int) / sizeof(char));
267 static ETL_CONSTANT bool is_signed = etl::is_signed<unsigned int>::value;
268 };
269
270 template <typename T>
271 ETL_CONSTANT unsigned int statics_unsigned_int<T>::min;
272
273 template <typename T>
274 ETL_CONSTANT unsigned int statics_unsigned_int<T>::max;
275
276 template <typename T>
277 ETL_CONSTANT int statics_unsigned_int<T>::bits;
278
279 template <typename T>
280 ETL_CONSTANT bool statics_unsigned_int<T>::is_signed;
281
282 //***********************************
283 // long
284 template <typename T = void>
286 {
287 typedef long value_type;
288
289 static ETL_CONSTANT long min = LONG_MIN;
290 static ETL_CONSTANT long max = LONG_MAX;
291 static ETL_CONSTANT int bits = CHAR_BIT * (sizeof(long) / sizeof(char));
292 static ETL_CONSTANT bool is_signed = etl::is_signed<long>::value;
293 };
294
295 template <typename T>
296 ETL_CONSTANT long statics_long<T>::min;
297
298 template <typename T>
299 ETL_CONSTANT long statics_long<T>::max;
300
301 template <typename T>
302 ETL_CONSTANT int statics_long<T>::bits;
303
304 template <typename T>
305 ETL_CONSTANT bool statics_long<T>::is_signed;
306
307 //***********************************
308 // unsigned long
309 template <typename T = void>
311 {
312 typedef unsigned long value_type;
313
314 static ETL_CONSTANT unsigned long min = 0;
315 static ETL_CONSTANT unsigned long max = ULONG_MAX;
316 static ETL_CONSTANT int bits = CHAR_BIT * (sizeof(unsigned long) / sizeof(char));
317 static ETL_CONSTANT bool is_signed = etl::is_signed<unsigned long>::value;
318 };
319
320 template <typename T>
321 ETL_CONSTANT unsigned long statics_unsigned_long<T>::min;
322
323 template <typename T>
324 ETL_CONSTANT unsigned long statics_unsigned_long<T>::max;
325
326 template <typename T>
327 ETL_CONSTANT int statics_unsigned_long<T>::bits;
328
329 template <typename T>
330 ETL_CONSTANT bool statics_unsigned_long<T>::is_signed;
331
332 //***********************************
333 // long long
334 template <typename T = void>
336 {
337 typedef long long value_type;
338
339 static ETL_CONSTANT long long min = LLONG_MIN;
340 static ETL_CONSTANT long long max = LLONG_MAX;
341 static ETL_CONSTANT int bits = CHAR_BIT * (sizeof(long long) / sizeof(char));
342 static ETL_CONSTANT bool is_signed = etl::is_signed<long long>::value;
343 };
344
345 template <typename T>
346 ETL_CONSTANT long long statics_long_long<T>::min;
347
348 template <typename T>
349 ETL_CONSTANT long long statics_long_long<T>::max;
350
351 template <typename T>
352 ETL_CONSTANT int statics_long_long<T>::bits;
353
354 template <typename T>
355 ETL_CONSTANT bool statics_long_long<T>::is_signed;
356
357 //***********************************
358 // unsigned long long
359 template <typename T = void>
361 {
362 typedef unsigned long value_type;
363
364 static ETL_CONSTANT unsigned long long min = 0;
365 static ETL_CONSTANT unsigned long long max = ULLONG_MAX;
366 static ETL_CONSTANT int bits = CHAR_BIT * (sizeof(unsigned long long) / sizeof(char));
367 static ETL_CONSTANT bool is_signed = etl::is_signed<unsigned long long>::value;
368 };
369
370 template <typename T>
371 ETL_CONSTANT unsigned long long statics_unsigned_long_long<T>::min;
372
373 template <typename T>
374 ETL_CONSTANT unsigned long long statics_unsigned_long_long<T>::max;
375
376 template <typename T>
378
379 template <typename T>
381
382#if ETL_HAS_NATIVE_CHAR8_T
383 //***********************************
384 // char8_t
385 template <typename T = void>
386 struct statics_char8_t
387 {
388 typedef char8_t value_type;
389
390 static ETL_CONSTANT char8_t min = (etl::is_signed<char8_t>::value) ? SCHAR_MIN : 0;
391 static ETL_CONSTANT char8_t max = (etl::is_signed<char8_t>::value) ? SCHAR_MAX : static_cast<char8_t>(UCHAR_MAX);
392 static ETL_CONSTANT int bits = CHAR_BIT;
393 static ETL_CONSTANT bool is_signed = etl::is_signed<char8_t>::value;
394 };
395
396 template <typename T>
397 ETL_CONSTANT char8_t statics_char8_t<T>::min;
398
399 template <typename T>
400 ETL_CONSTANT char8_t statics_char8_t<T>::max;
401
402 template <typename T>
403 ETL_CONSTANT int statics_char8_t<T>::bits;
404
405 template <typename T>
406 ETL_CONSTANT bool statics_char8_t<T>::is_signed;
407#endif
408
409#if ETL_HAS_NATIVE_CHAR16_T
410 //***********************************
411 // char16_t
412 template <typename T = void>
413 struct statics_char16_t
414 {
415 typedef char16_t value_type;
416
417 static ETL_CONSTANT char16_t min = 0;
418 static ETL_CONSTANT char16_t max = 0xFFFFU;
419 static ETL_CONSTANT int bits = 16;
420 static ETL_CONSTANT bool is_signed = false;
421 };
422
423 template <typename T>
424 ETL_CONSTANT char16_t statics_char16_t<T>::min;
425
426 template <typename T>
427 ETL_CONSTANT char16_t statics_char16_t<T>::max;
428
429 template <typename T>
430 ETL_CONSTANT int statics_char16_t<T>::bits;
431
432 template <typename T>
433 ETL_CONSTANT bool statics_char16_t<T>::is_signed;
434#endif
435
436#if ETL_HAS_NATIVE_CHAR32_T
437 //***********************************
438 // char32_t
439 template <typename T = void>
440 struct statics_char32_t
441 {
442 typedef char32_t value_type;
443
444 static ETL_CONSTANT char32_t min = 0;
445 static ETL_CONSTANT char32_t max = 0xFFFFFFFFU;
446 static ETL_CONSTANT int bits = 32;
447 static ETL_CONSTANT bool is_signed = false;
448 };
449
450 template <typename T>
451 ETL_CONSTANT char32_t statics_char32_t<T>::min;
452
453 template <typename T>
454 ETL_CONSTANT char32_t statics_char32_t<T>::max;
455
456 template <typename T>
457 ETL_CONSTANT int statics_char32_t<T>::bits;
458
459 template <typename T>
460 ETL_CONSTANT bool statics_char32_t<T>::is_signed;
461#endif
462
463#if ETL_USING_20BIT_TYPES
464template <typename T = void>
465 struct statics___int20
466 {
467 typedef __int20 value_type;
468
469 static ETL_CONSTANT __int20 min = 0x80000;
470 static ETL_CONSTANT __int20 max = 0x7FFFF;
471 static ETL_CONSTANT int bits = 20;
472 static ETL_CONSTANT bool is_signed = true;
473 };
474
475 template <typename T>
476 ETL_CONSTANT __int20 statics___int20<T>::min;
477
478 template <typename T>
479 ETL_CONSTANT __int20 statics___int20<T>::max;
480
481 template <typename T>
482 ETL_CONSTANT int statics___int20<T>::bits;
483
484 template <typename T>
485 ETL_CONSTANT bool statics___int20<T>::is_signed;
486
487 template <typename T = void>
488 struct statics_unsigned___int20
489 {
490 typedef unsigned __int20 value_type;
491
492 static ETL_CONSTANT unsigned __int20 min = 0;
493 static ETL_CONSTANT unsigned __int20 max = 0xFFFFF;
494 static ETL_CONSTANT int bits = 20;
495 static ETL_CONSTANT bool is_signed = false;
496 };
497
498 template <typename T>
499 ETL_CONSTANT unsigned __int20 statics_unsigned___int20<T>::min;
500
501 template <typename T>
502 ETL_CONSTANT unsigned __int20 statics_unsigned___int20<T>::max;
503
504 template <typename T>
505 ETL_CONSTANT int statics_unsigned___int20<T>::bits;
506
507 template <typename T>
508 ETL_CONSTANT bool statics_unsigned___int20<T>::is_signed;
509#endif
510 }
511
512 //***************************************************************************
514 //***************************************************************************
515 template <typename T>
517
518 //***************************************************************************
520 //***************************************************************************
521 template <>
525
526 //***************************************************************************
528 //***************************************************************************
529 template <>
533
534 //***************************************************************************
536 //***************************************************************************
537
538 template <>
540 {
541 typedef char value_type;
542 };
543
544 //***************************************************************************
546 //***************************************************************************
547 template <>
551
552 //***************************************************************************
554 //***************************************************************************
555 template <>
559
560 //***************************************************************************
562 //***************************************************************************
563 template <>
567
568 //***************************************************************************
570 //***************************************************************************
571 template <>
575
576 //***************************************************************************
578 //***************************************************************************
579 template <>
583
584 //***************************************************************************
586 //***************************************************************************
587 template <>
591
592 //***************************************************************************
594 //***************************************************************************
595 template <>
599
600 //***************************************************************************
602 //***************************************************************************
603 template <>
607
608 #if ETL_USING_20BIT_TYPES
609 //***************************************************************************
611 //***************************************************************************
612 template <>
613 struct integral_limits<__int20> : public private_integral_limits::statics___int20<>
614 {
615 };
616
617 template <>
618 struct integral_limits<unsigned __int20> : public private_integral_limits::statics_unsigned___int20<>
619 {
620 };
621 #endif
622}
623
624#include "private/minmax_pop.h"
625
626#endif
Definition integral_limits.h:516
is_signed
Definition type_traits_generator.h:1011
bitset_ext
Definition absolute.h:38
pair holds two objects of arbitrary type
Definition utility.h:164
Definition integral_limits.h:127
Definition integral_limits.h:236
Definition integral_limits.h:336
Definition integral_limits.h:286
Definition integral_limits.h:182
Definition integral_limits.h:152