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 <limits.h>
38#include <stddef.h>
39
40#include "private/minmax_push.h"
41
42//*****************************************************************************
47//*****************************************************************************
48
49#ifndef LLONG_MAX
50 #define LLONG_MAX 9223372036854775807LL
51#endif
52
53#ifndef LLONG_MIN
54 #define LLONG_MIN (-LLONG_MAX - 1LL)
55#endif
56
57#ifndef ULLONG_MAX
58 #define ULLONG_MAX 18446744073709551615ULL
59#endif
60
61namespace etl
62{
63 namespace private_integral_limits
64 {
65 //*****************************************************************************
73 //*****************************************************************************
74
75 //*********************************
76 // signed char
77 template <typename T = void>
79 {
80 typedef signed char value_type;
81
82 static ETL_CONSTANT signed char min = SCHAR_MIN;
83 static ETL_CONSTANT signed char max = SCHAR_MAX;
84 static ETL_CONSTANT int bits = CHAR_BIT;
85 static ETL_CONSTANT bool is_signed = etl::is_signed<signed char>::value;
86 };
87
88 template <typename T>
89 ETL_CONSTANT signed char statics_signed_char<T>::min;
90
91 template <typename T>
92 ETL_CONSTANT signed char statics_signed_char<T>::max;
93
94 template <typename T>
95 ETL_CONSTANT int statics_signed_char<T>::bits;
96
97 template <typename T>
98 ETL_CONSTANT bool statics_signed_char<T>::is_signed;
99
100 //***********************************
101 // unsigned char
102 template <typename T = void>
104 {
105 typedef unsigned char value_type;
106
107 static ETL_CONSTANT unsigned char min = 0;
108 static ETL_CONSTANT unsigned char max = UCHAR_MAX;
109 static ETL_CONSTANT int bits = CHAR_BIT;
110 static ETL_CONSTANT bool is_signed = etl::is_signed<unsigned char>::value;
111 };
112
113 template <typename T>
114 ETL_CONSTANT unsigned char statics_unsigned_char<T>::min;
115
116 template <typename T>
117 ETL_CONSTANT unsigned char statics_unsigned_char<T>::max;
118
119 template <typename T>
120 ETL_CONSTANT int statics_unsigned_char<T>::bits;
121
122 template <typename T>
123 ETL_CONSTANT bool statics_unsigned_char<T>::is_signed;
124
125 //***********************************
126 // char
127 template <typename T = void>
129 {
130 typedef char value_type;
131
132 static ETL_CONSTANT char min = (etl::is_signed<char>::value) ? SCHAR_MIN : 0;
133 static ETL_CONSTANT char max = (etl::is_signed<char>::value) ? SCHAR_MAX : static_cast<char>(UCHAR_MAX);
134 static ETL_CONSTANT int bits = CHAR_BIT;
135 static ETL_CONSTANT bool is_signed = etl::is_signed<char>::value;
136 };
137
138 template <typename T>
139 ETL_CONSTANT char statics_char<T>::min;
140
141 template <typename T>
142 ETL_CONSTANT char statics_char<T>::max;
143
144 template <typename T>
145 ETL_CONSTANT int statics_char<T>::bits;
146
147 template <typename T>
148 ETL_CONSTANT bool statics_char<T>::is_signed;
149
150 //***********************************
151 // wchar_t
152 template <typename T = void>
154 {
155 typedef wchar_t value_type;
156
157 static ETL_CONSTANT wchar_t min = WCHAR_MIN;
158 static ETL_CONSTANT wchar_t max = WCHAR_MAX;
159 static ETL_CONSTANT int bits = CHAR_BIT * sizeof(wchar_t);
160 static ETL_CONSTANT bool is_signed = etl::is_signed<wchar_t>::value;
161 };
162
163 template <typename T>
164 ETL_CONSTANT wchar_t statics_wchar_t<T>::min;
165
166 template <typename T>
167 ETL_CONSTANT wchar_t statics_wchar_t<T>::max;
168
169 template <typename T>
170 ETL_CONSTANT int statics_wchar_t<T>::bits;
171
172 template <typename T>
173 ETL_CONSTANT bool statics_wchar_t<T>::is_signed;
174
175 //***********************************
176 // short
177#if defined(ETL_COMPILER_MICROSOFT)
178 #pragma warning(push)
179 #pragma warning(disable : 4309)
180#endif
181
182 template <typename T = void>
184 {
185 typedef short value_type;
186
187 static ETL_CONSTANT short min = SHRT_MIN;
188 static ETL_CONSTANT short max = SHRT_MAX;
189 static ETL_CONSTANT int bits = CHAR_BIT * (sizeof(short) / sizeof(char));
190 static ETL_CONSTANT bool is_signed = etl::is_signed<short>::value;
191 };
192
193 template <typename T>
194 ETL_CONSTANT short statics_short<T>::min;
195
196 template <typename T>
197 ETL_CONSTANT short statics_short<T>::max;
198
199 template <typename T>
200 ETL_CONSTANT int statics_short<T>::bits;
201
202 template <typename T>
203 ETL_CONSTANT bool statics_short<T>::is_signed;
204
205#if defined(ETL_COMPILER_MICROSOFT)
206 #pragma warning(pop)
207#endif
208
209 //***********************************
210 // unsigned short
211 template <typename T = void>
213 {
214 typedef unsigned short value_type;
215
216 static ETL_CONSTANT unsigned short min = 0;
217 static ETL_CONSTANT unsigned short max = USHRT_MAX;
218 static ETL_CONSTANT int bits = CHAR_BIT * (sizeof(unsigned short) / sizeof(char));
219 static ETL_CONSTANT bool is_signed = etl::is_signed<unsigned short>::value;
220 };
221
222 template <typename T>
223 ETL_CONSTANT unsigned short statics_unsigned_short<T>::min;
224
225 template <typename T>
226 ETL_CONSTANT unsigned short statics_unsigned_short<T>::max;
227
228 template <typename T>
229 ETL_CONSTANT int statics_unsigned_short<T>::bits;
230
231 template <typename T>
232 ETL_CONSTANT bool statics_unsigned_short<T>::is_signed;
233
234 //***********************************
235 // int
236 template <typename T = void>
238 {
239 typedef int value_type;
240
241 static ETL_CONSTANT int min = INT_MIN;
242 static ETL_CONSTANT int max = INT_MAX;
243 static ETL_CONSTANT int bits = CHAR_BIT * (sizeof(int) / sizeof(char));
244 static ETL_CONSTANT bool is_signed = etl::is_signed<int>::value;
245 };
246
247 template <typename T>
248 ETL_CONSTANT int statics_int<T>::min;
249
250 template <typename T>
251 ETL_CONSTANT int statics_int<T>::max;
252
253 template <typename T>
254 ETL_CONSTANT int statics_int<T>::bits;
255
256 template <typename T>
257 ETL_CONSTANT bool statics_int<T>::is_signed;
258
259 //***********************************
260 // unsigned int
261 template <typename T = void>
263 {
264 typedef unsigned int value_type;
265
266 static ETL_CONSTANT unsigned int min = 0;
267 static ETL_CONSTANT unsigned int max = UINT_MAX;
268 static ETL_CONSTANT int bits = CHAR_BIT * (sizeof(unsigned int) / sizeof(char));
269 static ETL_CONSTANT bool is_signed = etl::is_signed<unsigned int>::value;
270 };
271
272 template <typename T>
273 ETL_CONSTANT unsigned int statics_unsigned_int<T>::min;
274
275 template <typename T>
276 ETL_CONSTANT unsigned int statics_unsigned_int<T>::max;
277
278 template <typename T>
279 ETL_CONSTANT int statics_unsigned_int<T>::bits;
280
281 template <typename T>
282 ETL_CONSTANT bool statics_unsigned_int<T>::is_signed;
283
284 //***********************************
285 // long
286 template <typename T = void>
288 {
289 typedef long value_type;
290
291 static ETL_CONSTANT long min = LONG_MIN;
292 static ETL_CONSTANT long max = LONG_MAX;
293 static ETL_CONSTANT int bits = CHAR_BIT * (sizeof(long) / sizeof(char));
294 static ETL_CONSTANT bool is_signed = etl::is_signed<long>::value;
295 };
296
297 template <typename T>
298 ETL_CONSTANT long statics_long<T>::min;
299
300 template <typename T>
301 ETL_CONSTANT long statics_long<T>::max;
302
303 template <typename T>
304 ETL_CONSTANT int statics_long<T>::bits;
305
306 template <typename T>
307 ETL_CONSTANT bool statics_long<T>::is_signed;
308
309 //***********************************
310 // unsigned long
311 template <typename T = void>
313 {
314 typedef unsigned long value_type;
315
316 static ETL_CONSTANT unsigned long min = 0;
317 static ETL_CONSTANT unsigned long max = ULONG_MAX;
318 static ETL_CONSTANT int bits = CHAR_BIT * (sizeof(unsigned long) / sizeof(char));
319 static ETL_CONSTANT bool is_signed = etl::is_signed<unsigned long>::value;
320 };
321
322 template <typename T>
323 ETL_CONSTANT unsigned long statics_unsigned_long<T>::min;
324
325 template <typename T>
326 ETL_CONSTANT unsigned long statics_unsigned_long<T>::max;
327
328 template <typename T>
329 ETL_CONSTANT int statics_unsigned_long<T>::bits;
330
331 template <typename T>
332 ETL_CONSTANT bool statics_unsigned_long<T>::is_signed;
333
334 //***********************************
335 // long long
336 template <typename T = void>
338 {
339 typedef long long value_type;
340
341 static ETL_CONSTANT long long min = LLONG_MIN;
342 static ETL_CONSTANT long long max = LLONG_MAX;
343 static ETL_CONSTANT int bits = CHAR_BIT * (sizeof(long long) / sizeof(char));
344 static ETL_CONSTANT bool is_signed = etl::is_signed<long long>::value;
345 };
346
347 template <typename T>
348 ETL_CONSTANT long long statics_long_long<T>::min;
349
350 template <typename T>
351 ETL_CONSTANT long long statics_long_long<T>::max;
352
353 template <typename T>
354 ETL_CONSTANT int statics_long_long<T>::bits;
355
356 template <typename T>
357 ETL_CONSTANT bool statics_long_long<T>::is_signed;
358
359 //***********************************
360 // unsigned long long
361 template <typename T = void>
363 {
364 typedef unsigned long value_type;
365
366 static ETL_CONSTANT unsigned long long min = 0;
367 static ETL_CONSTANT unsigned long long max = ULLONG_MAX;
368 static ETL_CONSTANT int bits = CHAR_BIT * (sizeof(unsigned long long) / sizeof(char));
369 static ETL_CONSTANT bool is_signed = etl::is_signed<unsigned long long>::value;
370 };
371
372 template <typename T>
373 ETL_CONSTANT unsigned long long statics_unsigned_long_long<T>::min;
374
375 template <typename T>
376 ETL_CONSTANT unsigned long long statics_unsigned_long_long<T>::max;
377
378 template <typename T>
379 ETL_CONSTANT int statics_unsigned_long_long<T>::bits;
380
381 template <typename T>
382 ETL_CONSTANT bool statics_unsigned_long_long<T>::is_signed;
383
384#if ETL_HAS_NATIVE_CHAR8_T
385 //***********************************
386 // char8_t
387 template <typename T = void>
388 struct statics_char8_t
389 {
390 typedef char8_t value_type;
391
392 static ETL_CONSTANT char8_t min = static_cast<char8_t>((etl::is_signed<char8_t>::value) ? SCHAR_MIN : 0);
393 static ETL_CONSTANT char8_t max = (etl::is_signed<char8_t>::value) ? static_cast<char8_t>(SCHAR_MAX) : static_cast<char8_t>(UCHAR_MAX);
394 static ETL_CONSTANT int bits = CHAR_BIT;
395 static ETL_CONSTANT bool is_signed = etl::is_signed<char8_t>::value;
396 };
397
398 template <typename T>
399 ETL_CONSTANT char8_t statics_char8_t<T>::min;
400
401 template <typename T>
402 ETL_CONSTANT char8_t statics_char8_t<T>::max;
403
404 template <typename T>
405 ETL_CONSTANT int statics_char8_t<T>::bits;
406
407 template <typename T>
408 ETL_CONSTANT bool statics_char8_t<T>::is_signed;
409#endif
410
411#if ETL_HAS_NATIVE_CHAR16_T
412 //***********************************
413 // char16_t
414 template <typename T = void>
415 struct statics_char16_t
416 {
417 typedef char16_t value_type;
418
419 static ETL_CONSTANT char16_t min = 0;
420 static ETL_CONSTANT char16_t max = 0xFFFFU;
421 static ETL_CONSTANT int bits = 16;
422 static ETL_CONSTANT bool is_signed = false;
423 };
424
425 template <typename T>
426 ETL_CONSTANT char16_t statics_char16_t<T>::min;
427
428 template <typename T>
429 ETL_CONSTANT char16_t statics_char16_t<T>::max;
430
431 template <typename T>
432 ETL_CONSTANT int statics_char16_t<T>::bits;
433
434 template <typename T>
435 ETL_CONSTANT bool statics_char16_t<T>::is_signed;
436#endif
437
438#if ETL_HAS_NATIVE_CHAR32_T
439 //***********************************
440 // char32_t
441 template <typename T = void>
442 struct statics_char32_t
443 {
444 typedef char32_t value_type;
445
446 static ETL_CONSTANT char32_t min = 0;
447 static ETL_CONSTANT char32_t max = 0xFFFFFFFFU;
448 static ETL_CONSTANT int bits = 32;
449 static ETL_CONSTANT bool is_signed = false;
450 };
451
452 template <typename T>
453 ETL_CONSTANT char32_t statics_char32_t<T>::min;
454
455 template <typename T>
456 ETL_CONSTANT char32_t statics_char32_t<T>::max;
457
458 template <typename T>
459 ETL_CONSTANT int statics_char32_t<T>::bits;
460
461 template <typename T>
462 ETL_CONSTANT bool statics_char32_t<T>::is_signed;
463#endif
464
465#if ETL_USING_20BIT_TYPES
466 template <typename T = void>
467 struct statics___int20
468 {
469 typedef __int20 value_type;
470
471 static ETL_CONSTANT __int20 min = 0x80000;
472 static ETL_CONSTANT __int20 max = 0x7FFFF;
473 static ETL_CONSTANT int bits = 20;
474 static ETL_CONSTANT bool is_signed = true;
475 };
476
477 template <typename T>
478 ETL_CONSTANT __int20 statics___int20<T>::min;
479
480 template <typename T>
481 ETL_CONSTANT __int20 statics___int20<T>::max;
482
483 template <typename T>
484 ETL_CONSTANT int statics___int20<T>::bits;
485
486 template <typename T>
487 ETL_CONSTANT bool statics___int20<T>::is_signed;
488
489 template <typename T = void>
490 struct statics_unsigned___int20
491 {
492 typedef unsigned __int20 value_type;
493
494 static ETL_CONSTANT unsigned __int20 min = 0;
495 static ETL_CONSTANT unsigned __int20 max = 0xFFFFF;
496 static ETL_CONSTANT int bits = 20;
497 static ETL_CONSTANT bool is_signed = false;
498 };
499
500 template <typename T>
501 ETL_CONSTANT unsigned __int20 statics_unsigned___int20<T>::min;
502
503 template <typename T>
504 ETL_CONSTANT unsigned __int20 statics_unsigned___int20<T>::max;
505
506 template <typename T>
507 ETL_CONSTANT int statics_unsigned___int20<T>::bits;
508
509 template <typename T>
510 ETL_CONSTANT bool statics_unsigned___int20<T>::is_signed;
511#endif
512 } // namespace private_integral_limits
513
514 //***************************************************************************
516 //***************************************************************************
517 template <typename T>
519
520 //***************************************************************************
522 //***************************************************************************
523 template <>
525 {
526 };
527
528 //***************************************************************************
530 //***************************************************************************
531 template <>
533 {
534 };
535
536 //***************************************************************************
538 //***************************************************************************
539
540 template <>
542 {
543 typedef char value_type;
544 };
545
546 //***************************************************************************
548 //***************************************************************************
549 template <>
551 {
552 };
553
554 //***************************************************************************
556 //***************************************************************************
557 template <>
559 {
560 };
561
562 //***************************************************************************
564 //***************************************************************************
565 template <>
567 {
568 };
569
570 //***************************************************************************
572 //***************************************************************************
573 template <>
575 {
576 };
577
578 //***************************************************************************
580 //***************************************************************************
581 template <>
583 {
584 };
585
586 //***************************************************************************
588 //***************************************************************************
589 template <>
591 {
592 };
593
594 //***************************************************************************
596 //***************************************************************************
597 template <>
599 {
600 };
601
602 //***************************************************************************
604 //***************************************************************************
605 template <>
607 {
608 };
609
610#if ETL_USING_20BIT_TYPES
611 //***************************************************************************
613 //***************************************************************************
614 template <>
615 struct integral_limits<__int20> : public private_integral_limits::statics___int20<>
616 {
617 };
618
619 template <>
620 struct integral_limits<unsigned __int20> : public private_integral_limits::statics_unsigned___int20<>
621 {
622 };
623#endif
624} // namespace etl
625
626#include "private/minmax_pop.h"
627
628#endif
Definition integral_limits.h:518
bitset_ext
Definition absolute.h:40
is_signed
Definition type_traits.h:458
Definition integral_limits.h:129
Definition integral_limits.h:238
Definition integral_limits.h:338
Definition integral_limits.h:288
Definition integral_limits.h:184
Definition integral_limits.h:154