Embedded Template Library 1.0
Loading...
Searching...
No Matches
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) 2018 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_LIMITS_INCLUDED
32#define ETL_LIMITS_INCLUDED
33
34#include "platform.h"
35#include "type_traits.h"
36#include "char_traits.h"
37#include "integral_limits.h"
38
39#if ETL_NOT_USING_STL && defined(ETL_COMPILER_ARM5) && !defined(__USE_C99_MATH)
40 // Required for nan, nanf, nanl
41 #define __USE_C99_MATH
42#endif
43
44#include <limits.h>
45#include <stdint.h>
46#include <float.h>
47#include <math.h>
48
49#include "private/minmax_push.h"
50
51#if defined(ETL_COMPILER_MICROSOFT)
52 #pragma warning(push)
53 #pragma warning(disable : 26812)
54#endif
55
56#if ETL_NOT_USING_STL
57 #define ETL_LOG10_OF_2(x) (((x) * 301) / 1000)
58
59#if !defined(LDBL_MIN) && defined(DBL_MIN)
60 // Looks like we don't have these macros defined.
61 // That probably means that 'long double' is the same size as 'double'.
62 #define LDBL_MIN DBL_MIN
63 #define LDBL_MAX DBL_MAX
64 #define LDBL_EPSILON DBL_EPSILON
65 #define LDBL_MANT_DIG DBL_MANT_DIG
66 #define LDBL_DIG DBL_DIG
67 #define LDBL_MIN_EXP DBL_MIN_EXP
68 #define LDBL_MIN_10_EXP DBL_MIN_10_EXP
69 #define LDBL_MAX_EXP DBL_MAX_EXP
70 #define LDBL_MAX_10_EXP DBL_MAX_10_EXP
71#endif
72
73#if !defined(HUGE_VAL)
74 // Looks like we don't have these macros defined.
75 // They're compiler implementation dependent, so we'll make them the same as the max values.
76 #define HUGE_VALF FLT_MAX
77 #define HUGE_VAL DBL_MAX
78 #define HUGE_VALL LDBL_MAX
79#endif
80
81#if defined(ETL_NO_CPP_NAN_SUPPORT)
82 #if defined(NAN)
84 #define ETL_NANF NAN
85 #define ETL_NAN static_cast<double>(NAN)
86 #define ETL_NANL static_cast<long double>(NAN)
87 #define ETL_HAS_NAN true
89 #else
91 #define ETL_NANF HUGE_VALF
92 #define ETL_NAN HUGE_VAL
93 #define ETL_NANL HUGE_VALL
94 #define ETL_HAS_NAN false
96 #endif
97#else
98 #define ETL_NANF nanf("")
99 #define ETL_NAN nan("")
100 #define ETL_NANL nanl("")
101 #define ETL_HAS_NAN true
102#endif
103
104namespace etl
105{
106 enum float_round_style
107 {
108 round_indeterminate = -1,
109 round_toward_zero = 0,
110 round_to_nearest = 1,
111 round_toward_infinity = 2,
112 round_toward_neg_infinity = 3,
113 };
114
115 enum float_denorm_style
116 {
117 denorm_indeterminate = -1,
118 denorm_absent = 0,
119 denorm_present = 1
120 };
121
122 namespace private_limits
123 {
124 //*********************************
125 // Integral limits common
126 template <typename T = void>
128 {
129 public:
130
131 static ETL_CONSTANT bool is_specialized = true;
132 static ETL_CONSTANT bool is_integer = true;
133 static ETL_CONSTANT bool is_exact = true;
134 static ETL_CONSTANT int max_digits10 = 0;
135 static ETL_CONSTANT int radix = 2;
136 static ETL_CONSTANT int min_exponent = 0;
137 static ETL_CONSTANT int min_exponent10 = 0;
138 static ETL_CONSTANT int max_exponent = 0;
139 static ETL_CONSTANT int max_exponent10 = 0;
140 static ETL_CONSTANT bool has_infinity = false;
141 static ETL_CONSTANT bool has_quiet_NaN = false;
142 static ETL_CONSTANT bool has_signaling_NaN = false;
143 static ETL_CONSTANT bool has_denorm_loss = false;
144 static ETL_CONSTANT bool is_iec559 = false;
145 static ETL_CONSTANT bool is_bounded = true;
146 static ETL_CONSTANT bool traps = false;
147 static ETL_CONSTANT bool tinyness_before = false;
148 static ETL_CONSTANT float_denorm_style has_denorm = denorm_absent;
149 static ETL_CONSTANT float_round_style round_style = round_toward_zero;
150 };
151
152 template <typename T>
153 ETL_CONSTANT bool integral_limits_common<T>::is_specialized;
154
155 template <typename T>
156 ETL_CONSTANT bool integral_limits_common<T>::is_integer;
157
158 template <typename T>
159 ETL_CONSTANT bool integral_limits_common<T>::is_exact;
160
161 template <typename T>
162 ETL_CONSTANT int integral_limits_common<T>::max_digits10;
163
164 template <typename T>
165 ETL_CONSTANT int integral_limits_common<T>::radix;
166
167 template <typename T>
168 ETL_CONSTANT int integral_limits_common<T>::min_exponent;
169
170 template <typename T>
171 ETL_CONSTANT int integral_limits_common<T>::min_exponent10;
172
173 template <typename T>
174 ETL_CONSTANT int integral_limits_common<T>::max_exponent;
175
176 template <typename T>
177 ETL_CONSTANT int integral_limits_common<T>::max_exponent10;
178
179 template <typename T>
180 ETL_CONSTANT bool integral_limits_common<T>::has_infinity;
181
182 template <typename T>
183 ETL_CONSTANT bool integral_limits_common<T>::has_quiet_NaN;
184
185 template <typename T>
186 ETL_CONSTANT bool integral_limits_common<T>::has_signaling_NaN;
187
188 template <typename T>
189 ETL_CONSTANT bool integral_limits_common<T>::has_denorm_loss;
190
191 template <typename T>
192 ETL_CONSTANT bool integral_limits_common<T>::is_iec559;
193
194 template <typename T>
195 ETL_CONSTANT bool integral_limits_common<T>::is_bounded;
196
197 template <typename T>
198 ETL_CONSTANT bool integral_limits_common<T>::traps;
199
200 template <typename T>
201 ETL_CONSTANT bool integral_limits_common<T>::tinyness_before;
202
203 template <typename T>
204 ETL_CONSTANT float_denorm_style integral_limits_common<T>::has_denorm;
205
206 template <typename T>
207 ETL_CONSTANT float_round_style integral_limits_common<T>::round_style;
208
209 //*********************************
210 // bool
211 template <typename T = void>
213 {
214 static ETL_CONSTANT int digits = 1;
215 static ETL_CONSTANT int digits10 = 0;
216 static ETL_CONSTANT bool is_signed = false;
217 static ETL_CONSTANT bool is_modulo = false;
218 };
219
220 template <typename T>
221 ETL_CONSTANT int integral_limits_bool<T>::digits;
222
223 template <typename T>
224 ETL_CONSTANT int integral_limits_bool<T>::digits10;
225
226 template <typename T>
227 ETL_CONSTANT bool integral_limits_bool<T>::is_signed;
228
229 template <typename T>
230 ETL_CONSTANT bool integral_limits_bool<T>::is_modulo;
231
232 //*********************************
233 // char
234 template <typename T = void>
236 {
237 static ETL_CONSTANT int digits = (CHAR_BIT * sizeof(char)) - (etl::is_signed<char>::value ? 1 : 0);
238 static ETL_CONSTANT int digits10 = ETL_LOG10_OF_2(digits);
239 static ETL_CONSTANT bool is_signed = etl::is_signed<char>::value;
240 static ETL_CONSTANT bool is_modulo = etl::is_unsigned<char>::value;
241 };
242
243 template <typename T>
244 ETL_CONSTANT int integral_limits_char<T>::digits;
245
246 template <typename T>
247 ETL_CONSTANT int integral_limits_char<T>::digits10;
248
249 template <typename T>
250 ETL_CONSTANT bool integral_limits_char<T>::is_signed;
251
252 template <typename T>
253 ETL_CONSTANT bool integral_limits_char<T>::is_modulo;
254
255 //*********************************
256 // unsigned char
257 template <typename T = void>
259 {
260 static ETL_CONSTANT int digits = (CHAR_BIT * sizeof(unsigned char));
261 static ETL_CONSTANT int digits10 = ETL_LOG10_OF_2(digits);
262 static ETL_CONSTANT bool is_signed = false;
263 static ETL_CONSTANT bool is_modulo = true;
264 };
265
266 template <typename T>
267 ETL_CONSTANT int integral_limits_unsigned_char<T>::digits;
268
269 template <typename T>
270 ETL_CONSTANT int integral_limits_unsigned_char<T>::digits10;
271
272 template <typename T>
273 ETL_CONSTANT bool integral_limits_unsigned_char<T>::is_signed;
274
275 template <typename T>
276 ETL_CONSTANT bool integral_limits_unsigned_char<T>::is_modulo;
277
278 //*********************************
279 // signed char
280 template <typename T = void>
282 {
283 static ETL_CONSTANT int digits = (CHAR_BIT * sizeof(char)) - 1;
284 static ETL_CONSTANT int digits10 = ETL_LOG10_OF_2(digits);
285 static ETL_CONSTANT bool is_signed = true;
286 static ETL_CONSTANT bool is_modulo = false;
287 };
288
289 template <typename T>
290 ETL_CONSTANT int integral_limits_signed_char<T>::digits;
291
292 template <typename T>
293 ETL_CONSTANT int integral_limits_signed_char<T>::digits10;
294
295 template <typename T>
296 ETL_CONSTANT bool integral_limits_signed_char<T>::is_signed;
297
298 template <typename T>
299 ETL_CONSTANT bool integral_limits_signed_char<T>::is_modulo;
300
301#if ETL_HAS_NATIVE_CHAR8_T
302 //*********************************
303 // char8_t
304 template <typename T = void>
306 {
307 static ETL_CONSTANT int digits = (CHAR_BIT * sizeof(char8_t)) - (etl::is_signed<char8_t>::value ? 1 : 0);
308 static ETL_CONSTANT int digits10 = ETL_LOG10_OF_2(digits);
309 static ETL_CONSTANT bool is_signed = etl::is_signed<char8_t>::value;
310 static ETL_CONSTANT bool is_modulo = false;
311 };
312
313 template <typename T>
314 ETL_CONSTANT int integral_limits_char8_t<T>::digits;
315
316 template <typename T>
317 ETL_CONSTANT int integral_limits_char8_t<T>::digits10;
318
319 template <typename T>
320 ETL_CONSTANT bool integral_limits_char8_t<T>::is_signed;
321
322 template <typename T>
323 ETL_CONSTANT bool integral_limits_char8_t<T>::is_modulo;
324#endif
325
326#if ETL_HAS_NATIVE_CHAR16_T
327 //*********************************
328 // char16_t
329 template <typename T = void>
331 {
332 static ETL_CONSTANT int digits = (CHAR_BIT * sizeof(char16_t));
333 static ETL_CONSTANT int digits10 = ETL_LOG10_OF_2(digits);
334 static ETL_CONSTANT bool is_signed = false;
335 static ETL_CONSTANT bool is_modulo = true;
336 };
337
338 template <typename T>
339 ETL_CONSTANT int integral_limits_char16_t<T>::digits;
340
341 template <typename T>
342 ETL_CONSTANT int integral_limits_char16_t<T>::digits10;
343
344 template <typename T>
345 ETL_CONSTANT bool integral_limits_char16_t<T>::is_signed;
346
347 template <typename T>
348 ETL_CONSTANT bool integral_limits_char16_t<T>::is_modulo;
349#endif
350
351#if ETL_HAS_NATIVE_CHAR32_T
352 //*********************************
353 // char32_t
354 template <typename T = void>
356 {
357 static ETL_CONSTANT int digits = (CHAR_BIT * sizeof(char32_t));
358 static ETL_CONSTANT int digits10 = ETL_LOG10_OF_2(digits);
359 static ETL_CONSTANT bool is_signed = false;
360 static ETL_CONSTANT bool is_modulo = true;
361 };
362
363 template <typename T>
364 ETL_CONSTANT int integral_limits_char32_t<T>::digits;
365
366 template <typename T>
367 ETL_CONSTANT int integral_limits_char32_t<T>::digits10;
368
369 template <typename T>
370 ETL_CONSTANT bool integral_limits_char32_t<T>::is_signed;
371
372 template <typename T>
373 ETL_CONSTANT bool integral_limits_char32_t<T>::is_modulo;
374#endif
375
376 //*********************************
377 // wchar_t
378 template <typename T = void>
380 {
381 static ETL_CONSTANT int digits = (CHAR_BIT * sizeof(wchar_t)) - (etl::is_signed<wchar_t>::value ? 1 : 0);
382 static ETL_CONSTANT int digits10 = ETL_LOG10_OF_2(digits);
383 static ETL_CONSTANT bool is_signed = etl::is_signed<wchar_t>::value;
384 static ETL_CONSTANT bool is_modulo = etl::is_unsigned<wchar_t>::value;
385 };
386
387 template <typename T>
388 ETL_CONSTANT int integral_limits_wchar_t<T>::digits;
389
390 template <typename T>
391 ETL_CONSTANT int integral_limits_wchar_t<T>::digits10;
392
393 template <typename T>
394 ETL_CONSTANT bool integral_limits_wchar_t<T>::is_signed;
395
396 template <typename T>
397 ETL_CONSTANT bool integral_limits_wchar_t<T>::is_modulo;
398
399 //*********************************
400 // short
401 template <typename T = void>
403 {
404 static ETL_CONSTANT int digits = (CHAR_BIT * sizeof(short)) - 1;
405 static ETL_CONSTANT int digits10 = ETL_LOG10_OF_2(digits);
406 static ETL_CONSTANT bool is_signed = true;
407 static ETL_CONSTANT bool is_modulo = false;
408 };
409
410 template <typename T>
411 ETL_CONSTANT int integral_limits_short<T>::digits;
412
413 template <typename T>
414 ETL_CONSTANT int integral_limits_short<T>::digits10;
415
416 template <typename T>
417 ETL_CONSTANT bool integral_limits_short<T>::is_signed;
418
419 template <typename T>
420 ETL_CONSTANT bool integral_limits_short<T>::is_modulo;
421
422 //*********************************
423 // unsigned short
424 template <typename T = void>
426 {
427 static ETL_CONSTANT int digits = (CHAR_BIT * sizeof(unsigned short));
428 static ETL_CONSTANT int digits10 = ETL_LOG10_OF_2(digits);
429 static ETL_CONSTANT bool is_signed = false;
430 static ETL_CONSTANT bool is_modulo = true;
431 };
432
433 template <typename T>
434 ETL_CONSTANT int integral_limits_unsigned_short<T>::digits;
435
436 template <typename T>
437 ETL_CONSTANT int integral_limits_unsigned_short<T>::digits10;
438
439 template <typename T>
440 ETL_CONSTANT bool integral_limits_unsigned_short<T>::is_signed;
441
442 template <typename T>
443 ETL_CONSTANT bool integral_limits_unsigned_short<T>::is_modulo;
444
445 //*********************************
446 // int
447 template <typename T = void>
449 {
450 static ETL_CONSTANT int digits = (CHAR_BIT * sizeof(int)) - 1;
451 static ETL_CONSTANT int digits10 = ETL_LOG10_OF_2(digits);
452 static ETL_CONSTANT bool is_signed = true;
453 static ETL_CONSTANT bool is_modulo = false;
454 };
455
456 template <typename T>
457 ETL_CONSTANT int integral_limits_int<T>::digits;
458
459 template <typename T>
460 ETL_CONSTANT int integral_limits_int<T>::digits10;
461
462 template <typename T>
463 ETL_CONSTANT bool integral_limits_int<T>::is_signed;
464
465 template <typename T>
466 ETL_CONSTANT bool integral_limits_int<T>::is_modulo;
467
468 //*********************************
469 // unsigned int
470 template <typename T = void>
472 {
473 static ETL_CONSTANT int digits = (CHAR_BIT * sizeof(unsigned int));
474 static ETL_CONSTANT int digits10 = ETL_LOG10_OF_2(digits);
475 static ETL_CONSTANT bool is_signed = false;
476 static ETL_CONSTANT bool is_modulo = true;
477 };
478
479 template <typename T>
480 ETL_CONSTANT int integral_limits_unsigned_int<T>::digits;
481
482 template <typename T>
483 ETL_CONSTANT int integral_limits_unsigned_int<T>::digits10;
484
485 template <typename T>
486 ETL_CONSTANT bool integral_limits_unsigned_int<T>::is_signed;
487
488 template <typename T>
489 ETL_CONSTANT bool integral_limits_unsigned_int<T>::is_modulo;
490
491 //*********************************
492 // long
493 template <typename T = void>
495 {
496 static ETL_CONSTANT int digits = (CHAR_BIT * sizeof(long)) - 1;
497 static ETL_CONSTANT int digits10 = ETL_LOG10_OF_2(digits);
498 static ETL_CONSTANT bool is_signed = true;
499 static ETL_CONSTANT bool is_modulo = false;
500 };
501
502 template <typename T>
503 ETL_CONSTANT int integral_limits_long<T>::digits;
504
505 template <typename T>
506 ETL_CONSTANT int integral_limits_long<T>::digits10;
507
508 template <typename T>
509 ETL_CONSTANT bool integral_limits_long<T>::is_signed;
510
511 template <typename T>
512 ETL_CONSTANT bool integral_limits_long<T>::is_modulo;
513
514 //*********************************
515 // unsigned long
516 template <typename T = void>
518 {
519 static ETL_CONSTANT int digits = (CHAR_BIT * sizeof(unsigned long));
520 static ETL_CONSTANT int digits10 = ETL_LOG10_OF_2(digits);
521 static ETL_CONSTANT bool is_signed = false;
522 static ETL_CONSTANT bool is_modulo = true;
523 };
524
525 template <typename T>
526 ETL_CONSTANT int integral_limits_unsigned_long<T>::digits;
527
528 template <typename T>
529 ETL_CONSTANT int integral_limits_unsigned_long<T>::digits10;
530
531 template <typename T>
532 ETL_CONSTANT bool integral_limits_unsigned_long<T>::is_signed;
533
534 template <typename T>
535 ETL_CONSTANT bool integral_limits_unsigned_long<T>::is_modulo;
536
537 //*********************************
538 // long long
539 template <typename T = void>
541 {
542 static ETL_CONSTANT int digits = (CHAR_BIT * sizeof(long long)) - 1;
543 static ETL_CONSTANT int digits10 = ETL_LOG10_OF_2(digits);
544 static ETL_CONSTANT bool is_signed = true;
545 static ETL_CONSTANT bool is_modulo = false;
546 };
547
548 template <typename T>
549 ETL_CONSTANT int integral_limits_long_long<T>::digits;
550
551 template <typename T>
552 ETL_CONSTANT int integral_limits_long_long<T>::digits10;
553
554 template <typename T>
555 ETL_CONSTANT bool integral_limits_long_long<T>::is_signed;
556
557 template <typename T>
558 ETL_CONSTANT bool integral_limits_long_long<T>::is_modulo;
559
560 //*********************************
561 // unsigned long long
562 template <typename T = void>
564 {
565 static ETL_CONSTANT int digits = (CHAR_BIT * sizeof(unsigned long long));
566 static ETL_CONSTANT int digits10 = ETL_LOG10_OF_2(digits);
567 static ETL_CONSTANT bool is_signed = false;
568 static ETL_CONSTANT bool is_modulo = true;
569 };
570
571 template <typename T>
572 ETL_CONSTANT int integral_limits_unsigned_long_long<T>::digits;
573
574 template <typename T>
575 ETL_CONSTANT int integral_limits_unsigned_long_long<T>::digits10;
576
577 template <typename T>
578 ETL_CONSTANT bool integral_limits_unsigned_long_long<T>::is_signed;
579
580 template <typename T>
581 ETL_CONSTANT bool integral_limits_unsigned_long_long<T>::is_modulo;
582
583 //*********************************
584 // Floating point limits common
585 template <typename T = void>
587 {
588 public:
589
590 static ETL_CONSTANT bool is_specialized = true;
591 static ETL_CONSTANT bool is_signed = true;
592 static ETL_CONSTANT bool is_integer = false;
593 static ETL_CONSTANT bool is_exact = false;
594 static ETL_CONSTANT int radix = 2;
595 static ETL_CONSTANT bool has_infinity = true;
596 static ETL_CONSTANT bool has_quiet_NaN = ETL_HAS_NAN;
597 static ETL_CONSTANT bool has_signaling_NaN = ETL_HAS_NAN;
598 static ETL_CONSTANT bool has_denorm_loss = false;
599 static ETL_CONSTANT bool is_iec559 = false;
600 static ETL_CONSTANT bool is_bounded = true;
601 static ETL_CONSTANT bool is_modulo = false;
602 static ETL_CONSTANT bool traps = false;
603 static ETL_CONSTANT bool tinyness_before = false;
604 static ETL_CONSTANT float_denorm_style has_denorm = denorm_indeterminate;
605 static ETL_CONSTANT float_round_style round_style = round_indeterminate;
606 };
607
608 template <typename T>
609 ETL_CONSTANT bool floating_point_limits_common<T>::is_specialized;
610
611 template <typename T>
612 ETL_CONSTANT bool floating_point_limits_common<T>::is_signed;
613
614 template <typename T>
615 ETL_CONSTANT bool floating_point_limits_common<T>::is_integer;
616
617 template <typename T>
618 ETL_CONSTANT bool floating_point_limits_common<T>::is_exact;
619
620 template <typename T>
621 ETL_CONSTANT int floating_point_limits_common<T>::radix;
622
623 template <typename T>
624 ETL_CONSTANT bool floating_point_limits_common<T>::has_infinity;
625
626 template <typename T>
627 ETL_CONSTANT bool floating_point_limits_common<T>::has_quiet_NaN;
628
629 template <typename T>
630 ETL_CONSTANT bool floating_point_limits_common<T>::has_signaling_NaN;
631
632 template <typename T>
633 ETL_CONSTANT bool floating_point_limits_common<T>::has_denorm_loss;
634
635 template <typename T>
636 ETL_CONSTANT bool floating_point_limits_common<T>::is_iec559;
637
638 template <typename T>
639 ETL_CONSTANT bool floating_point_limits_common<T>::is_bounded;
640
641 template <typename T>
642 ETL_CONSTANT bool floating_point_limits_common<T>::is_modulo;
643
644 template <typename T>
645 ETL_CONSTANT bool floating_point_limits_common<T>::traps;
646
647 template <typename T>
648 ETL_CONSTANT bool floating_point_limits_common<T>::tinyness_before;
649
650 template <typename T>
651 ETL_CONSTANT float_denorm_style floating_point_limits_common<T>::has_denorm;
652
653 template <typename T>
654 ETL_CONSTANT float_round_style floating_point_limits_common<T>::round_style;
655
656 //*********************************
657 // float
658 template <typename T = void>
660 {
661 static ETL_CONSTANT int digits = FLT_MANT_DIG;
662 static ETL_CONSTANT int digits10 = FLT_DIG;
663 static ETL_CONSTANT int max_digits10 = ETL_LOG10_OF_2(FLT_MANT_DIG) + 2;
664
665 static ETL_CONSTANT int min_exponent = FLT_MIN_EXP;
666 static ETL_CONSTANT int min_exponent10 = FLT_MIN_10_EXP;
667 static ETL_CONSTANT int max_exponent = FLT_MAX_EXP;
668 static ETL_CONSTANT int max_exponent10 = FLT_MAX_10_EXP;
669 };
670
671 template <typename T>
672 ETL_CONSTANT int floating_point_limits_float<T>::digits;
673
674 template <typename T>
675 ETL_CONSTANT int floating_point_limits_float<T>::digits10;
676
677 template <typename T>
678 ETL_CONSTANT int floating_point_limits_float<T>::max_digits10;
679
680 template <typename T>
681 ETL_CONSTANT int floating_point_limits_float<T>::min_exponent;
682
683 template <typename T>
684 ETL_CONSTANT int floating_point_limits_float<T>::min_exponent10;
685
686 template <typename T>
687 ETL_CONSTANT int floating_point_limits_float<T>::max_exponent;
688
689 template <typename T>
690 ETL_CONSTANT int floating_point_limits_float<T>::max_exponent10;
691
692 //*********************************
693 // double
694 template <typename T = void>
696 {
697 static ETL_CONSTANT int digits = DBL_MANT_DIG;
698 static ETL_CONSTANT int digits10 = DBL_DIG;
699 static ETL_CONSTANT int max_digits10 = ETL_LOG10_OF_2(DBL_MANT_DIG) + 2;
700
701 static ETL_CONSTANT int min_exponent = DBL_MIN_EXP;
702 static ETL_CONSTANT int min_exponent10 = DBL_MIN_10_EXP;
703 static ETL_CONSTANT int max_exponent = DBL_MAX_EXP;
704 static ETL_CONSTANT int max_exponent10 = DBL_MAX_10_EXP;
705 };
706
707 template <typename T>
708 ETL_CONSTANT int floating_point_limits_double<T>::digits;
709
710 template <typename T>
711 ETL_CONSTANT int floating_point_limits_double<T>::digits10;
712
713 template <typename T>
714 ETL_CONSTANT int floating_point_limits_double<T>::max_digits10;
715
716 template <typename T>
717 ETL_CONSTANT int floating_point_limits_double<T>::min_exponent;
718
719 template <typename T>
720 ETL_CONSTANT int floating_point_limits_double<T>::min_exponent10;
721
722 template <typename T>
723 ETL_CONSTANT int floating_point_limits_double<T>::max_exponent;
724
725 template <typename T>
726 ETL_CONSTANT int floating_point_limits_double<T>::max_exponent10;
727
728 //*********************************
729 // long double
730 template <typename T = void>
732 {
733 static ETL_CONSTANT int digits = LDBL_MANT_DIG;
734 static ETL_CONSTANT int digits10 = LDBL_DIG;
735 static ETL_CONSTANT int max_digits10 = ETL_LOG10_OF_2(LDBL_MANT_DIG) + 2;
736
737 static ETL_CONSTANT int min_exponent = LDBL_MIN_EXP;
738 static ETL_CONSTANT int min_exponent10 = LDBL_MIN_10_EXP;
739 static ETL_CONSTANT int max_exponent = LDBL_MAX_EXP;
740 static ETL_CONSTANT int max_exponent10 = LDBL_MAX_10_EXP;
741 };
742
743 template <typename T>
744 ETL_CONSTANT int floating_point_limits_long_double<T>::digits;
745
746 template <typename T>
747 ETL_CONSTANT int floating_point_limits_long_double<T>::digits10;
748
749 template <typename T>
750 ETL_CONSTANT int floating_point_limits_long_double<T>::max_digits10;
751
752 template <typename T>
753 ETL_CONSTANT int floating_point_limits_long_double<T>::min_exponent;
754
755 template <typename T>
756 ETL_CONSTANT int floating_point_limits_long_double<T>::min_exponent10;
757
758 template <typename T>
759 ETL_CONSTANT int floating_point_limits_long_double<T>::max_exponent;
760
761 template <typename T>
762 ETL_CONSTANT int floating_point_limits_long_double<T>::max_exponent10;
763 }
764
765 //***************************************************************************
766 // Default
767 template <typename T>
768 class numeric_limits;
769
770 template <typename T>
771 class numeric_limits<const T> : public numeric_limits<T> { };
772
773 template <typename T>
774 class numeric_limits<volatile T> : public numeric_limits<T> { };
775
776 template <typename T>
777 class numeric_limits<const volatile T> : public numeric_limits<T> { };
778
779 //***********************************
780 // bool
781 template<>
782 class numeric_limits<bool> : public private_limits::integral_limits_common<>,
783 public private_limits::integral_limits_bool<>
784 {
785 public:
786
787 static ETL_CONSTEXPR bool min() { return false; }
788 static ETL_CONSTEXPR bool max() { return true; }
789 static ETL_CONSTEXPR bool lowest() { return false; }
790 static ETL_CONSTEXPR bool epsilon() { return false; }
791 static ETL_CONSTEXPR bool round_error() { return false; }
792 static ETL_CONSTEXPR bool denorm_min() { return false; }
793 static ETL_CONSTEXPR bool infinity() { return false; }
794 static ETL_CONSTEXPR bool quiet_NaN() { return false; }
795 static ETL_CONSTEXPR bool signaling_NaN() { return false; }
796 };
797
798 //***************************************************************************
799 // char
800 template<>
801 class numeric_limits<char> : public private_limits::integral_limits_common<>,
802 public private_limits::integral_limits_char<>
803 {
804 public:
805
806 static ETL_CONSTEXPR char min() { return char(CHAR_MIN); }
807 static ETL_CONSTEXPR char max() { return char(CHAR_MAX); }
808 static ETL_CONSTEXPR char lowest() { return char(CHAR_MIN); }
809 static ETL_CONSTEXPR char epsilon() { return 0; }
810 static ETL_CONSTEXPR char round_error() { return 0; }
811 static ETL_CONSTEXPR char denorm_min() { return 0; }
812 static ETL_CONSTEXPR char infinity() { return 0; }
813 static ETL_CONSTEXPR char quiet_NaN() { return 0; }
814 static ETL_CONSTEXPR char signaling_NaN() { return 0; }
815 };
816
817 //***************************************************************************
818 // unsigned char
819 template<>
820 class numeric_limits<unsigned char> : public private_limits::integral_limits_common<>,
821 public private_limits::integral_limits_unsigned_char<>
822 {
823 public:
824
825 static ETL_CONSTEXPR unsigned char min() { return 0U; }
826 static ETL_CONSTEXPR unsigned char max() { return UCHAR_MAX; }
827 static ETL_CONSTEXPR unsigned char lowest() { return 0U; }
828 static ETL_CONSTEXPR unsigned char epsilon() { return 0U; }
829 static ETL_CONSTEXPR unsigned char round_error() { return 0U; }
830 static ETL_CONSTEXPR unsigned char denorm_min() { return 0U; }
831 static ETL_CONSTEXPR unsigned char infinity() { return 0U; }
832 static ETL_CONSTEXPR unsigned char quiet_NaN() { return 0U; }
833 static ETL_CONSTEXPR unsigned char signaling_NaN() { return 0U; }
834 };
835
836 //***************************************************************************
837 // signed char
838 template<>
839 class numeric_limits<signed char> : public private_limits::integral_limits_common<>,
840 public private_limits::integral_limits_signed_char<>
841 {
842 public:
843
844 static ETL_CONSTEXPR signed char min() { return SCHAR_MIN; }
845 static ETL_CONSTEXPR signed char max() { return SCHAR_MAX; }
846 static ETL_CONSTEXPR signed char lowest() { return SCHAR_MIN; }
847 static ETL_CONSTEXPR signed char epsilon() { return 0; }
848 static ETL_CONSTEXPR signed char round_error() { return 0; }
849 static ETL_CONSTEXPR signed char denorm_min() { return 0; }
850 static ETL_CONSTEXPR signed char infinity() { return 0; }
851 static ETL_CONSTEXPR signed char quiet_NaN() { return 0; }
852 static ETL_CONSTEXPR signed char signaling_NaN() { return 0; }
853 };
854
855#if ETL_HAS_NATIVE_CHAR8_T
856 //***************************************************************************
857 // char8_t
858 template<>
859 class numeric_limits<char8_t> : public private_limits::integral_limits_common<>,
860 public private_limits::integral_limits_char8_t<>
861 {
862 public:
863
864 static ETL_CONSTEXPR char8_t min() { return char8_t(CHAR_MIN); }
865 static ETL_CONSTEXPR char8_t max() { return char8_t(CHAR_MAX); }
866 static ETL_CONSTEXPR char8_t lowest() { return char8_t(CHAR_MIN); }
867 static ETL_CONSTEXPR char8_t epsilon() { return 0; }
868 static ETL_CONSTEXPR char8_t round_error() { return 0; }
869 static ETL_CONSTEXPR char8_t denorm_min() { return 0; }
870 static ETL_CONSTEXPR char8_t infinity() { return 0; }
871 static ETL_CONSTEXPR char8_t quiet_NaN() { return 0; }
872 static ETL_CONSTEXPR char8_t signaling_NaN() { return 0; }
873 };
874#endif
875
876#if ETL_HAS_NATIVE_CHAR16_T
877 //***************************************************************************
878 // char16_t
879 template<>
880 class numeric_limits<char16_t> : public private_limits::integral_limits_common<>,
881 public private_limits::integral_limits_char16_t<>
882 {
883 public:
884
885 static ETL_CONSTEXPR char16_t min() { return 0U; }
886 static ETL_CONSTEXPR char16_t max() { return UINT_LEAST16_MAX; }
887 static ETL_CONSTEXPR char16_t lowest() { return 0U; }
888 static ETL_CONSTEXPR char16_t epsilon() { return 0U; }
889 static ETL_CONSTEXPR char16_t round_error() { return 0U; }
890 static ETL_CONSTEXPR char16_t denorm_min() { return 0U; }
891 static ETL_CONSTEXPR char16_t infinity() { return 0U; }
892 static ETL_CONSTEXPR char16_t quiet_NaN() { return 0U; }
893 static ETL_CONSTEXPR char16_t signaling_NaN() { return 0U; }
894 };
895#endif
896
897#if ETL_HAS_NATIVE_CHAR32_T
898 //***************************************************************************
899 // char32_t
900 template<>
901 class numeric_limits<char32_t> : public private_limits::integral_limits_common<>,
902 public private_limits::integral_limits_char32_t<>
903 {
904 public:
905
906 static ETL_CONSTEXPR char32_t min() { return 0U; }
907 static ETL_CONSTEXPR char32_t max() { return UINT_LEAST32_MAX; }
908 static ETL_CONSTEXPR char32_t lowest() { return 0U; }
909 static ETL_CONSTEXPR char32_t epsilon() { return 0U; }
910 static ETL_CONSTEXPR char32_t round_error() { return 0U; }
911 static ETL_CONSTEXPR char32_t denorm_min() { return 0U; }
912 static ETL_CONSTEXPR char32_t infinity() { return 0U; }
913 static ETL_CONSTEXPR char32_t quiet_NaN() { return 0U; }
914 static ETL_CONSTEXPR char32_t signaling_NaN() { return 0U; }
915 };
916#endif
917
918 //***************************************************************************
919 // wchar_t
920 template<>
921 class numeric_limits<wchar_t> : public private_limits::integral_limits_common<>,
922 public private_limits::integral_limits_wchar_t<>
923 {
924 public:
925
926 static ETL_CONSTEXPR wchar_t min() { return WCHAR_MIN; }
927 static ETL_CONSTEXPR wchar_t max() { return WCHAR_MAX; }
928 static ETL_CONSTEXPR wchar_t lowest() { return WCHAR_MIN; }
929 static ETL_CONSTEXPR wchar_t epsilon() { return wchar_t(0); }
930 static ETL_CONSTEXPR wchar_t round_error() { return wchar_t(0); }
931 static ETL_CONSTEXPR wchar_t denorm_min() { return wchar_t(0); }
932 static ETL_CONSTEXPR wchar_t infinity() { return wchar_t(0); }
933 static ETL_CONSTEXPR wchar_t quiet_NaN() { return wchar_t(0); }
934 static ETL_CONSTEXPR wchar_t signaling_NaN() { return wchar_t(0); }
935 };
936
937 //***************************************************************************
938 // short
939 template<>
940 class numeric_limits<short> : public private_limits::integral_limits_common<>,
941 public private_limits::integral_limits_short<>
942 {
943 public:
944
945 static ETL_CONSTEXPR short min() { return SHRT_MIN; }
946 static ETL_CONSTEXPR short max() { return SHRT_MAX; }
947 static ETL_CONSTEXPR short lowest() { return SHRT_MIN; }
948 static ETL_CONSTEXPR short epsilon() { return 0; }
949 static ETL_CONSTEXPR short round_error() { return 0; }
950 static ETL_CONSTEXPR short denorm_min() { return 0; }
951 static ETL_CONSTEXPR short infinity() { return 0; }
952 static ETL_CONSTEXPR short quiet_NaN() { return 0; }
953 static ETL_CONSTEXPR short signaling_NaN() { return 0; }
954 };
955
956 //***************************************************************************
957 // unsigned short
958 template<>
959 class numeric_limits<unsigned short> : public private_limits::integral_limits_common<>,
960 public private_limits::integral_limits_unsigned_short<>
961 {
962 public:
963
964 static ETL_CONSTEXPR unsigned short min() { return 0U; }
965 static ETL_CONSTEXPR unsigned short max() { return USHRT_MAX; }
966 static ETL_CONSTEXPR unsigned short lowest() { return 0U; }
967 static ETL_CONSTEXPR unsigned short epsilon() { return 0U; }
968 static ETL_CONSTEXPR unsigned short round_error() { return 0U; }
969 static ETL_CONSTEXPR unsigned short denorm_min() { return 0U; }
970 static ETL_CONSTEXPR unsigned short infinity() { return 0U; }
971 static ETL_CONSTEXPR unsigned short quiet_NaN() { return 0U; }
972 static ETL_CONSTEXPR unsigned short signaling_NaN() { return 0U; }
973 };
974
975 //***************************************************************************
976 // int
977 template<>
978 class numeric_limits<int> : public private_limits::integral_limits_common<>,
979 public private_limits::integral_limits_int<>
980 {
981 public:
982
983 static ETL_CONSTEXPR int min() { return INT_MIN; }
984 static ETL_CONSTEXPR int max() { return INT_MAX; }
985 static ETL_CONSTEXPR int lowest() { return INT_MIN; }
986 static ETL_CONSTEXPR int epsilon() { return 0; }
987 static ETL_CONSTEXPR int round_error() { return 0; }
988 static ETL_CONSTEXPR int denorm_min() { return 0; }
989 static ETL_CONSTEXPR int infinity() { return 0; }
990 static ETL_CONSTEXPR int quiet_NaN() { return 0; }
991 static ETL_CONSTEXPR int signaling_NaN() { return 0; }
992 };
993
994 //***************************************************************************
995 // unsigned int
996 template<>
997 class numeric_limits<unsigned int> : public private_limits::integral_limits_common<>,
998 public private_limits::integral_limits_unsigned_int<>
999 {
1000 public:
1001
1002 static ETL_CONSTEXPR unsigned int min() { return 0U; }
1003 static ETL_CONSTEXPR unsigned int max() { return UINT_MAX; }
1004 static ETL_CONSTEXPR unsigned int lowest() { return 0U; }
1005 static ETL_CONSTEXPR unsigned int epsilon() { return 0U; }
1006 static ETL_CONSTEXPR unsigned int round_error() { return 0U; }
1007 static ETL_CONSTEXPR unsigned int denorm_min() { return 0U; }
1008 static ETL_CONSTEXPR unsigned int infinity() { return 0U; }
1009 static ETL_CONSTEXPR unsigned int quiet_NaN() { return 0U; }
1010 static ETL_CONSTEXPR unsigned int signaling_NaN() { return 0U; }
1011 };
1012
1013 //***************************************************************************
1014 // long
1015 template<>
1016 class numeric_limits<long> : public private_limits::integral_limits_common<>,
1017 public private_limits::integral_limits_long<>
1018 {
1019 public:
1020
1021 static ETL_CONSTEXPR long min() { return LONG_MIN; }
1022 static ETL_CONSTEXPR long max() { return LONG_MAX; }
1023 static ETL_CONSTEXPR long lowest() { return LONG_MIN; }
1024 static ETL_CONSTEXPR long epsilon() { return 0; }
1025 static ETL_CONSTEXPR long round_error() { return 0; }
1026 static ETL_CONSTEXPR long denorm_min() { return 0; }
1027 static ETL_CONSTEXPR long infinity() { return 0; }
1028 static ETL_CONSTEXPR long quiet_NaN() { return 0; }
1029 static ETL_CONSTEXPR long signaling_NaN() { return 0; }
1030 };
1031
1032 //***************************************************************************
1033 // unsigned long
1034 template<>
1035 class numeric_limits<unsigned long> : public private_limits::integral_limits_common<>,
1036 public private_limits::integral_limits_unsigned_long<>
1037 {
1038 public:
1039
1040 static ETL_CONSTEXPR unsigned long min() { return 0U; }
1041 static ETL_CONSTEXPR unsigned long max() { return ULONG_MAX; }
1042 static ETL_CONSTEXPR unsigned long lowest() { return 0U; }
1043 static ETL_CONSTEXPR unsigned long epsilon() { return 0U; }
1044 static ETL_CONSTEXPR unsigned long round_error() { return 0U; }
1045 static ETL_CONSTEXPR unsigned long denorm_min() { return 0U; }
1046 static ETL_CONSTEXPR unsigned long infinity() { return 0U; }
1047 static ETL_CONSTEXPR unsigned long quiet_NaN() { return 0U; }
1048 static ETL_CONSTEXPR unsigned long signaling_NaN() { return 0U; }
1049 };
1050
1051 //***************************************************************************
1052 // long long
1053 template<>
1054 class numeric_limits<long long> : public private_limits::integral_limits_common<>,
1055 public private_limits::integral_limits_long_long<>
1056 {
1057 public:
1058
1059 static ETL_CONSTEXPR long long min() { return LLONG_MIN; }
1060 static ETL_CONSTEXPR long long max() { return LLONG_MAX; }
1061 static ETL_CONSTEXPR long long lowest() { return LLONG_MIN; }
1062 static ETL_CONSTEXPR long long epsilon() { return 0; }
1063 static ETL_CONSTEXPR long long round_error() { return 0; }
1064 static ETL_CONSTEXPR long long denorm_min() { return 0; }
1065 static ETL_CONSTEXPR long long infinity() { return 0; }
1066 static ETL_CONSTEXPR long long quiet_NaN() { return 0; }
1067 static ETL_CONSTEXPR long long signaling_NaN() { return 0; }
1068 };
1069
1070 //***************************************************************************
1071 // unsigned long long
1072 template<>
1073 class numeric_limits<unsigned long long> : public private_limits::integral_limits_common<>,
1074 public private_limits::integral_limits_unsigned_long_long<>
1075 {
1076 public:
1077
1078 static ETL_CONSTEXPR unsigned long long min() { return 0U; }
1079 static ETL_CONSTEXPR unsigned long long max() { return ULLONG_MAX; }
1080 static ETL_CONSTEXPR unsigned long long lowest() { return 0U; }
1081 static ETL_CONSTEXPR unsigned long long epsilon() { return 0U; }
1082 static ETL_CONSTEXPR unsigned long long round_error() { return 0U; }
1083 static ETL_CONSTEXPR unsigned long long denorm_min() { return 0U; }
1084 static ETL_CONSTEXPR unsigned long long infinity() { return 0U; }
1085 static ETL_CONSTEXPR unsigned long long quiet_NaN() { return 0U; }
1086 static ETL_CONSTEXPR unsigned long long signaling_NaN() { return 0U; }
1087 };
1088
1089 //***************************************************************************
1090 // float
1091 template<>
1092 class numeric_limits<float> : public private_limits::floating_point_limits_common<>,
1093 public private_limits::floating_point_limits_float<>
1094 {
1095 public:
1096
1097 static ETL_CONSTEXPR float min() { return FLT_MIN; }
1098 static ETL_CONSTEXPR float max() { return FLT_MAX; }
1099 static ETL_CONSTEXPR float lowest() { return -FLT_MAX; }
1100 static ETL_CONSTEXPR float epsilon() { return FLT_EPSILON; }
1101 static ETL_CONSTEXPR float denorm_min() { return FLT_MIN; }
1102 static ETL_CONSTEXPR float infinity() { return HUGE_VALF; }
1103 static float round_error() { return 0.5f; }
1104 static float quiet_NaN() { return ETL_NANF; }
1105 static float signaling_NaN() { return ETL_NANF; }
1106 };
1107
1108 //***************************************************************************
1109 // double
1110 template<>
1111 class numeric_limits<double> : public private_limits::floating_point_limits_common<>,
1112 public private_limits::floating_point_limits_double<>
1113 {
1114 public:
1115
1116 static ETL_CONSTEXPR double min() { return DBL_MIN; }
1117 static ETL_CONSTEXPR double max() { return DBL_MAX; }
1118 static ETL_CONSTEXPR double lowest() { return -DBL_MAX; }
1119 static ETL_CONSTEXPR double epsilon() { return DBL_EPSILON; }
1120 static ETL_CONSTEXPR double denorm_min() { return DBL_MIN; }
1121 static ETL_CONSTEXPR double infinity() { return HUGE_VAL; }
1122 static double round_error() { return 0.5; }
1123 static double quiet_NaN() { return ETL_NAN; }
1124 static double signaling_NaN() { return ETL_NAN; }
1125 };
1126
1127 //***************************************************************************
1128 // long double
1129 template<>
1130 class numeric_limits<long double> : public private_limits::floating_point_limits_common<>,
1131 public private_limits::floating_point_limits_long_double<>
1132 {
1133 public:
1134
1135 static ETL_CONSTEXPR long double min() { return LDBL_MIN; }
1136 static ETL_CONSTEXPR long double max() { return LDBL_MAX; }
1137 static ETL_CONSTEXPR long double lowest() { return -LDBL_MAX; }
1138 static ETL_CONSTEXPR long double epsilon() { return LDBL_EPSILON; }
1139 static ETL_CONSTEXPR long double denorm_min() { return LDBL_MIN; }
1140 static ETL_CONSTEXPR long double infinity() { return HUGE_VALL; }
1141 static long double round_error() { return 0.5L; }
1142 static long double quiet_NaN() { return ETL_NANL; }
1143 static long double signaling_NaN() { return ETL_NANL; }
1144 };
1145}
1146
1147#else
1148
1149#include <limits>
1150
1151namespace etl
1152{
1153 enum float_round_style
1154 {
1155 round_indeterminate = std::round_indeterminate,
1156 round_toward_zero = std::round_toward_zero,
1157 round_to_nearest = std::round_to_nearest,
1158 round_toward_infinity = std::round_toward_infinity,
1159 round_toward_neg_infinity = std::round_toward_neg_infinity,
1160 };
1161
1162 enum float_denorm_style
1163 {
1164 denorm_indeterminate = std::denorm_indeterminate,
1165 denorm_absent = std::denorm_absent,
1166 denorm_present = std::denorm_present
1167 };
1168
1169#if ETL_USING_CPP11
1170 template <typename T>
1171 using numeric_limits = std::numeric_limits<T>;
1172#else
1173 template <typename T>
1174 class numeric_limits : public std::numeric_limits<T>
1175 {
1176 };
1177#endif
1178}
1179#endif
1180
1181#if defined(ETL_COMPILER_MICROSOFT)
1182 #pragma warning(pop)
1183#endif
1184
1185#include "private/minmax_pop.h"
1186
1187#endif
Definition limits.h:1175
is_signed
Definition type_traits_generator.h:1006
is_unsigned
Definition type_traits_generator.h:1016
bitset_ext
Definition absolute.h:38
ETL_CONSTEXPR pair()
Default constructor.
Definition utility.h:176