1
 
/*      Copyright (C) 2006 Garrett A. Kajmowicz
 
2
 
        This file is part of the uClibc++ Library.
 
4
 
        This library is free software; you can redistribute it and/or
 
5
 
        modify it under the terms of the GNU Lesser General Public
 
6
 
        License as published by the Free Software Foundation; either
 
7
 
        version 2.1 of the License, or (at your option) any later version.
 
9
 
        This library is distributed in the hope that it will be useful,
 
10
 
        but WITHOUT ANY WARRANTY; without even the implied warranty of
 
11
 
        MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
12
 
        Lesser General Public License for more details.
 
14
 
        You should have received a copy of the GNU Lesser General Public
 
15
 
        License along with this library; if not, write to the Free Software
 
16
 
        Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
21
 
#ifndef __STD_HEADER_LIMITS
 
22
 
#define __STD_HEADER_LIMITS 1
 
25
 
//#warning limits header is nowhere complete or accurate
 
27
 
#pragma GCC visibility push(default)
 
31
 
enum float_round_style{
 
32
 
        round_indeterminate             =-1,
 
33
 
        round_toward_zero               = 0,
 
35
 
        round_toward_infinity           = 2,
 
36
 
        round_toward_neg_infinity       = 3
 
39
 
template <int bitsize> struct __bits_to_base_10{
 
40
 
        static const int size = -1;
 
42
 
template <> struct __bits_to_base_10<7>{
 
43
 
        static const int size = 2;
 
45
 
template <> struct __bits_to_base_10<8>{
 
46
 
        static const int size = 2;
 
48
 
template <> struct __bits_to_base_10<9>{
 
49
 
        static const int size = 2;
 
51
 
template <> struct __bits_to_base_10<10>{
 
52
 
        static const int size = 3;
 
54
 
template <> struct __bits_to_base_10<15>{
 
55
 
        static const int size = 4;
 
57
 
template <> struct __bits_to_base_10<16>{
 
58
 
        static const int size = 4;
 
60
 
template <> struct __bits_to_base_10<17>{
 
61
 
        static const int size = 5;
 
63
 
template <> struct __bits_to_base_10<18>{
 
64
 
        static const int size = 5;
 
66
 
template <> struct __bits_to_base_10<31>{
 
67
 
        static const int size = 9;
 
69
 
template <> struct __bits_to_base_10<32>{
 
70
 
        static const int size = 9;
 
72
 
template <> struct __bits_to_base_10<35>{
 
73
 
        static const int size = 10;
 
75
 
template <> struct __bits_to_base_10<36>{
 
76
 
        static const int size = 10;
 
78
 
template <> struct __bits_to_base_10<63>{
 
79
 
        static const int size = 18;
 
81
 
template <> struct __bits_to_base_10<64>{
 
82
 
        static const int size = 19;
 
84
 
template <> struct __bits_to_base_10<71>{
 
85
 
        static const int size = 21;
 
87
 
template <> struct __bits_to_base_10<72>{
 
88
 
        static const int size = 21;
 
90
 
template <> struct __bits_to_base_10<79>{
 
91
 
        static const int size = 23;
 
93
 
template <> struct __bits_to_base_10<80>{
 
94
 
        static const int size = 24;
 
96
 
template <> struct __bits_to_base_10<127>{
 
97
 
        static const int size = 38;
 
99
 
template <> struct __bits_to_base_10<128>{
 
100
 
        static const int size = 38;
 
108
 
template <class T> class numeric_limits {
 
110
 
        // General -- meaningful for all specializations.
 
112
 
        static const bool is_specialized = false;
 
115
 
        static const int radix;
 
116
 
        static const int digits;
 
117
 
        static const int digits10;
 
118
 
        static const bool is_signed;
 
119
 
        static const bool is_integer;
 
120
 
        static const bool is_exact;
 
121
 
        static const bool traps;
 
122
 
        static const bool is_modulo;
 
123
 
        static const bool is_bounded;
 
125
 
        // Floating point specific.
 
128
 
        static T round_error();
 
129
 
        static const int min_exponent10;
 
130
 
        static const int max_exponent10;
 
131
 
        static const int min_exponent;
 
133
 
        static const int max_exponent;
 
134
 
        static const bool has_infinity;
 
135
 
        static const bool has_quiet_NaN;
 
136
 
        static const bool has_signaling_NaN;
 
137
 
        static const bool is_iec559;
 
138
 
        static const bool has_denorm;
 
139
 
        static const bool tinyness_before;
 
140
 
        static const float_round_style round_style;
 
141
 
        static T denorm_min();
 
143
 
        static T quiet_NaN();
 
144
 
        static T signaling_NaN();
 
147
 
template <> class numeric_limits<bool> {
 
150
 
        // General -- meaningful for all specializations.
 
151
 
        static const bool is_specialized = true;
 
158
 
        static const int radix = 2;
 
159
 
        static const int digits = 1;
 
160
 
        static const int digits10 = 0;
 
161
 
        static const bool is_signed = false;
 
162
 
        static const bool is_integer = true;
 
163
 
        static const bool is_exact = true;
 
164
 
        static const bool traps = false;
 
165
 
        static const bool is_modulo = false;
 
166
 
        static const bool is_bounded = true;
 
168
 
        // Floating point specific.
 
173
 
        static T round_error(){
 
176
 
        static const int min_exponent10 = 0;
 
177
 
        static const int max_exponent10 = 0;
 
178
 
        static const int min_exponent = 0;
 
180
 
        static const int max_exponent = 0;
 
181
 
        static const bool has_infinity = false;
 
182
 
        static const bool has_quiet_NaN = false;
 
183
 
        static const bool has_signaling_NaN = false;
 
184
 
        static const bool is_iec559 = false;
 
185
 
        static const bool has_denorm = false;
 
186
 
        static const bool tinyness_before = false;
 
187
 
        static const float_round_style round_style = round_indeterminate;
 
188
 
        static T denorm_min();
 
190
 
        static T quiet_NaN();
 
191
 
        static T signaling_NaN();
 
194
 
template <> class numeric_limits<unsigned char> {
 
196
 
        typedef unsigned char T;
 
197
 
        // General -- meaningful for all specializations.
 
198
 
        static const bool is_specialized = true;
 
205
 
        static const int radix = 2;
 
206
 
        static const int digits = CHAR_BIT;
 
207
 
        static const int digits10 = __bits_to_base_10<digits>::size;
 
208
 
        static const bool is_signed = false;
 
209
 
        static const bool is_integer = true;
 
210
 
        static const bool is_exact = true;
 
211
 
        static const bool traps = false;
 
212
 
        static const bool is_modulo = true;
 
213
 
        static const bool is_bounded = true;
 
215
 
        // Floating point specific.
 
220
 
        static T round_error(){
 
223
 
        static const int min_exponent10 = 0;
 
224
 
        static const int max_exponent10 = 0;
 
225
 
        static const int min_exponent = 0;
 
227
 
        static const int max_exponent = 0;
 
228
 
        static const bool has_infinity = false;
 
229
 
        static const bool has_quiet_NaN = false;
 
230
 
        static const bool has_signaling_NaN = false;
 
231
 
        static const bool is_iec559 = false;
 
232
 
        static const bool has_denorm = false;
 
233
 
        static const bool tinyness_before = false;
 
234
 
        static const float_round_style round_style = round_indeterminate;
 
235
 
        static T denorm_min();
 
237
 
        static T quiet_NaN();
 
238
 
        static T signaling_NaN();
 
241
 
template <> class numeric_limits<signed char> {
 
243
 
        typedef signed char T;
 
244
 
        // General -- meaningful for all specializations.
 
245
 
        static const bool is_specialized = true;
 
252
 
        static const int radix = 2;
 
253
 
        static const int digits = CHAR_BIT - 1;
 
254
 
        static const int digits10 = __bits_to_base_10<digits>::size;
 
255
 
        static const bool is_signed = true;
 
256
 
        static const bool is_integer = true;
 
257
 
        static const bool is_exact = true;
 
258
 
        static const bool traps = false;
 
259
 
        static const bool is_modulo = true;
 
260
 
        static const bool is_bounded = true;
 
262
 
        // Floating point specific.
 
267
 
        static T round_error(){
 
270
 
        static const int min_exponent10 = 0;
 
271
 
        static const int max_exponent10 = 0;
 
272
 
        static const int min_exponent = 0;
 
274
 
        static const int max_exponent = 0;
 
275
 
        static const bool has_infinity = false;
 
276
 
        static const bool has_quiet_NaN = false;
 
277
 
        static const bool has_signaling_NaN = false;
 
278
 
        static const bool is_iec559 = false;
 
279
 
        static const bool has_denorm = false;
 
280
 
        static const bool tinyness_before = false;
 
281
 
        static const float_round_style round_style = round_indeterminate;
 
282
 
        static T denorm_min();
 
284
 
        static T quiet_NaN();
 
285
 
        static T signaling_NaN();
 
288
 
template <> class numeric_limits<char> {
 
291
 
        // General -- meaningful for all specializations.
 
292
 
        static const bool is_specialized = true;
 
299
 
        static const int radix = 2;
 
300
 
        static const int digits = (CHAR_MIN != 0) ? CHAR_BIT - 1 : CHAR_BIT;
 
301
 
        static const int digits10 = __bits_to_base_10<digits>::size;
 
302
 
        static const bool is_signed = (CHAR_MIN != 0);
 
303
 
        static const bool is_integer = true;
 
304
 
        static const bool is_exact = true;
 
305
 
        static const bool traps = false;
 
306
 
        static const bool is_modulo = true;
 
307
 
        static const bool is_bounded = true;
 
309
 
        // Floating point specific.
 
314
 
        static T round_error(){
 
317
 
        static const int min_exponent10 = 0;
 
318
 
        static const int max_exponent10 = 0;
 
319
 
        static const int min_exponent = 0;
 
321
 
        static const int max_exponent = 0;
 
322
 
        static const bool has_infinity = false;
 
323
 
        static const bool has_quiet_NaN = false;
 
324
 
        static const bool has_signaling_NaN = false;
 
325
 
        static const bool is_iec559 = false;
 
326
 
        static const bool has_denorm = false;
 
327
 
        static const bool tinyness_before = false;
 
328
 
        static const float_round_style round_style = round_indeterminate;
 
329
 
        static T denorm_min();
 
331
 
        static T quiet_NaN();
 
332
 
        static T signaling_NaN();
 
335
 
template <> class numeric_limits<unsigned short> {
 
337
 
        typedef unsigned short T;
 
338
 
        // General -- meaningful for all specializations.
 
339
 
        static const bool is_specialized = true;
 
346
 
        static const int radix = 2;
 
347
 
        static const int digits = CHAR_BIT * sizeof(T);
 
348
 
        static const int digits10 = __bits_to_base_10<digits>::size;
 
349
 
        static const bool is_signed = false;
 
350
 
        static const bool is_integer = true;
 
351
 
        static const bool is_exact = true;
 
352
 
        static const bool traps = false;
 
353
 
        static const bool is_modulo = true;
 
354
 
        static const bool is_bounded = true;
 
356
 
        // Floating point specific.
 
361
 
        static T round_error(){
 
364
 
        static const int min_exponent10 = 0;
 
365
 
        static const int max_exponent10 = 0;
 
366
 
        static const int min_exponent = 0;
 
368
 
        static const int max_exponent = 0;
 
369
 
        static const bool has_infinity = false;
 
370
 
        static const bool has_quiet_NaN = false;
 
371
 
        static const bool has_signaling_NaN = false;
 
372
 
        static const bool is_iec559 = false;
 
373
 
        static const bool has_denorm = false;
 
374
 
        static const bool tinyness_before = false;
 
375
 
        static const float_round_style round_style = round_indeterminate;
 
376
 
        static T denorm_min();
 
378
 
        static T quiet_NaN();
 
379
 
        static T signaling_NaN();
 
382
 
template <> class numeric_limits<signed short> {
 
384
 
        typedef signed short T;
 
385
 
        // General -- meaningful for all specializations.
 
386
 
        static const bool is_specialized = true;
 
393
 
        static const int radix = 2;
 
394
 
        static const int digits = CHAR_BIT * sizeof(T);
 
395
 
        static const int digits10 = __bits_to_base_10<digits>::size;
 
396
 
        static const bool is_signed = true;
 
397
 
        static const bool is_integer = true;
 
398
 
        static const bool is_exact = true;
 
399
 
        static const bool traps = false;
 
400
 
        static const bool is_modulo = true;
 
401
 
        static const bool is_bounded = true;
 
403
 
        // Floating point specific.
 
408
 
        static T round_error(){
 
411
 
        static const int min_exponent10 = 0;
 
412
 
        static const int max_exponent10 = 0;
 
413
 
        static const int min_exponent = 0;
 
415
 
        static const int max_exponent = 0;
 
416
 
        static const bool has_infinity = false;
 
417
 
        static const bool has_quiet_NaN = false;
 
418
 
        static const bool has_signaling_NaN = false;
 
419
 
        static const bool is_iec559 = false;
 
420
 
        static const bool has_denorm = false;
 
421
 
        static const bool tinyness_before = false;
 
422
 
        static const float_round_style round_style = round_indeterminate;
 
423
 
        static T denorm_min();
 
425
 
        static T quiet_NaN();
 
426
 
        static T signaling_NaN();
 
429
 
template <> class numeric_limits<unsigned int> {
 
431
 
        typedef unsigned int T;
 
432
 
        // General -- meaningful for all specializations.
 
433
 
        static const bool is_specialized = true;
 
440
 
        static const int radix = 2;
 
441
 
        static const int digits = CHAR_BIT * sizeof(T);
 
442
 
        static const int digits10 = __bits_to_base_10<digits>::size;
 
443
 
        static const bool is_signed = false;
 
444
 
        static const bool is_integer = true;
 
445
 
        static const bool is_exact = true;
 
446
 
        static const bool traps = false;
 
447
 
        static const bool is_modulo = true;
 
448
 
        static const bool is_bounded = true;
 
450
 
        // Floating point specific.
 
455
 
        static T round_error(){
 
458
 
        static const int min_exponent10 = 0;
 
459
 
        static const int max_exponent10 = 0;
 
460
 
        static const int min_exponent = 0;
 
462
 
        static const int max_exponent = 0;
 
463
 
        static const bool has_infinity = false;
 
464
 
        static const bool has_quiet_NaN = false;
 
465
 
        static const bool has_signaling_NaN = false;
 
466
 
        static const bool is_iec559 = false;
 
467
 
        static const bool has_denorm = false;
 
468
 
        static const bool tinyness_before = false;
 
469
 
        static const float_round_style round_style = round_indeterminate;
 
470
 
        static T denorm_min();
 
472
 
        static T quiet_NaN();
 
473
 
        static T signaling_NaN();
 
476
 
template <> class numeric_limits<signed int> {
 
478
 
        typedef signed int T;
 
479
 
        // General -- meaningful for all specializations.
 
480
 
        static const bool is_specialized = true;
 
487
 
        static const int radix = 2;
 
488
 
        static const int digits = CHAR_BIT * sizeof(T);
 
489
 
        static const int digits10 = __bits_to_base_10<digits>::size;
 
490
 
        static const bool is_signed = true;
 
491
 
        static const bool is_integer = true;
 
492
 
        static const bool is_exact = true;
 
493
 
        static const bool traps = false;
 
494
 
        static const bool is_modulo = true;
 
495
 
        static const bool is_bounded = true;
 
497
 
        // Floating point specific.
 
502
 
        static T round_error(){
 
505
 
        static const int min_exponent10 = 0;
 
506
 
        static const int max_exponent10 = 0;
 
507
 
        static const int min_exponent = 0;
 
509
 
        static const int max_exponent = 0;
 
510
 
        static const bool has_infinity = false;
 
511
 
        static const bool has_quiet_NaN = false;
 
512
 
        static const bool has_signaling_NaN = false;
 
513
 
        static const bool is_iec559 = false;
 
514
 
        static const bool has_denorm = false;
 
515
 
        static const bool tinyness_before = false;
 
516
 
        static const float_round_style round_style = round_indeterminate;
 
517
 
        static T denorm_min();
 
519
 
        static T quiet_NaN();
 
520
 
        static T signaling_NaN();
 
523
 
template <> class numeric_limits<unsigned long int> {
 
525
 
        typedef unsigned long int T;
 
526
 
        // General -- meaningful for all specializations.
 
527
 
        static const bool is_specialized = true;
 
534
 
        static const int radix = 2;
 
535
 
        static const int digits = CHAR_BIT * sizeof(T);
 
536
 
        static const int digits10 = __bits_to_base_10<digits>::size;
 
537
 
        static const bool is_signed = false;
 
538
 
        static const bool is_integer = true;
 
539
 
        static const bool is_exact = true;
 
540
 
        static const bool traps = false;
 
541
 
        static const bool is_modulo = true;
 
542
 
        static const bool is_bounded = true;
 
544
 
        // Floating point specific.
 
549
 
        static T round_error(){
 
552
 
        static const int min_exponent10 = 0;
 
553
 
        static const int max_exponent10 = 0;
 
554
 
        static const int min_exponent = 0;
 
556
 
        static const int max_exponent = 0;
 
557
 
        static const bool has_infinity = false;
 
558
 
        static const bool has_quiet_NaN = false;
 
559
 
        static const bool has_signaling_NaN = false;
 
560
 
        static const bool is_iec559 = false;
 
561
 
        static const bool has_denorm = false;
 
562
 
        static const bool tinyness_before = false;
 
563
 
        static const float_round_style round_style = round_indeterminate;
 
564
 
        static T denorm_min();
 
566
 
        static T quiet_NaN();
 
567
 
        static T signaling_NaN();
 
570
 
template <> class numeric_limits<signed long int> {
 
572
 
        typedef signed long int T;
 
573
 
        // General -- meaningful for all specializations.
 
574
 
        static const bool is_specialized = true;
 
581
 
        static const int radix = 2;
 
582
 
        static const int digits = CHAR_BIT * sizeof(T);
 
583
 
        static const int digits10 = __bits_to_base_10<digits>::size;
 
584
 
        static const bool is_signed = true;
 
585
 
        static const bool is_integer = true;
 
586
 
        static const bool is_exact = true;
 
587
 
        static const bool traps = false;
 
588
 
        static const bool is_modulo = true;
 
589
 
        static const bool is_bounded = true;
 
591
 
        // Floating point specific.
 
596
 
        static T round_error(){
 
599
 
        static const int min_exponent10 = 0;
 
600
 
        static const int max_exponent10 = 0;
 
601
 
        static const int min_exponent = 0;
 
603
 
        static const int max_exponent = 0;
 
604
 
        static const bool has_infinity = false;
 
605
 
        static const bool has_quiet_NaN = false;
 
606
 
        static const bool has_signaling_NaN = false;
 
607
 
        static const bool is_iec559 = false;
 
608
 
        static const bool has_denorm = false;
 
609
 
        static const bool tinyness_before = false;
 
610
 
        static const float_round_style round_style = round_indeterminate;
 
611
 
        static T denorm_min();
 
613
 
        static T quiet_NaN();
 
614
 
        static T signaling_NaN();
 
617
 
template <> class numeric_limits<double> {
 
619
 
        typedef double numeric_type;
 
621
 
        static const bool is_specialized = true;
 
622
 
        static numeric_type min () { return __DBL_MIN__; }
 
623
 
        static numeric_type max () { return __DBL_MAX__; }
 
624
 
        static const int radix = __FLT_RADIX__;
 
625
 
        static const int digits = __DBL_MANT_DIG__;
 
626
 
        static const int digits10 = __DBL_DIG__;
 
627
 
        static const bool is_signed = true;
 
628
 
        static const bool is_integer = false;
 
629
 
        static const bool is_exact = false;
 
630
 
        static const bool traps = false; // this is a guess
 
631
 
        static const bool is_modulo = false;
 
632
 
        static const bool is_bounded = true;
 
634
 
        // Floating point specific.
 
636
 
        static numeric_type epsilon () { return __DBL_EPSILON__; }
 
637
 
        static numeric_type round_error () { return 0.5; }
 
638
 
        static const int min_exponent10 = -1; //How do I properly get this?
 
639
 
        static const int max_exponent10 = -1; //How do I properly get this?
 
640
 
        static const int min_exponent   = -1; //How do I properly get this?
 
641
 
        static const int max_exponent   = -1; //How do I properly get this?
 
642
 
        static const bool has_infinity  = false; //I don't know, so until I can find out, I'm saying no
 
643
 
        static const bool has_quiet_NaN = false; //I don't know, so until I can find out, I'm saying no
 
644
 
        static const bool has_signaling_NaN = false; //I don't know, so until I can find out, I'm saying no
 
645
 
        static const bool has_denorm = false; //I don't know, so until I can find out, I'm saying no
 
647
 
        static const bool is_iec559 = false;  //I don't know, so until I can find out, I'm saying no
 
648
 
        static const bool tinyness_before = false; // more questions
 
649
 
        static const float_round_style round_style = round_to_nearest; // more questions
 
650
 
        static numeric_type denorm_min () { return -1; } //How do I properly get this?
 
651
 
        static numeric_type infinity () { return -1; } //How do I properly get this?
 
652
 
        static numeric_type quiet_NaN () { return -1; } //How do I properly get this?
 
653
 
        static numeric_type signaling_NaN () { return -1; } //How do I properly get this?
 
662
 
#pragma GCC visibility pop