stdgpu/limits.h Source File

stdgpu/limits.h Source File#

stdgpu: stdgpu/limits.h Source File
stdgpu Latest
Efficient STL-like Data Structures on the GPU
limits.h
Go to the documentation of this file.
1/*
2 * Copyright 2019 Patrick Stotko
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16#ifndef STDGPU_LIMITS_H
17#define STDGPU_LIMITS_H
18
28#include <cfloat>
29#include <climits>
30
31#include <stdgpu/compiler.h>
32#include <stdgpu/platform.h>
33
34namespace stdgpu
35{
36
42template <class T>
44{
49 static constexpr STDGPU_HOST_DEVICE T
50 min() noexcept;
51
56 static constexpr STDGPU_HOST_DEVICE T
57 max() noexcept;
58
63 static constexpr STDGPU_HOST_DEVICE T
64 lowest() noexcept;
65
70 static constexpr STDGPU_HOST_DEVICE T
71 epsilon() noexcept;
72
77 static constexpr STDGPU_HOST_DEVICE T
78 round_error() noexcept;
79
84 static constexpr STDGPU_HOST_DEVICE T
85 infinity() noexcept;
86
90 static constexpr bool is_specialized = false;
91
95 static constexpr bool is_signed = false;
96
100 static constexpr bool is_integer = false;
101
105 static constexpr bool is_exact = false;
106
110 static constexpr int digits = 0;
111
115 static constexpr int radix = 0;
116};
117
122template <>
123struct numeric_limits<bool>
124{
129 static constexpr STDGPU_HOST_DEVICE bool
130 min() noexcept;
131
136 static constexpr STDGPU_HOST_DEVICE bool
137 max() noexcept;
138
143 static constexpr STDGPU_HOST_DEVICE bool
144 lowest() noexcept;
145
150 static constexpr STDGPU_HOST_DEVICE bool
151 epsilon() noexcept;
152
157 static constexpr STDGPU_HOST_DEVICE bool
158 round_error() noexcept;
159
164 static constexpr STDGPU_HOST_DEVICE bool
165 infinity() noexcept;
166
170 static constexpr bool is_specialized = true;
171
175 static constexpr bool is_signed = false;
176
180 static constexpr bool is_integer = true;
181
185 static constexpr bool is_exact = true;
186
190 static constexpr int digits = 1;
191
195 static constexpr int radix = 2;
196};
197
202template <>
203struct numeric_limits<char>
204{
209 static constexpr STDGPU_HOST_DEVICE char
210 min() noexcept;
211
216 static constexpr STDGPU_HOST_DEVICE char
217 max() noexcept;
218
223 static constexpr STDGPU_HOST_DEVICE char
224 lowest() noexcept;
225
230 static constexpr STDGPU_HOST_DEVICE char
231 epsilon() noexcept;
232
237 static constexpr STDGPU_HOST_DEVICE char
238 round_error() noexcept;
239
244 static constexpr STDGPU_HOST_DEVICE char
245 infinity() noexcept;
246
250 static constexpr bool is_specialized = true;
251
256 static constexpr bool is_signed = (static_cast<char>(-1) < 0);
257
261 static constexpr bool is_integer = true;
262
266 static constexpr bool is_exact = true;
267
271 static constexpr int digits = CHAR_BIT - static_cast<int>(numeric_limits<char>::is_signed);
272
276 static constexpr int radix = 2;
277};
278
283template <>
284struct numeric_limits<signed char>
285{
290 static constexpr STDGPU_HOST_DEVICE signed char
291 min() noexcept;
292
297 static constexpr STDGPU_HOST_DEVICE signed char
298 max() noexcept;
299
304 static constexpr STDGPU_HOST_DEVICE signed char
305 lowest() noexcept;
306
311 static constexpr STDGPU_HOST_DEVICE signed char
312 epsilon() noexcept;
313
318 static constexpr STDGPU_HOST_DEVICE signed char
319 round_error() noexcept;
320
325 static constexpr STDGPU_HOST_DEVICE signed char
326 infinity() noexcept;
327
331 static constexpr bool is_specialized = true;
332
336 static constexpr bool is_signed = true;
337
341 static constexpr bool is_integer = true;
342
346 static constexpr bool is_exact = true;
347
351 static constexpr int digits = CHAR_BIT - 1;
352
356 static constexpr int radix = 2;
357};
358
363template <>
364struct numeric_limits<unsigned char>
365{
370 static constexpr STDGPU_HOST_DEVICE unsigned char
371 min() noexcept;
372
377 static constexpr STDGPU_HOST_DEVICE unsigned char
378 max() noexcept;
379
384 static constexpr STDGPU_HOST_DEVICE unsigned char
385 lowest() noexcept;
386
391 static constexpr STDGPU_HOST_DEVICE unsigned char
392 epsilon() noexcept;
393
398 static constexpr STDGPU_HOST_DEVICE unsigned char
399 round_error() noexcept;
400
405 static constexpr STDGPU_HOST_DEVICE unsigned char
406 infinity() noexcept;
407
411 static constexpr bool is_specialized = true;
412
416 static constexpr bool is_signed = false;
417
421 static constexpr bool is_integer = true;
422
426 static constexpr bool is_exact = true;
427
431 static constexpr int digits = CHAR_BIT;
432
436 static constexpr int radix = 2;
437};
438
443template <>
444struct numeric_limits<wchar_t>
445{
450 static constexpr STDGPU_HOST_DEVICE wchar_t
451 min() noexcept;
452
457 static constexpr STDGPU_HOST_DEVICE wchar_t
458 max() noexcept;
459
464 static constexpr STDGPU_HOST_DEVICE wchar_t
465 lowest() noexcept;
466
471 static constexpr STDGPU_HOST_DEVICE wchar_t
472 epsilon() noexcept;
473
478 static constexpr STDGPU_HOST_DEVICE wchar_t
479 round_error() noexcept;
480
485 static constexpr STDGPU_HOST_DEVICE wchar_t
486 infinity() noexcept;
487
491 static constexpr bool is_specialized = true;
492
498 static constexpr bool is_signed = (static_cast<wchar_t>(-1) < 0);
499
503 static constexpr bool is_integer = true;
504
508 static constexpr bool is_exact = true;
509
513 static constexpr int digits = CHAR_BIT * sizeof(wchar_t) - static_cast<int>(numeric_limits<wchar_t>::is_signed);
514
518 static constexpr int radix = 2;
519};
520
525template <>
526struct numeric_limits<char16_t>
527{
532 static constexpr STDGPU_HOST_DEVICE char16_t
533 min() noexcept;
534
539 static constexpr STDGPU_HOST_DEVICE char16_t
540 max() noexcept;
541
546 static constexpr STDGPU_HOST_DEVICE char16_t
547 lowest() noexcept;
548
553 static constexpr STDGPU_HOST_DEVICE char16_t
554 epsilon() noexcept;
555
560 static constexpr STDGPU_HOST_DEVICE char16_t
561 round_error() noexcept;
562
567 static constexpr STDGPU_HOST_DEVICE char16_t
568 infinity() noexcept;
569
573 static constexpr bool is_specialized = true;
574
578 static constexpr bool is_signed = false;
579
583 static constexpr bool is_integer = true;
584
588 static constexpr bool is_exact = true;
589
593 static constexpr int digits = CHAR_BIT * sizeof(char16_t);
594
598 static constexpr int radix = 2;
599};
600
605template <>
606struct numeric_limits<char32_t>
607{
612 static constexpr STDGPU_HOST_DEVICE char32_t
613 min() noexcept;
614
619 static constexpr STDGPU_HOST_DEVICE char32_t
620 max() noexcept;
621
626 static constexpr STDGPU_HOST_DEVICE char32_t
627 lowest() noexcept;
628
633 static constexpr STDGPU_HOST_DEVICE char32_t
634 epsilon() noexcept;
635
640 static constexpr STDGPU_HOST_DEVICE char32_t
641 round_error() noexcept;
642
647 static constexpr STDGPU_HOST_DEVICE char32_t
648 infinity() noexcept;
649
653 static constexpr bool is_specialized = true;
654
658 static constexpr bool is_signed = false;
659
663 static constexpr bool is_integer = true;
664
668 static constexpr bool is_exact = true;
669
673 static constexpr int digits = CHAR_BIT * sizeof(char32_t);
674
678 static constexpr int radix = 2;
679};
680
685template <>
686struct numeric_limits<short>
687{
692 static constexpr STDGPU_HOST_DEVICE short
693 min() noexcept;
694
699 static constexpr STDGPU_HOST_DEVICE short
700 max() noexcept;
701
706 static constexpr STDGPU_HOST_DEVICE short
707 lowest() noexcept;
708
713 static constexpr STDGPU_HOST_DEVICE short
714 epsilon() noexcept;
715
720 static constexpr STDGPU_HOST_DEVICE short
721 round_error() noexcept;
722
727 static constexpr STDGPU_HOST_DEVICE short
728 infinity() noexcept;
729
733 static constexpr bool is_specialized = true;
734
738 static constexpr bool is_signed = true;
739
743 static constexpr bool is_integer = true;
744
748 static constexpr bool is_exact = true;
749
753 static constexpr int digits = CHAR_BIT * sizeof(short) - 1;
754
758 static constexpr int radix = 2;
759};
760
765template <>
766struct numeric_limits<unsigned short>
767{
772 static constexpr STDGPU_HOST_DEVICE unsigned short
773 min() noexcept;
774
779 static constexpr STDGPU_HOST_DEVICE unsigned short
780 max() noexcept;
781
786 static constexpr STDGPU_HOST_DEVICE unsigned short
787 lowest() noexcept;
788
793 static constexpr STDGPU_HOST_DEVICE unsigned short
794 epsilon() noexcept;
795
800 static constexpr STDGPU_HOST_DEVICE unsigned short
801 round_error() noexcept;
802
807 static constexpr STDGPU_HOST_DEVICE unsigned short
808 infinity() noexcept;
809
813 static constexpr bool is_specialized = true;
814
818 static constexpr bool is_signed = false;
819
823 static constexpr bool is_integer = true;
824
828 static constexpr bool is_exact = true;
829
833 static constexpr int digits = CHAR_BIT * sizeof(unsigned short);
834
838 static constexpr int radix = 2;
839};
840
845template <>
846struct numeric_limits<int>
847{
852 static constexpr STDGPU_HOST_DEVICE int
853 min() noexcept;
854
859 static constexpr STDGPU_HOST_DEVICE int
860 max() noexcept;
861
866 static constexpr STDGPU_HOST_DEVICE int
867 lowest() noexcept;
868
873 static constexpr STDGPU_HOST_DEVICE int
874 epsilon() noexcept;
875
880 static constexpr STDGPU_HOST_DEVICE int
881 round_error() noexcept;
882
887 static constexpr STDGPU_HOST_DEVICE int
888 infinity() noexcept;
889
893 static constexpr bool is_specialized = true;
894
898 static constexpr bool is_signed = true;
899
903 static constexpr bool is_integer = true;
904
908 static constexpr bool is_exact = true;
909
913 static constexpr int digits = CHAR_BIT * sizeof(int) - 1;
914
918 static constexpr int radix = 2;
919};
920
925template <>
926struct numeric_limits<unsigned int>
927{
932 static constexpr STDGPU_HOST_DEVICE unsigned int
933 min() noexcept;
934
939 static constexpr STDGPU_HOST_DEVICE unsigned int
940 max() noexcept;
941
946 static constexpr STDGPU_HOST_DEVICE unsigned int
947 lowest() noexcept;
948
953 static constexpr STDGPU_HOST_DEVICE unsigned int
954 epsilon() noexcept;
955
960 static constexpr STDGPU_HOST_DEVICE unsigned int
961 round_error() noexcept;
962
967 static constexpr STDGPU_HOST_DEVICE unsigned int
968 infinity() noexcept;
969
973 static constexpr bool is_specialized = true;
974
978 static constexpr bool is_signed = false;
979
983 static constexpr bool is_integer = true;
984
988 static constexpr bool is_exact = true;
989
993 static constexpr int digits = CHAR_BIT * sizeof(unsigned int);
994
998 static constexpr int radix = 2;
999};
1000
1005template <>
1006struct numeric_limits<long>
1007{
1012 static constexpr STDGPU_HOST_DEVICE long
1013 min() noexcept;
1014
1019 static constexpr STDGPU_HOST_DEVICE long
1020 max() noexcept;
1021
1026 static constexpr STDGPU_HOST_DEVICE long
1027 lowest() noexcept;
1028
1033 static constexpr STDGPU_HOST_DEVICE long
1034 epsilon() noexcept;
1035
1040 static constexpr STDGPU_HOST_DEVICE long
1041 round_error() noexcept;
1042
1047 static constexpr STDGPU_HOST_DEVICE long
1048 infinity() noexcept;
1049
1053 static constexpr bool is_specialized = true;
1054
1058 static constexpr bool is_signed = true;
1059
1063 static constexpr bool is_integer = true;
1064
1068 static constexpr bool is_exact = true;
1069
1073 static constexpr int digits = CHAR_BIT * sizeof(long) - 1;
1074
1078 static constexpr int radix = 2;
1079};
1080
1085template <>
1086struct numeric_limits<unsigned long>
1087{
1092 static constexpr STDGPU_HOST_DEVICE unsigned long
1093 min() noexcept;
1094
1099 static constexpr STDGPU_HOST_DEVICE unsigned long
1100 max() noexcept;
1101
1106 static constexpr STDGPU_HOST_DEVICE unsigned long
1107 lowest() noexcept;
1108
1113 static constexpr STDGPU_HOST_DEVICE unsigned long
1114 epsilon() noexcept;
1115
1120 static constexpr STDGPU_HOST_DEVICE unsigned long
1121 round_error() noexcept;
1122
1127 static constexpr STDGPU_HOST_DEVICE unsigned long
1128 infinity() noexcept;
1129
1133 static constexpr bool is_specialized = true;
1134
1138 static constexpr bool is_signed = false;
1139
1143 static constexpr bool is_integer = true;
1144
1148 static constexpr bool is_exact = true;
1149
1153 static constexpr int digits = CHAR_BIT * sizeof(unsigned long);
1154
1158 static constexpr int radix = 2;
1159};
1160
1165template <>
1166struct numeric_limits<long long>
1167{
1172 static constexpr STDGPU_HOST_DEVICE long long
1173 min() noexcept;
1174
1179 static constexpr STDGPU_HOST_DEVICE long long
1180 max() noexcept;
1181
1186 static constexpr STDGPU_HOST_DEVICE long long
1187 lowest() noexcept;
1188
1193 static constexpr STDGPU_HOST_DEVICE long long
1194 epsilon() noexcept;
1195
1200 static constexpr STDGPU_HOST_DEVICE long long
1201 round_error() noexcept;
1202
1207 static constexpr STDGPU_HOST_DEVICE long long
1208 infinity() noexcept;
1209
1213 static constexpr bool is_specialized = true;
1214
1218 static constexpr bool is_signed = true;
1219
1223 static constexpr bool is_integer = true;
1224
1228 static constexpr bool is_exact = true;
1229
1233 static constexpr int digits = CHAR_BIT * sizeof(long long) - 1;
1234
1238 static constexpr int radix = 2;
1239};
1240
1245template <>
1246struct numeric_limits<unsigned long long>
1247{
1252 static constexpr STDGPU_HOST_DEVICE unsigned long long
1253 min() noexcept;
1254
1259 static constexpr STDGPU_HOST_DEVICE unsigned long long
1260 max() noexcept;
1261
1266 static constexpr STDGPU_HOST_DEVICE unsigned long long
1267 lowest() noexcept;
1268
1273 static constexpr STDGPU_HOST_DEVICE unsigned long long
1274 epsilon() noexcept;
1275
1280 static constexpr STDGPU_HOST_DEVICE unsigned long long
1281 round_error() noexcept;
1282
1287 static constexpr STDGPU_HOST_DEVICE unsigned long long
1288 infinity() noexcept;
1289
1293 static constexpr bool is_specialized = true;
1294
1298 static constexpr bool is_signed = false;
1299
1303 static constexpr bool is_integer = true;
1304
1308 static constexpr bool is_exact = true;
1309
1313 static constexpr int digits = CHAR_BIT * sizeof(unsigned long long);
1314
1318 static constexpr int radix = 2;
1319};
1320
1325template <>
1326struct numeric_limits<float>
1327{
1332 static constexpr STDGPU_HOST_DEVICE float
1333 min() noexcept;
1334
1339 static constexpr STDGPU_HOST_DEVICE float
1340 max() noexcept;
1341
1346 static constexpr STDGPU_HOST_DEVICE float
1347 lowest() noexcept;
1348
1353 static constexpr STDGPU_HOST_DEVICE float
1354 epsilon() noexcept;
1355
1360 static constexpr STDGPU_HOST_DEVICE float
1361 round_error() noexcept;
1362
1367 static constexpr STDGPU_HOST_DEVICE float
1368 infinity() noexcept;
1369
1373 static constexpr bool is_specialized = true;
1374
1378 static constexpr bool is_signed = true;
1379
1383 static constexpr bool is_integer = false;
1384
1388 static constexpr bool is_exact = false;
1389
1393 static constexpr int digits = FLT_MANT_DIG;
1394
1398 static constexpr int radix = FLT_RADIX;
1399};
1400
1405template <>
1406struct numeric_limits<double>
1407{
1412 static constexpr STDGPU_HOST_DEVICE double
1413 min() noexcept;
1414
1419 static constexpr STDGPU_HOST_DEVICE double
1420 max() noexcept;
1421
1426 static constexpr STDGPU_HOST_DEVICE double
1427 lowest() noexcept;
1428
1433 static constexpr STDGPU_HOST_DEVICE double
1434 epsilon() noexcept;
1435
1440 static constexpr STDGPU_HOST_DEVICE double
1441 round_error() noexcept;
1442
1447 static constexpr STDGPU_HOST_DEVICE double
1448 infinity() noexcept;
1449
1453 static constexpr bool is_specialized = true;
1454
1458 static constexpr bool is_signed = true;
1459
1463 static constexpr bool is_integer = false;
1464
1468 static constexpr bool is_exact = false;
1469
1473 static constexpr int digits = DBL_MANT_DIG;
1474
1478 static constexpr int radix = FLT_RADIX;
1479};
1480
1485template <>
1486struct numeric_limits<long double>
1487{
1492 static constexpr STDGPU_HOST_DEVICE long double
1493 min() noexcept;
1494
1499 static constexpr STDGPU_HOST_DEVICE long double
1500 max() noexcept;
1501
1506 static constexpr STDGPU_HOST_DEVICE long double
1507 lowest() noexcept;
1508
1513 static constexpr STDGPU_HOST_DEVICE long double
1514 epsilon() noexcept;
1515
1520 static constexpr STDGPU_HOST_DEVICE long double
1521 round_error() noexcept;
1522
1527 static constexpr STDGPU_HOST_DEVICE long double
1528 infinity() noexcept;
1529
1533 static constexpr bool is_specialized = true;
1534
1538 static constexpr bool is_signed = true;
1539
1543 static constexpr bool is_integer = false;
1544
1548 static constexpr bool is_exact = false;
1549
1553 static constexpr int digits = LDBL_MANT_DIG;
1554
1558 static constexpr int radix = FLT_RADIX;
1559};
1560
1561} // namespace stdgpu
1562
1563#include <stdgpu/impl/limits_detail.h>
1564
1565#endif // STDGPU_LIMITS_H
#define STDGPU_HOST_DEVICE
Platform-independent host device function annotation.
Definition: platform.h:77
static constexpr STDGPU_HOST_DEVICE bool min() noexcept
Smallest representable finite value.
static constexpr STDGPU_HOST_DEVICE char16_t min() noexcept
Smallest representable finite value.
static constexpr STDGPU_HOST_DEVICE char32_t min() noexcept
Smallest representable finite value.
static constexpr STDGPU_HOST_DEVICE char min() noexcept
Smallest representable finite value.
static constexpr STDGPU_HOST_DEVICE double min() noexcept
Smallest representable finite value.
static constexpr STDGPU_HOST_DEVICE float min() noexcept
Smallest representable finite value.
static constexpr STDGPU_HOST_DEVICE int min() noexcept
Smallest representable finite value.
static constexpr STDGPU_HOST_DEVICE long min() noexcept
Smallest representable finite value.
static constexpr STDGPU_HOST_DEVICE long double min() noexcept
Smallest representable finite value.
static constexpr STDGPU_HOST_DEVICE long long min() noexcept
Smallest representable finite value.
static constexpr STDGPU_HOST_DEVICE short min() noexcept
Smallest representable finite value.
static constexpr STDGPU_HOST_DEVICE signed char min() noexcept
Smallest representable finite value.
static constexpr STDGPU_HOST_DEVICE unsigned char min() noexcept
Smallest representable finite value.
static constexpr STDGPU_HOST_DEVICE unsigned int min() noexcept
Smallest representable finite value.
static constexpr STDGPU_HOST_DEVICE unsigned long min() noexcept
Smallest representable finite value.
static constexpr STDGPU_HOST_DEVICE unsigned long long min() noexcept
Smallest representable finite value.
static constexpr STDGPU_HOST_DEVICE unsigned short min() noexcept
Smallest representable finite value.
static constexpr STDGPU_HOST_DEVICE wchar_t min() noexcept
Smallest representable finite value.
static constexpr STDGPU_HOST_DEVICE T min() noexcept
Smallest representable finite value.
static constexpr STDGPU_HOST_DEVICE T lowest() noexcept
Lowest representable finite value.
static constexpr STDGPU_HOST_DEVICE T infinity() noexcept
Infinity value.
static constexpr STDGPU_HOST_DEVICE T max() noexcept
Largest representable finite value.
static constexpr STDGPU_HOST_DEVICE T round_error() noexcept
Maximum round error.
static constexpr STDGPU_HOST_DEVICE T epsilon() noexcept
Machine epsilon.
Generic traits.
Definition: limits.h:44
static constexpr int digits
Number of radix digits.
Definition: limits.h:110
static constexpr int radix
Integer base.
Definition: limits.h:115
static constexpr bool is_exact
Whether the type is exact.
Definition: limits.h:105
static constexpr bool is_specialized
Whether the traits of the type are specialized.
Definition: limits.h:90
static constexpr bool is_integer
Whether the type is an integer.
Definition: limits.h:100
static constexpr bool is_signed
Whether the type is signed.
Definition: limits.h:95