/elec/propeller-clock

To get this branch, use:
bzr branch http://bzr.ed.am/elec/propeller-clock
57 by edam
added ulibc
1
/*	Copyright (C) 2006 Garrett A. Kajmowicz
2
	This file is part of the uClibc++ Library.
3
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.
8
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.
13
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
17
*/
18
19
#include <climits>
20
21
#ifndef __STD_HEADER_LIMITS
22
#define __STD_HEADER_LIMITS 1
23
24
// Yeah, yeah we know
25
//#warning limits header is nowhere complete or accurate
26
27
#pragma GCC visibility push(default)
28
29
namespace std{
30
31
enum float_round_style{
32
	round_indeterminate		=-1,
33
	round_toward_zero		= 0,
34
	round_to_nearest		= 1,
35
	round_toward_infinity		= 2,
36
	round_toward_neg_infinity	= 3
37
};
38
39
template <int bitsize> struct __bits_to_base_10{
40
	static const int size = -1;
41
};
42
template <> struct __bits_to_base_10<7>{
43
	static const int size = 2;
44
};
45
template <> struct __bits_to_base_10<8>{
46
	static const int size = 2;
47
};
48
template <> struct __bits_to_base_10<9>{
49
	static const int size = 2;
50
};
51
template <> struct __bits_to_base_10<10>{
52
	static const int size = 3;
53
};
54
template <> struct __bits_to_base_10<15>{
55
	static const int size = 4;
56
};
57
template <> struct __bits_to_base_10<16>{
58
	static const int size = 4;
59
};
60
template <> struct __bits_to_base_10<17>{
61
	static const int size = 5;
62
};
63
template <> struct __bits_to_base_10<18>{
64
	static const int size = 5;
65
};
66
template <> struct __bits_to_base_10<31>{
67
	static const int size = 9;
68
};
69
template <> struct __bits_to_base_10<32>{
70
	static const int size = 9;
71
};
72
template <> struct __bits_to_base_10<35>{
73
	static const int size = 10;
74
};
75
template <> struct __bits_to_base_10<36>{
76
	static const int size = 10;
77
};
78
template <> struct __bits_to_base_10<63>{
79
	static const int size = 18;
80
};
81
template <> struct __bits_to_base_10<64>{
82
	static const int size = 19;
83
};
84
template <> struct __bits_to_base_10<71>{
85
	static const int size = 21;
86
};
87
template <> struct __bits_to_base_10<72>{
88
	static const int size = 21;
89
};
90
template <> struct __bits_to_base_10<79>{
91
	static const int size = 23;
92
};
93
template <> struct __bits_to_base_10<80>{
94
	static const int size = 24;
95
};
96
template <> struct __bits_to_base_10<127>{
97
	static const int size = 38;
98
};
99
template <> struct __bits_to_base_10<128>{
100
	static const int size = 38;
101
};
102
103
104
105
106
107
108
template <class T> class numeric_limits {
109
public:
110
	// General -- meaningful for all specializations.
111
112
	static const bool is_specialized = false;
113
	static T min();
114
	static T max();
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;
124
125
	// Floating point specific.
126
127
	static T epsilon();
128
	static T round_error();
129
	static const int min_exponent10;
130
	static const int max_exponent10;
131
	static const int min_exponent;
132
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();
142
	static T infinity();
143
	static T quiet_NaN();
144
	static T signaling_NaN();
145
};
146
147
template <> class numeric_limits<bool> {
148
public:
149
	typedef bool T;
150
	// General -- meaningful for all specializations.
151
	static const bool is_specialized = true;
152
	static T min(){
153
		return false;
154
	}
155
	static T max(){
156
		return true;
157
	}
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;
167
168
	// Floating point specific.
169
170
	static T epsilon(){
171
		return 0;
172
	}
173
	static T round_error(){
174
		return 0;
175
	}
176
	static const int min_exponent10 = 0;
177
	static const int max_exponent10 = 0;
178
	static const int min_exponent = 0;
179
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();
189
	static T infinity();
190
	static T quiet_NaN();
191
	static T signaling_NaN();
192
};
193
194
template <> class numeric_limits<unsigned char> {
195
public:
196
	typedef unsigned char T;
197
	// General -- meaningful for all specializations.
198
	static const bool is_specialized = true;
199
	static T min(){
200
		return 0;
201
	}
202
	static T max(){
203
		return UCHAR_MAX;
204
	}
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;
214
215
	// Floating point specific.
216
217
	static T epsilon(){
218
		return 0;
219
	}
220
	static T round_error(){
221
		return 0;
222
	}
223
	static const int min_exponent10 = 0;
224
	static const int max_exponent10 = 0;
225
	static const int min_exponent = 0;
226
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();
236
	static T infinity();
237
	static T quiet_NaN();
238
	static T signaling_NaN();
239
};
240
241
template <> class numeric_limits<signed char> {
242
public:
243
	typedef signed char T;
244
	// General -- meaningful for all specializations.
245
	static const bool is_specialized = true;
246
	static T min(){
247
		return SCHAR_MIN;
248
	}
249
	static T max(){
250
		return SCHAR_MAX;
251
	}
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;
261
262
	// Floating point specific.
263
264
	static T epsilon(){
265
		return 0;
266
	}
267
	static T round_error(){
268
		return 0;
269
	}
270
	static const int min_exponent10 = 0;
271
	static const int max_exponent10 = 0;
272
	static const int min_exponent = 0;
273
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();
283
	static T infinity();
284
	static T quiet_NaN();
285
	static T signaling_NaN();
286
};
287
288
template <> class numeric_limits<char> {
289
public:
290
	typedef char T;
291
	// General -- meaningful for all specializations.
292
	static const bool is_specialized = true;
293
	static T min(){
294
		return CHAR_MIN;
295
	}
296
	static T max(){
297
		return CHAR_MAX;
298
	}
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;
308
309
	// Floating point specific.
310
311
	static T epsilon(){
312
		return 0;
313
	}
314
	static T round_error(){
315
		return 0;
316
	}
317
	static const int min_exponent10 = 0;
318
	static const int max_exponent10 = 0;
319
	static const int min_exponent = 0;
320
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();
330
	static T infinity();
331
	static T quiet_NaN();
332
	static T signaling_NaN();
333
};
334
335
template <> class numeric_limits<unsigned short> {
336
public:
337
	typedef unsigned short T;
338
	// General -- meaningful for all specializations.
339
	static const bool is_specialized = true;
340
	static T min(){
341
		return 0;
342
	}
343
	static T max(){
344
		return USHRT_MAX;
345
	}
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;
355
356
	// Floating point specific.
357
358
	static T epsilon(){
359
		return 0;
360
	}
361
	static T round_error(){
362
		return 0;
363
	}
364
	static const int min_exponent10 = 0;
365
	static const int max_exponent10 = 0;
366
	static const int min_exponent = 0;
367
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();
377
	static T infinity();
378
	static T quiet_NaN();
379
	static T signaling_NaN();
380
};
381
382
template <> class numeric_limits<signed short> {
383
public:
384
	typedef signed short T;
385
	// General -- meaningful for all specializations.
386
	static const bool is_specialized = true;
387
	static T min(){
388
		return SHRT_MIN;
389
	}
390
	static T max(){
391
		return SHRT_MAX;
392
	}
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;
402
403
	// Floating point specific.
404
405
	static T epsilon(){
406
		return 0;
407
	}
408
	static T round_error(){
409
		return 0;
410
	}
411
	static const int min_exponent10 = 0;
412
	static const int max_exponent10 = 0;
413
	static const int min_exponent = 0;
414
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();
424
	static T infinity();
425
	static T quiet_NaN();
426
	static T signaling_NaN();
427
};
428
429
template <> class numeric_limits<unsigned int> {
430
public:
431
	typedef unsigned int T;
432
	// General -- meaningful for all specializations.
433
	static const bool is_specialized = true;
434
	static T min(){
435
		return 0;
436
	}
437
	static T max(){
438
		return UINT_MAX;
439
	}
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;
449
450
	// Floating point specific.
451
452
	static T epsilon(){
453
		return 0;
454
	}
455
	static T round_error(){
456
		return 0;
457
	}
458
	static const int min_exponent10 = 0;
459
	static const int max_exponent10 = 0;
460
	static const int min_exponent = 0;
461
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();
471
	static T infinity();
472
	static T quiet_NaN();
473
	static T signaling_NaN();
474
};
475
476
template <> class numeric_limits<signed int> {
477
public:
478
	typedef signed int T;
479
	// General -- meaningful for all specializations.
480
	static const bool is_specialized = true;
481
	static T min(){
482
		return INT_MIN;
483
	}
484
	static T max(){
485
		return INT_MAX;
486
	}
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;
496
497
	// Floating point specific.
498
499
	static T epsilon(){
500
		return 0;
501
	}
502
	static T round_error(){
503
		return 0;
504
	}
505
	static const int min_exponent10 = 0;
506
	static const int max_exponent10 = 0;
507
	static const int min_exponent = 0;
508
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();
518
	static T infinity();
519
	static T quiet_NaN();
520
	static T signaling_NaN();
521
};
522
523
template <> class numeric_limits<unsigned long int> {
524
public:
525
	typedef unsigned long int T;
526
	// General -- meaningful for all specializations.
527
	static const bool is_specialized = true;
528
	static T min(){
529
		return 0;
530
	}
531
	static T max(){
532
		return ULONG_MAX;
533
	}
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;
543
544
	// Floating point specific.
545
546
	static T epsilon(){
547
		return 0;
548
	}
549
	static T round_error(){
550
		return 0;
551
	}
552
	static const int min_exponent10 = 0;
553
	static const int max_exponent10 = 0;
554
	static const int min_exponent = 0;
555
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();
565
	static T infinity();
566
	static T quiet_NaN();
567
	static T signaling_NaN();
568
};
569
570
template <> class numeric_limits<signed long int> {
571
public:
572
	typedef signed long int T;
573
	// General -- meaningful for all specializations.
574
	static const bool is_specialized = true;
575
	static T min(){
576
		return LONG_MIN;
577
	}
578
	static T max(){
579
		return LONG_MAX;
580
	}
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;
590
591
	// Floating point specific.
592
593
	static T epsilon(){
594
		return 0;
595
	}
596
	static T round_error(){
597
		return 0;
598
	}
599
	static const int min_exponent10 = 0;
600
	static const int max_exponent10 = 0;
601
	static const int min_exponent = 0;
602
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();
612
	static T infinity();
613
	static T quiet_NaN();
614
	static T signaling_NaN();
615
};
616
617
template <> class numeric_limits<double> {
618
public:
619
	typedef double numeric_type;
620
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;
633
634
	// Floating point specific.
635
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
646
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?
654
};
655
656
657
658
659
660
}
661
662
#pragma GCC visibility pop
663
664
#endif