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 = true;
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#if STDGPU_HOST_COMPILER == STDGPU_HOST_COMPILER_MSVC
499 static constexpr bool is_signed = false;
500#else
501 static constexpr bool is_signed = true;
502#endif
503
507 static constexpr bool is_integer = true;
508
512 static constexpr bool is_exact = true;
513
517 static constexpr int digits = CHAR_BIT * sizeof(wchar_t) - static_cast<int>(numeric_limits<wchar_t>::is_signed);
518
522 static constexpr int radix = 2;
523};
524
529template <>
530struct numeric_limits<char16_t>
531{
536 static constexpr STDGPU_HOST_DEVICE char16_t
537 min() noexcept;
538
543 static constexpr STDGPU_HOST_DEVICE char16_t
544 max() noexcept;
545
550 static constexpr STDGPU_HOST_DEVICE char16_t
551 lowest() noexcept;
552
557 static constexpr STDGPU_HOST_DEVICE char16_t
558 epsilon() noexcept;
559
564 static constexpr STDGPU_HOST_DEVICE char16_t
565 round_error() noexcept;
566
571 static constexpr STDGPU_HOST_DEVICE char16_t
572 infinity() noexcept;
573
577 static constexpr bool is_specialized = true;
578
582 static constexpr bool is_signed = false;
583
587 static constexpr bool is_integer = true;
588
592 static constexpr bool is_exact = true;
593
597 static constexpr int digits = CHAR_BIT * sizeof(char16_t);
598
602 static constexpr int radix = 2;
603};
604
609template <>
610struct numeric_limits<char32_t>
611{
616 static constexpr STDGPU_HOST_DEVICE char32_t
617 min() noexcept;
618
623 static constexpr STDGPU_HOST_DEVICE char32_t
624 max() noexcept;
625
630 static constexpr STDGPU_HOST_DEVICE char32_t
631 lowest() noexcept;
632
637 static constexpr STDGPU_HOST_DEVICE char32_t
638 epsilon() noexcept;
639
644 static constexpr STDGPU_HOST_DEVICE char32_t
645 round_error() noexcept;
646
651 static constexpr STDGPU_HOST_DEVICE char32_t
652 infinity() noexcept;
653
657 static constexpr bool is_specialized = true;
658
662 static constexpr bool is_signed = false;
663
667 static constexpr bool is_integer = true;
668
672 static constexpr bool is_exact = true;
673
677 static constexpr int digits = CHAR_BIT * sizeof(char32_t);
678
682 static constexpr int radix = 2;
683};
684
689template <>
690struct numeric_limits<short>
691{
696 static constexpr STDGPU_HOST_DEVICE short
697 min() noexcept;
698
703 static constexpr STDGPU_HOST_DEVICE short
704 max() noexcept;
705
710 static constexpr STDGPU_HOST_DEVICE short
711 lowest() noexcept;
712
717 static constexpr STDGPU_HOST_DEVICE short
718 epsilon() noexcept;
719
724 static constexpr STDGPU_HOST_DEVICE short
725 round_error() noexcept;
726
731 static constexpr STDGPU_HOST_DEVICE short
732 infinity() noexcept;
733
737 static constexpr bool is_specialized = true;
738
742 static constexpr bool is_signed = true;
743
747 static constexpr bool is_integer = true;
748
752 static constexpr bool is_exact = true;
753
757 static constexpr int digits = CHAR_BIT * sizeof(short) - 1;
758
762 static constexpr int radix = 2;
763};
764
769template <>
770struct numeric_limits<unsigned short>
771{
776 static constexpr STDGPU_HOST_DEVICE unsigned short
777 min() noexcept;
778
783 static constexpr STDGPU_HOST_DEVICE unsigned short
784 max() noexcept;
785
790 static constexpr STDGPU_HOST_DEVICE unsigned short
791 lowest() noexcept;
792
797 static constexpr STDGPU_HOST_DEVICE unsigned short
798 epsilon() noexcept;
799
804 static constexpr STDGPU_HOST_DEVICE unsigned short
805 round_error() noexcept;
806
811 static constexpr STDGPU_HOST_DEVICE unsigned short
812 infinity() noexcept;
813
817 static constexpr bool is_specialized = true;
818
822 static constexpr bool is_signed = false;
823
827 static constexpr bool is_integer = true;
828
832 static constexpr bool is_exact = true;
833
837 static constexpr int digits = CHAR_BIT * sizeof(unsigned short);
838
842 static constexpr int radix = 2;
843};
844
849template <>
850struct numeric_limits<int>
851{
856 static constexpr STDGPU_HOST_DEVICE int
857 min() noexcept;
858
863 static constexpr STDGPU_HOST_DEVICE int
864 max() noexcept;
865
870 static constexpr STDGPU_HOST_DEVICE int
871 lowest() noexcept;
872
877 static constexpr STDGPU_HOST_DEVICE int
878 epsilon() noexcept;
879
884 static constexpr STDGPU_HOST_DEVICE int
885 round_error() noexcept;
886
891 static constexpr STDGPU_HOST_DEVICE int
892 infinity() noexcept;
893
897 static constexpr bool is_specialized = true;
898
902 static constexpr bool is_signed = true;
903
907 static constexpr bool is_integer = true;
908
912 static constexpr bool is_exact = true;
913
917 static constexpr int digits = CHAR_BIT * sizeof(int) - 1;
918
922 static constexpr int radix = 2;
923};
924
929template <>
930struct numeric_limits<unsigned int>
931{
936 static constexpr STDGPU_HOST_DEVICE unsigned int
937 min() noexcept;
938
943 static constexpr STDGPU_HOST_DEVICE unsigned int
944 max() noexcept;
945
950 static constexpr STDGPU_HOST_DEVICE unsigned int
951 lowest() noexcept;
952
957 static constexpr STDGPU_HOST_DEVICE unsigned int
958 epsilon() noexcept;
959
964 static constexpr STDGPU_HOST_DEVICE unsigned int
965 round_error() noexcept;
966
971 static constexpr STDGPU_HOST_DEVICE unsigned int
972 infinity() noexcept;
973
977 static constexpr bool is_specialized = true;
978
982 static constexpr bool is_signed = false;
983
987 static constexpr bool is_integer = true;
988
992 static constexpr bool is_exact = true;
993
997 static constexpr int digits = CHAR_BIT * sizeof(unsigned int);
998
1002 static constexpr int radix = 2;
1003};
1004
1009template <>
1010struct numeric_limits<long>
1011{
1016 static constexpr STDGPU_HOST_DEVICE long
1017 min() noexcept;
1018
1023 static constexpr STDGPU_HOST_DEVICE long
1024 max() noexcept;
1025
1030 static constexpr STDGPU_HOST_DEVICE long
1031 lowest() noexcept;
1032
1037 static constexpr STDGPU_HOST_DEVICE long
1038 epsilon() noexcept;
1039
1044 static constexpr STDGPU_HOST_DEVICE long
1045 round_error() noexcept;
1046
1051 static constexpr STDGPU_HOST_DEVICE long
1052 infinity() noexcept;
1053
1057 static constexpr bool is_specialized = true;
1058
1062 static constexpr bool is_signed = true;
1063
1067 static constexpr bool is_integer = true;
1068
1072 static constexpr bool is_exact = true;
1073
1077 static constexpr int digits = CHAR_BIT * sizeof(long) - 1;
1078
1082 static constexpr int radix = 2;
1083};
1084
1089template <>
1090struct numeric_limits<unsigned long>
1091{
1096 static constexpr STDGPU_HOST_DEVICE unsigned long
1097 min() noexcept;
1098
1103 static constexpr STDGPU_HOST_DEVICE unsigned long
1104 max() noexcept;
1105
1110 static constexpr STDGPU_HOST_DEVICE unsigned long
1111 lowest() noexcept;
1112
1117 static constexpr STDGPU_HOST_DEVICE unsigned long
1118 epsilon() noexcept;
1119
1124 static constexpr STDGPU_HOST_DEVICE unsigned long
1125 round_error() noexcept;
1126
1131 static constexpr STDGPU_HOST_DEVICE unsigned long
1132 infinity() noexcept;
1133
1137 static constexpr bool is_specialized = true;
1138
1142 static constexpr bool is_signed = false;
1143
1147 static constexpr bool is_integer = true;
1148
1152 static constexpr bool is_exact = true;
1153
1157 static constexpr int digits = CHAR_BIT * sizeof(unsigned long);
1158
1162 static constexpr int radix = 2;
1163};
1164
1169template <>
1170struct numeric_limits<long long>
1171{
1176 static constexpr STDGPU_HOST_DEVICE long long
1177 min() noexcept;
1178
1183 static constexpr STDGPU_HOST_DEVICE long long
1184 max() noexcept;
1185
1190 static constexpr STDGPU_HOST_DEVICE long long
1191 lowest() noexcept;
1192
1197 static constexpr STDGPU_HOST_DEVICE long long
1198 epsilon() noexcept;
1199
1204 static constexpr STDGPU_HOST_DEVICE long long
1205 round_error() noexcept;
1206
1211 static constexpr STDGPU_HOST_DEVICE long long
1212 infinity() noexcept;
1213
1217 static constexpr bool is_specialized = true;
1218
1222 static constexpr bool is_signed = true;
1223
1227 static constexpr bool is_integer = true;
1228
1232 static constexpr bool is_exact = true;
1233
1237 static constexpr int digits = CHAR_BIT * sizeof(long long) - 1;
1238
1242 static constexpr int radix = 2;
1243};
1244
1249template <>
1250struct numeric_limits<unsigned long long>
1251{
1256 static constexpr STDGPU_HOST_DEVICE unsigned long long
1257 min() noexcept;
1258
1263 static constexpr STDGPU_HOST_DEVICE unsigned long long
1264 max() noexcept;
1265
1270 static constexpr STDGPU_HOST_DEVICE unsigned long long
1271 lowest() noexcept;
1272
1277 static constexpr STDGPU_HOST_DEVICE unsigned long long
1278 epsilon() noexcept;
1279
1284 static constexpr STDGPU_HOST_DEVICE unsigned long long
1285 round_error() noexcept;
1286
1291 static constexpr STDGPU_HOST_DEVICE unsigned long long
1292 infinity() noexcept;
1293
1297 static constexpr bool is_specialized = true;
1298
1302 static constexpr bool is_signed = false;
1303
1307 static constexpr bool is_integer = true;
1308
1312 static constexpr bool is_exact = true;
1313
1317 static constexpr int digits = CHAR_BIT * sizeof(unsigned long long);
1318
1322 static constexpr int radix = 2;
1323};
1324
1329template <>
1330struct numeric_limits<float>
1331{
1336 static constexpr STDGPU_HOST_DEVICE float
1337 min() noexcept;
1338
1343 static constexpr STDGPU_HOST_DEVICE float
1344 max() noexcept;
1345
1350 static constexpr STDGPU_HOST_DEVICE float
1351 lowest() noexcept;
1352
1357 static constexpr STDGPU_HOST_DEVICE float
1358 epsilon() noexcept;
1359
1364 static constexpr STDGPU_HOST_DEVICE float
1365 round_error() noexcept;
1366
1371 static constexpr STDGPU_HOST_DEVICE float
1372 infinity() noexcept;
1373
1377 static constexpr bool is_specialized = true;
1378
1382 static constexpr bool is_signed = true;
1383
1387 static constexpr bool is_integer = false;
1388
1392 static constexpr bool is_exact = false;
1393
1397 static constexpr int digits = FLT_MANT_DIG;
1398
1402 static constexpr int radix = FLT_RADIX;
1403};
1404
1409template <>
1410struct numeric_limits<double>
1411{
1416 static constexpr STDGPU_HOST_DEVICE double
1417 min() noexcept;
1418
1423 static constexpr STDGPU_HOST_DEVICE double
1424 max() noexcept;
1425
1430 static constexpr STDGPU_HOST_DEVICE double
1431 lowest() noexcept;
1432
1437 static constexpr STDGPU_HOST_DEVICE double
1438 epsilon() noexcept;
1439
1444 static constexpr STDGPU_HOST_DEVICE double
1445 round_error() noexcept;
1446
1451 static constexpr STDGPU_HOST_DEVICE double
1452 infinity() noexcept;
1453
1457 static constexpr bool is_specialized = true;
1458
1462 static constexpr bool is_signed = true;
1463
1467 static constexpr bool is_integer = false;
1468
1472 static constexpr bool is_exact = false;
1473
1477 static constexpr int digits = DBL_MANT_DIG;
1478
1482 static constexpr int radix = FLT_RADIX;
1483};
1484
1489template <>
1490struct numeric_limits<long double>
1491{
1496 static constexpr STDGPU_HOST_DEVICE long double
1497 min() noexcept;
1498
1503 static constexpr STDGPU_HOST_DEVICE long double
1504 max() noexcept;
1505
1510 static constexpr STDGPU_HOST_DEVICE long double
1511 lowest() noexcept;
1512
1517 static constexpr STDGPU_HOST_DEVICE long double
1518 epsilon() noexcept;
1519
1524 static constexpr STDGPU_HOST_DEVICE long double
1525 round_error() noexcept;
1526
1531 static constexpr STDGPU_HOST_DEVICE long double
1532 infinity() noexcept;
1533
1537 static constexpr bool is_specialized = true;
1538
1542 static constexpr bool is_signed = true;
1543
1547 static constexpr bool is_integer = false;
1548
1552 static constexpr bool is_exact = false;
1553
1557 static constexpr int digits = LDBL_MANT_DIG;
1558
1562 static constexpr int radix = FLT_RADIX;
1563};
1564
1565} // namespace stdgpu
1566
1567#include <stdgpu/impl/limits_detail.h>
1568
1569#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