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