acme
Foundational cross-platform layer of the ca2 framework
Toggle main menu visibility
Loading...
Searching...
No Matches
numeric_info.h
1
#pragma once
2
3
4
#include <limits.h>
5
//#include <memory.h>
6
#include <float.h>
7
8
9
namespace
numeric_info_internal
10
{
11
12
class
numeric_info_base
13
{
14
public
:
15
16
static
const
bool
is_signed =
false
;
17
static
const
bool
is_integer =
false
;
18
19
};
20
21
22
template
<
typename
T >
23
class
numeric_info
:
24
public
numeric_info_base
25
{
26
public
:
27
28
typedef
T TYPE;
29
typedef
T OFFSET_TYPE;
30
31
static
constexpr
TYPE maximum()
32
{
33
return
(TYPE) 0;
34
}
35
static
constexpr
TYPE minimum()
36
{
37
return
(TYPE) 0;
38
}
39
static
constexpr
TYPE null()
40
{
41
return
(TYPE) 0;
42
}
43
static
constexpr
TYPE unitary()
44
{
45
return
(TYPE) 1;
46
}
47
static
inline
TYPE allset()
48
{
49
TYPE t;
50
memory_set(&t,0xff,
sizeof
(TYPE));
51
return
t;
52
}
53
54
55
56
};
57
58
59
class
numeric_integer_base
:
60
public
numeric_info_base
61
{
62
public
:
63
64
static
const
bool
is_integer =
true
;
65
66
};
67
68
69
class
numeric_floating_base
:
70
public
numeric_info_base
71
{
72
public
:
73
74
static
const
bool
is_integer =
false
;
75
76
};
77
78
79
template
< >
80
class
CLASS_DECL_ACME
numeric_info
< ::i8 > :
81
public
numeric_integer_base
82
{
83
public
:
84
85
typedef
::i8 TYPE;
86
typedef
::i8 OFFSET_TYPE;
87
88
static
consteval
TYPE maximum()
89
{
90
return
(TYPE)INT8_MAX;
91
}
92
static
consteval
TYPE minimum()
93
{
94
return
(TYPE)INT8_MIN;
95
}
96
static
consteval
TYPE null()
97
{
98
return
(TYPE)0;
99
}
100
static
consteval
TYPE unitary()
101
{
102
return
(TYPE)1;
103
}
104
// static inline TYPE allset()
105
// {
106
// TYPE t;
107
// memory_set(&t,0xff,sizeof(TYPE));
108
// return t;
109
// }
110
111
static
const
bool
is_signed =
true
;
112
113
};
114
115
template
< >
116
class
CLASS_DECL_ACME
numeric_info
< ::u8 > :
117
public
numeric_integer_base
118
{
119
public
:
120
121
typedef
::u8 TYPE;
122
typedef
::i8 OFFSET_TYPE;
123
124
static
consteval
TYPE maximum()
125
{
126
return
(TYPE)UINT8_MAX;
127
}
128
static
consteval
TYPE minimum()
129
{
130
return
(TYPE)0;
131
}
132
static
consteval
TYPE null()
133
{
134
return
(TYPE)0;
135
}
136
static
consteval
TYPE unitary()
137
{
138
return
(TYPE)1;
139
}
140
// static consteval TYPE allset()
141
// {
142
// TYPE t;
143
// memory_set(&t,0xff,sizeof(TYPE));
144
// return t;
145
// }
146
147
static
const
bool
is_signed =
false
;
148
149
};
150
template
< >
151
class
CLASS_DECL_ACME
numeric_info
< ::i16 > :
152
public
numeric_integer_base
153
{
154
public
:
155
156
typedef
::i16 TYPE;
157
typedef
::i16 OFFSET_TYPE;
158
159
static
consteval
TYPE maximum()
160
{
161
return
(TYPE)INT16_MAX;
162
}
163
static
consteval
TYPE minimum()
164
{
165
return
(TYPE)INT16_MIN;
166
}
167
static
consteval
TYPE null()
168
{
169
return
(TYPE)0;
170
}
171
static
consteval
TYPE unitary()
172
{
173
return
(TYPE)1;
174
}
175
// static consteval TYPE allset()
176
// {
177
// TYPE t;
178
// memory_set(&t,0xff,sizeof(TYPE));
179
// return t;
180
// }
181
182
static
const
bool
is_signed =
true
;
183
184
};
185
186
template
< >
187
class
CLASS_DECL_ACME
numeric_info
< ::u16 > :
188
public
numeric_integer_base
189
{
190
public
:
191
192
typedef
::u16 TYPE;
193
typedef
::i16 OFFSET_TYPE;
194
195
static
consteval
TYPE maximum()
196
{
197
return
(TYPE)UINT16_MAX;
198
}
199
static
consteval
TYPE minimum()
200
{
201
return
(TYPE)0;
202
}
203
static
consteval
TYPE null()
204
{
205
return
(TYPE)0;
206
}
207
static
consteval
TYPE unitary()
208
{
209
return
(TYPE)1;
210
}
211
// static inline TYPE allset()
212
// {
213
// TYPE t;
214
// memory_set(&t,0xff,sizeof(TYPE));
215
// return t;
216
// }
217
218
static
const
bool
is_signed =
false
;
219
220
};
221
222
template
< >
223
class
CLASS_DECL_ACME
numeric_info
< ::i32 > :
224
public
numeric_integer_base
225
{
226
public
:
227
228
typedef
::i32 TYPE;
229
typedef
::i32 OFFSET_TYPE;
230
231
static
consteval
TYPE maximum()
232
{
233
return
(TYPE)INT32_MAX;
234
}
235
static
consteval
TYPE minimum()
236
{
237
return
(TYPE)INT32_MIN;
238
}
239
static
consteval
TYPE null()
240
{
241
return
(TYPE)0;
242
}
243
static
consteval
TYPE unitary()
244
{
245
return
(TYPE)1;
246
}
247
// static consteval TYPE allset()
248
// {
249
// TYPE t;
250
// memory_set(&t,0xff,sizeof(TYPE));
251
// return t;
252
// }
253
254
static
const
bool
is_signed =
true
;
255
256
};
257
258
259
template
< >
260
class
CLASS_DECL_ACME
numeric_info
< long > :
261
public
numeric_integer_base
262
{
263
public
:
264
265
typedef
long
TYPE;
266
typedef
long
OFFSET_TYPE;
267
268
static
consteval
TYPE maximum()
269
{
270
#ifdef __LP64__
271
return
(TYPE)LLONG_MAX;
272
#else
273
return
(TYPE)LONG_MAX;
274
#endif
275
}
276
static
consteval
TYPE minimum()
277
{
278
#ifdef __LP64__
279
return
(TYPE)LLONG_MIN;
280
#else
281
return
(TYPE)LONG_MIN;
282
#endif
283
}
284
static
consteval
TYPE null()
285
{
286
return
(TYPE)0;
287
}
288
static
consteval
TYPE unitary()
289
{
290
return
(TYPE)1;
291
}
292
// static consteval TYPE allset()
293
// {
294
// TYPE t;
295
// memory_set(&t, 0xff, sizeof(TYPE));
296
// return t;
297
// }
298
299
static
const
bool
is_signed =
true
;
300
301
};
302
303
template
< >
304
class
CLASS_DECL_ACME
numeric_info
< ::i64 > :
305
public
numeric_integer_base
306
{
307
public
:
308
309
typedef
::i64 TYPE;
310
typedef
::i64 OFFSET_TYPE;
311
312
static
consteval
TYPE maximum()
313
{
314
return
(TYPE)LLONG_MAX;
315
}
316
static
consteval
TYPE minimum()
317
{
318
return
(TYPE)LLONG_MIN;
319
}
320
static
consteval
TYPE null()
321
{
322
return
(TYPE)0;
323
}
324
static
consteval
TYPE unitary()
325
{
326
return
(TYPE)1;
327
}
328
// static consteval TYPE allset()
329
// {
330
// TYPE t;
331
// memory_set(&t, 0xff, sizeof(TYPE));
332
// return t;
333
// }
334
335
static
const
bool
is_signed =
true
;
336
337
};
338
339
template
< >
340
class
CLASS_DECL_ACME
numeric_info
< ::u64 > :
341
public
numeric_integer_base
342
{
343
public
:
344
345
typedef
::u64 TYPE;
346
typedef
::i64 OFFSET_TYPE;
347
348
static
consteval
TYPE maximum()
349
{
350
return
(TYPE)ULLONG_MAX;
351
}
352
static
consteval
TYPE minimum()
353
{
354
return
(TYPE)0;
355
}
356
static
consteval
TYPE null()
357
{
358
return
(TYPE)0;
359
}
360
static
consteval
TYPE unitary()
361
{
362
return
(TYPE)1;
363
}
364
// static consteval TYPE allset()
365
// {
366
// TYPE t;
367
// memory_set(&t, 0xff, sizeof(TYPE));
368
// return t;
369
// }
370
371
static
const
bool
is_signed =
false
;
372
373
};
374
375
template
< >
376
class
CLASS_DECL_ACME
numeric_info
< ::u32 > :
377
public
numeric_integer_base
378
{
379
public
:
380
381
typedef
::u32 TYPE;
382
typedef
::i32 OFFSET_TYPE;
383
384
static
consteval
TYPE maximum()
385
{
386
return
(TYPE)UINT32_MAX;
387
}
388
static
consteval
TYPE minimum()
389
{
390
return
(TYPE)0;
391
}
392
static
consteval
TYPE null()
393
{
394
return
(TYPE)0;
395
}
396
static
consteval
TYPE unitary()
397
{
398
return
(TYPE)1;
399
}
400
// static consteval TYPE allset()
401
// {
402
// TYPE t;
403
// memory_set(&t,0xff,sizeof(TYPE));
404
// return t;
405
// }
406
407
static
const
bool
is_signed =
false
;
408
409
};
410
411
412
template
< >
413
class
CLASS_DECL_ACME
numeric_info
< ulong > :
414
public
numeric_integer_base
415
{
416
public
:
417
418
typedef
::u32 TYPE;
419
typedef
::i32 OFFSET_TYPE;
420
421
static
consteval
TYPE maximum()
422
{
423
return
(TYPE)ULONG_MAX;
424
}
425
static
consteval
TYPE minimum()
426
{
427
return
(TYPE)0;
428
}
429
static
consteval
TYPE null()
430
{
431
return
(TYPE)0;
432
}
433
static
consteval
TYPE unitary()
434
{
435
return
(TYPE)1;
436
}
437
// static consteval TYPE allset()
438
// {
439
// TYPE t;
440
// memory_set(&t, 0xff, sizeof(TYPE));
441
// return t;
442
// }
443
444
static
const
bool
is_signed =
false
;
445
446
};
447
448
#if !defined(GNU_COMPILER) \
449
&& !defined(FREEBSD) \
450
&& !defined(OPENBSD) \
451
&& !defined(WINDOWS_DESKTOP) \
452
&& !defined(__APPLE__) \
453
&& !defined(UNIVERSAL_WINDOWS) \
454
&& !defined(__ANDROID__)
455
456
template
< >
457
class
CLASS_DECL_ACME
numeric_info
< ::i64 > :
458
public
numeric_integer_base
459
{
460
public
:
461
462
typedef
::i64 TYPE;
463
typedef
::i64 OFFSET_TYPE;
464
465
static
consteval
TYPE maximum()
466
{
467
return
(TYPE)LLONG_MAX;
468
}
469
static
consteval
TYPE minimum()
470
{
471
return
(TYPE)LLONG_MIN;
472
}
473
static
consteval
TYPE null()
474
{
475
return
(TYPE)0;
476
}
477
static
consteval
TYPE unitary()
478
{
479
return
(TYPE)1;
480
}
481
//static consteval TYPE allset()
482
//{
483
// TYPE t;
484
// memory_set(&t,0xff,sizeof(TYPE));
485
// return t;
486
//}
487
488
static
const
bool
is_signed =
true
;
489
490
};
491
492
template
< >
493
class
CLASS_DECL_ACME
numeric_info
< ::u64 >:
494
public
numeric_integer_base
495
{
496
public
:
497
498
typedef
::u64 TYPE;
499
typedef
::i64 OFFSET_TYPE;
500
501
static
consteval
TYPE maximum()
502
{
503
return
(TYPE)ULLONG_MAX;
504
}
505
static
consteval
TYPE minimum()
506
{
507
return
(TYPE)0;
508
}
509
static
consteval
TYPE null()
510
{
511
return
(TYPE)0;
512
}
513
static
consteval
TYPE unitary()
514
{
515
return
(TYPE)1;
516
}
517
/*static consteval TYPE allset()
518
{
519
TYPE t;
520
memory_set(&t,0xff,sizeof(TYPE));
521
return t;
522
}*/
523
524
static
const
bool
is_signed =
false
;
525
526
};
527
528
529
#endif
530
531
532
template
< >
533
class
CLASS_DECL_ACME
numeric_info
< ::f32 >:
534
public
numeric_floating_base
535
{
536
public
:
537
538
typedef
::f32 TYPE;
539
typedef
::f32 OFFSET_TYPE;
540
541
static
consteval
TYPE maximum()
542
{
543
return
(TYPE)FLT_MAX;
544
}
545
static
consteval
TYPE minimum()
546
{
547
return
(TYPE)FLT_MIN;
548
}
549
static
consteval
TYPE null()
550
{
551
return
(TYPE)0.f;
552
}
553
static
consteval
TYPE unitary()
554
{
555
return
(TYPE)1.f;
556
}
557
// static consteval TYPE allset()
558
// {
559
// TYPE t;
560
// memory_set(&t,0xff,sizeof(TYPE));
561
// return t;
562
// }
563
564
};
565
566
567
568
template
< >
569
class
CLASS_DECL_ACME
numeric_info
< ::f64 >:
570
public
numeric_floating_base
571
{
572
public
:
573
574
typedef
::f64 TYPE;
575
typedef
::f64 OFFSET_TYPE;
576
577
578
static
consteval
TYPE maximum()
579
{
580
return
(TYPE)DBL_MAX;
581
}
582
static
consteval
TYPE minimum()
583
{
584
return
(TYPE)DBL_MIN;
585
}
586
static
consteval
TYPE null()
587
{
588
return
(TYPE)0.0;
589
}
590
static
consteval
TYPE unitary()
591
{
592
return
(TYPE)1.0;
593
}
594
// static consteval TYPE allset()
595
// {
596
// TYPE t;
597
// memory_set(&t,0xff,sizeof(TYPE));
598
// return t;
599
// }
600
601
static
const
bool
is_signed =
false
;
602
603
};
604
605
template
< >
606
class
CLASS_DECL_ACME
numeric_info
< std::strong_ordering >
607
{
608
public
:
609
610
using
INTERNAL_TYPE = std::strong_ordering;
611
612
using
INTERNAL_INFO = std::strong_ordering;
613
614
static
consteval
auto
null()
615
{
616
return
nullptr
;
617
}
618
//static consteval auto unitary()
619
//{
620
// return INTERNAL_INFO::unitary();
621
//}
622
//static consteval auto allset()
623
//{
624
// return INTERNAL_INFO::allset();
625
//}
626
//static consteval auto minimum()
627
//{
628
// return ;
629
//}
630
//static consteval auto maximum()
631
//{
632
// return 1;
633
//}
634
//template < typename T2 >
635
//static consteval auto natural(const T2 & t2)
636
//{
637
// return minimum(maximum(), maximum(null(), (T)t2));
638
//}
639
640
};
641
642
}
// namespace numeric_info_internal
643
644
template
<
typename
T>
645
struct
remove_const
{
646
using
type = T;
647
};
648
649
template
<
typename
T>
650
struct
remove_const
< const T > {
651
using
type = T;
652
};
653
654
template
<
typename
T>
655
struct
remove_reference
{
656
using
type = T;
657
};
658
659
template
<
typename
T>
660
struct
remove_reference
< T & > {
661
using
type = T;
662
};
663
664
template
<
typename
T>
665
struct
remove_reference
< T&& > {
666
using
type = T;
667
};
668
669
670
template
<
typename
T >
671
class
numeric_info
672
{
673
public
:
674
675
using
INTERNAL_TYPE =
typename
remove_reference < typename remove_const < T >::type>::type;
676
677
using
INTERNAL_INFO = numeric_info_internal::numeric_info < INTERNAL_TYPE > ;
678
679
static
consteval
auto
null()
680
{
681
return
INTERNAL_INFO::null();
682
}
683
static
consteval
auto
unitary()
684
{
685
return
INTERNAL_INFO::unitary();
686
}
687
static
consteval
auto
allset()
688
{
689
return
INTERNAL_INFO::allset();
690
}
691
static
consteval
auto
minimum()
692
{
693
return
INTERNAL_INFO::minimum();
694
}
695
static
consteval
auto
maximum()
696
{
697
return
INTERNAL_INFO::maximum();
698
}
699
template
<
typename
T2 >
700
static
consteval
auto
natural(
const
T2 & t2)
701
{
702
return
minimum(maximum(), maximum(null(), (T) t2));
703
}
704
705
};
706
707
708
//template < typename T, typename T2 >
709
//inline T clip_assign(T & t, const T2 & t2)
710
//{
711
// t = minimum(::numeric_info < T >::maximum(),maximum(::numeric_info < T >::minimum(),(T)t2));
712
//}
713
714
template
<
typename
T,
typename
T2 >
715
inline
T natural_assign(T & t,
const
T2 & t2)
716
{
717
t = minimum(::numeric_info < T >::maximum(),maximum(::numeric_info < T >::null(),(T)t2));
718
}
719
720
template
<
typename
T >
721
T & minimum(T & t)
722
{
723
724
return
t = numeric_info<T>::minimum();
725
726
}
727
728
729
template
<
typename
T >
730
T & maximum(T & t)
731
{
732
733
return
t = numeric_info<T>::maximum();
734
735
}
736
737
743
template
< prototype_
int
egral N >
744
constexpr
bool
is_bit_set(N n, ::i32 bit)
745
{
746
747
return
!(n & numeric_info < N >::unitary() << bit);
748
749
}
750
751
756
template
< prototype_
int
egral N >
757
constexpr ::i32 most_significant_bit_index(N n)
758
{
759
760
::i32 bit = sizeof_in_bits(N);
761
762
do
763
{
764
765
bit--;
766
767
if
(is_bit_set(n, bit))
768
{
769
770
return
bit;
771
772
}
773
774
}
while
(bit > 0);
775
776
return
-1;
777
778
}
779
780
781
782
numeric_info_internal::numeric_floating_base
Definition
numeric_info.h:71
numeric_info_internal::numeric_info_base
Definition
numeric_info.h:13
numeric_info_internal::numeric_info
Definition
numeric_info.h:25
numeric_info_internal::numeric_integer_base
Definition
numeric_info.h:61
numeric_info
Definition
numeric_info.h:672
remove_const
Definition
numeric_info.h:645
remove_reference
Definition
numeric_info.h:655
prototype
mathematics
numeric_info.h
Generated by
1.17.0