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