1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
|
//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
// SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES.
//
//===----------------------------------------------------------------------===//
#ifndef _LIBCUDACXX___LIMITS_NUMERIC_LIMITS_H
#define _LIBCUDACXX___LIMITS_NUMERIC_LIMITS_H
#include <cuda/std/detail/__config>
#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC)
# pragma GCC system_header
#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG)
# pragma clang system_header
#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC)
# pragma system_header
#endif // no system header
#include <cuda/std/__bit/bit_cast.h>
#include <cuda/std/__type_traits/is_extended_floating_point.h>
#include <cuda/std/__type_traits/is_floating_point.h>
#include <cuda/std/__type_traits/is_integral.h>
#include <cuda/std/__type_traits/is_same.h>
#include <cuda/std/cfloat>
#include <cuda/std/climits>
#include <cuda/std/__cccl/prologue.h>
_LIBCUDACXX_BEGIN_NAMESPACE_STD
enum float_round_style
{
round_indeterminate = -1,
round_toward_zero = 0,
round_to_nearest = 1,
round_toward_infinity = 2,
round_toward_neg_infinity = 3
};
enum _LIBCUDACXX_DEPRECATED_IN_CXX23 float_denorm_style
{
denorm_indeterminate = -1,
denorm_absent = 0,
denorm_present = 1
};
enum class __numeric_limits_type
{
__integral,
__bool,
__floating_point,
__other,
};
template <class _Tp>
_CCCL_API constexpr __numeric_limits_type __make_numeric_limits_type()
{
if constexpr (_CCCL_TRAIT(is_same, _Tp, bool))
{
return __numeric_limits_type::__bool;
}
else if constexpr (_CCCL_TRAIT(is_integral, _Tp))
{
return __numeric_limits_type::__integral;
}
else if constexpr (_CCCL_TRAIT(is_floating_point, _Tp) || _CCCL_TRAIT(__is_extended_floating_point, _Tp))
{
return __numeric_limits_type::__floating_point;
}
else
{
return __numeric_limits_type::__other;
}
}
template <class _Tp, __numeric_limits_type = __make_numeric_limits_type<_Tp>()>
class __numeric_limits_impl
{
public:
using type = _Tp;
static constexpr bool is_specialized = false;
_CCCL_API static constexpr type min() noexcept
{
return type();
}
_CCCL_API static constexpr type max() noexcept
{
return type();
}
_CCCL_API static constexpr type lowest() noexcept
{
return type();
}
static constexpr int digits = 0;
static constexpr int digits10 = 0;
static constexpr int max_digits10 = 0;
static constexpr bool is_signed = false;
static constexpr bool is_integer = false;
static constexpr bool is_exact = false;
static constexpr int radix = 0;
_CCCL_API static constexpr type epsilon() noexcept
{
return type();
}
_CCCL_API static constexpr type round_error() noexcept
{
return type();
}
static constexpr int min_exponent = 0;
static constexpr int min_exponent10 = 0;
static constexpr int max_exponent = 0;
static constexpr int max_exponent10 = 0;
static constexpr bool has_infinity = false;
static constexpr bool has_quiet_NaN = false;
static constexpr bool has_signaling_NaN = false;
_LIBCUDACXX_DEPRECATED_IN_CXX23 static constexpr float_denorm_style has_denorm = denorm_absent;
_LIBCUDACXX_DEPRECATED_IN_CXX23 static constexpr bool has_denorm_loss = false;
_CCCL_API static constexpr type infinity() noexcept
{
return type();
}
_CCCL_API static constexpr type quiet_NaN() noexcept
{
return type();
}
_CCCL_API static constexpr type signaling_NaN() noexcept
{
return type();
}
_CCCL_API static constexpr type denorm_min() noexcept
{
return type();
}
static constexpr bool is_iec559 = false;
static constexpr bool is_bounded = false;
static constexpr bool is_modulo = false;
static constexpr bool traps = false;
static constexpr bool tinyness_before = false;
static constexpr float_round_style round_style = round_toward_zero;
};
// MSVC warns about overflowing left shift
_CCCL_DIAG_PUSH
_CCCL_DIAG_SUPPRESS_MSVC(4309)
template <class _Tp, int __digits, bool _IsSigned>
struct __int_min
{
static constexpr _Tp value = static_cast<_Tp>(_Tp(1) << __digits);
};
_CCCL_DIAG_POP
template <class _Tp, int __digits>
struct __int_min<_Tp, __digits, false>
{
static constexpr _Tp value = _Tp(0);
};
template <class _Tp>
class __numeric_limits_impl<_Tp, __numeric_limits_type::__integral>
{
public:
using type = _Tp;
static constexpr bool is_specialized = true;
static constexpr bool is_signed = type(-1) < type(0);
static constexpr int digits = static_cast<int>(sizeof(type) * CHAR_BIT - is_signed);
static constexpr int digits10 = digits * 3 / 10;
static constexpr int max_digits10 = 0;
_CCCL_API static constexpr type min() noexcept
{
return __int_min<type, digits, is_signed>::value;
}
_CCCL_API static constexpr type max() noexcept
{
return is_signed ? type(type(~0) ^ min()) : type(~0);
}
_CCCL_API static constexpr type lowest() noexcept
{
return min();
}
static constexpr bool is_integer = true;
static constexpr bool is_exact = true;
static constexpr int radix = 2;
_CCCL_API static constexpr type epsilon() noexcept
{
return type(0);
}
_CCCL_API static constexpr type round_error() noexcept
{
return type(0);
}
static constexpr int min_exponent = 0;
static constexpr int min_exponent10 = 0;
static constexpr int max_exponent = 0;
static constexpr int max_exponent10 = 0;
static constexpr bool has_infinity = false;
static constexpr bool has_quiet_NaN = false;
static constexpr bool has_signaling_NaN = false;
_LIBCUDACXX_DEPRECATED_IN_CXX23 static constexpr float_denorm_style has_denorm = denorm_absent;
_LIBCUDACXX_DEPRECATED_IN_CXX23 static constexpr bool has_denorm_loss = false;
_CCCL_API static constexpr type infinity() noexcept
{
return type(0);
}
_CCCL_API static constexpr type quiet_NaN() noexcept
{
return type(0);
}
_CCCL_API static constexpr type signaling_NaN() noexcept
{
return type(0);
}
_CCCL_API static constexpr type denorm_min() noexcept
{
return type(0);
}
static constexpr bool is_iec559 = false;
static constexpr bool is_bounded = true;
static constexpr bool is_modulo = !is_signed;
#if (_CCCL_ARCH(X86_64) && _CCCL_OS(LINUX)) || defined(__pnacl__) || defined(__wasm__)
static constexpr bool traps = true;
#else
static constexpr bool traps = false;
#endif
static constexpr bool tinyness_before = false;
static constexpr float_round_style round_style = round_toward_zero;
};
template <>
class __numeric_limits_impl<bool, __numeric_limits_type::__bool>
{
public:
using type = bool;
static constexpr bool is_specialized = true;
static constexpr bool is_signed = false;
static constexpr int digits = 1;
static constexpr int digits10 = 0;
static constexpr int max_digits10 = 0;
_CCCL_API static constexpr type min() noexcept
{
return false;
}
_CCCL_API static constexpr type max() noexcept
{
return true;
}
_CCCL_API static constexpr type lowest() noexcept
{
return min();
}
static constexpr bool is_integer = true;
static constexpr bool is_exact = true;
static constexpr int radix = 2;
_CCCL_API static constexpr type epsilon() noexcept
{
return type(0);
}
_CCCL_API static constexpr type round_error() noexcept
{
return type(0);
}
static constexpr int min_exponent = 0;
static constexpr int min_exponent10 = 0;
static constexpr int max_exponent = 0;
static constexpr int max_exponent10 = 0;
static constexpr bool has_infinity = false;
static constexpr bool has_quiet_NaN = false;
static constexpr bool has_signaling_NaN = false;
_LIBCUDACXX_DEPRECATED_IN_CXX23 static constexpr float_denorm_style has_denorm = denorm_absent;
_LIBCUDACXX_DEPRECATED_IN_CXX23 static constexpr bool has_denorm_loss = false;
_CCCL_API static constexpr type infinity() noexcept
{
return type(0);
}
_CCCL_API static constexpr type quiet_NaN() noexcept
{
return type(0);
}
_CCCL_API static constexpr type signaling_NaN() noexcept
{
return type(0);
}
_CCCL_API static constexpr type denorm_min() noexcept
{
return type(0);
}
static constexpr bool is_iec559 = false;
static constexpr bool is_bounded = true;
static constexpr bool is_modulo = false;
static constexpr bool traps = false;
static constexpr bool tinyness_before = false;
static constexpr float_round_style round_style = round_toward_zero;
};
template <>
class __numeric_limits_impl<float, __numeric_limits_type::__floating_point>
{
public:
using type = float;
static constexpr bool is_specialized = true;
static constexpr bool is_signed = true;
static constexpr int digits = FLT_MANT_DIG;
static constexpr int digits10 = FLT_DIG;
static constexpr int max_digits10 = 2 + (digits * 30103l) / 100000l;
_CCCL_API static constexpr type min() noexcept
{
return FLT_MIN;
}
_CCCL_API static constexpr type max() noexcept
{
return FLT_MAX;
}
_CCCL_API static constexpr type lowest() noexcept
{
return -max();
}
static constexpr bool is_integer = false;
static constexpr bool is_exact = false;
static constexpr int radix = FLT_RADIX;
_CCCL_API static constexpr type epsilon() noexcept
{
return FLT_EPSILON;
}
_CCCL_API static constexpr type round_error() noexcept
{
return 0.5F;
}
static constexpr int min_exponent = FLT_MIN_EXP;
static constexpr int min_exponent10 = FLT_MIN_10_EXP;
static constexpr int max_exponent = FLT_MAX_EXP;
static constexpr int max_exponent10 = FLT_MAX_10_EXP;
static constexpr bool has_infinity = true;
static constexpr bool has_quiet_NaN = true;
static constexpr bool has_signaling_NaN = true;
_LIBCUDACXX_DEPRECATED_IN_CXX23 static constexpr float_denorm_style has_denorm = denorm_present;
_LIBCUDACXX_DEPRECATED_IN_CXX23 static constexpr bool has_denorm_loss = false;
#if defined(_CCCL_BUILTIN_HUGE_VALF)
_CCCL_API static constexpr type infinity() noexcept
{
return _CCCL_BUILTIN_HUGE_VALF();
}
#else // ^^^ _CCCL_BUILTIN_HUGE_VALF ^^^ // vvv !_CCCL_BUILTIN_HUGE_VALF vvv
_CCCL_API inline static _LIBCUDACXX_CONSTEXPR_BIT_CAST type infinity() noexcept
{
return _CUDA_VSTD::bit_cast<type>(0x7f800000);
}
#endif // !_CCCL_BUILTIN_HUGE_VALF
#if defined(_CCCL_BUILTIN_NANF)
_CCCL_API static constexpr type quiet_NaN() noexcept
{
return _CCCL_BUILTIN_NANF("");
}
#else // ^^^ _CCCL_BUILTIN_NANF ^^^ // vvv !_CCCL_BUILTIN_NANF vvv
_CCCL_API inline static _LIBCUDACXX_CONSTEXPR_BIT_CAST type quiet_NaN() noexcept
{
return _CUDA_VSTD::bit_cast<type>(0x7fc00000);
}
#endif // !_CCCL_BUILTIN_NANF
#if defined(_CCCL_BUILTIN_NANSF)
_CCCL_API static constexpr type signaling_NaN() noexcept
{
return _CCCL_BUILTIN_NANSF("");
}
#else // ^^^ _CCCL_BUILTIN_NANSF ^^^ // vvv !_CCCL_BUILTIN_NANSF vvv
_CCCL_API inline static _LIBCUDACXX_CONSTEXPR_BIT_CAST type signaling_NaN() noexcept
{
return _CUDA_VSTD::bit_cast<type>(0x7fa00000);
}
#endif // !_CCCL_BUILTIN_NANSF
_CCCL_API static constexpr type denorm_min() noexcept
{
#if defined(FLT_TRUE_MIN)
return FLT_TRUE_MIN;
#else // ^^^ FLT_TRUE_MIN ^^^ // vvv !FLT_TRUE_MIN vvv
return __FLT_DENORM_MIN__;
#endif // ^^^ !FLT_TRUE_MIN ^^^
}
static constexpr bool is_iec559 = true;
static constexpr bool is_bounded = true;
static constexpr bool is_modulo = false;
static constexpr bool traps = false;
static constexpr bool tinyness_before = false;
static constexpr float_round_style round_style = round_to_nearest;
};
template <>
class __numeric_limits_impl<double, __numeric_limits_type::__floating_point>
{
public:
using type = double;
static constexpr bool is_specialized = true;
static constexpr bool is_signed = true;
static constexpr int digits = DBL_MANT_DIG;
static constexpr int digits10 = DBL_DIG;
static constexpr int max_digits10 = 2 + (digits * 30103l) / 100000l;
_CCCL_API static constexpr type min() noexcept
{
return DBL_MIN;
}
_CCCL_API static constexpr type max() noexcept
{
return DBL_MAX;
}
_CCCL_API static constexpr type lowest() noexcept
{
return -max();
}
static constexpr bool is_integer = false;
static constexpr bool is_exact = false;
static constexpr int radix = FLT_RADIX;
_CCCL_API static constexpr type epsilon() noexcept
{
return DBL_EPSILON;
}
_CCCL_API static constexpr type round_error() noexcept
{
return 0.5;
}
static constexpr int min_exponent = DBL_MIN_EXP;
static constexpr int min_exponent10 = DBL_MIN_10_EXP;
static constexpr int max_exponent = DBL_MAX_EXP;
static constexpr int max_exponent10 = DBL_MAX_10_EXP;
static constexpr bool has_infinity = true;
static constexpr bool has_quiet_NaN = true;
static constexpr bool has_signaling_NaN = true;
_LIBCUDACXX_DEPRECATED_IN_CXX23 static constexpr float_denorm_style has_denorm = denorm_present;
_LIBCUDACXX_DEPRECATED_IN_CXX23 static constexpr bool has_denorm_loss = false;
#if defined(_CCCL_BUILTIN_HUGE_VAL)
_CCCL_API static constexpr type infinity() noexcept
{
return _CCCL_BUILTIN_HUGE_VAL();
}
#else // ^^^ _CCCL_BUILTIN_HUGE_VAL ^^^ // vvv !_CCCL_BUILTIN_HUGE_VAL vvv
_CCCL_API inline static _LIBCUDACXX_CONSTEXPR_BIT_CAST type infinity() noexcept
{
return _CUDA_VSTD::bit_cast<type>(0x7ff0000000000000);
}
#endif // !_CCCL_BUILTIN_HUGE_VAL
#if defined(_CCCL_BUILTIN_NAN)
_CCCL_API static constexpr type quiet_NaN() noexcept
{
return _CCCL_BUILTIN_NAN("");
}
#else // ^^^ _CCCL_BUILTIN_NAN ^^^ // vvv !_CCCL_BUILTIN_NAN vvv
_CCCL_API inline static _LIBCUDACXX_CONSTEXPR_BIT_CAST type quiet_NaN() noexcept
{
return _CUDA_VSTD::bit_cast<type>(0x7ff8000000000000);
}
#endif // !_CCCL_BUILTIN_NAN
#if defined(_CCCL_BUILTIN_NANS)
_CCCL_API static constexpr type signaling_NaN() noexcept
{
return _CCCL_BUILTIN_NANS("");
}
#else // ^^^ _CCCL_BUILTIN_NANS ^^^ // vvv !_CCCL_BUILTIN_NANS vvv
_CCCL_API inline static _LIBCUDACXX_CONSTEXPR_BIT_CAST type signaling_NaN() noexcept
{
return _CUDA_VSTD::bit_cast<type>(0x7ff4000000000000);
}
#endif // !_CCCL_BUILTIN_NANS
_CCCL_API static constexpr type denorm_min() noexcept
{
#if defined(DBL_TRUE_MIN)
return DBL_TRUE_MIN;
#else // ^^^ DBL_TRUE_MIN ^^^ // vvv !DBL_TRUE_MIN vvv
return __DBL_DENORM_MIN__;
#endif // ^^^ !DBL_TRUE_MIN ^^^
}
static constexpr bool is_iec559 = true;
static constexpr bool is_bounded = true;
static constexpr bool is_modulo = false;
static constexpr bool traps = false;
static constexpr bool tinyness_before = false;
static constexpr float_round_style round_style = round_to_nearest;
};
template <>
class __numeric_limits_impl<long double, __numeric_limits_type::__floating_point>
{
#if _CCCL_HAS_LONG_DOUBLE()
public:
using type = long double;
static constexpr bool is_specialized = true;
static constexpr bool is_signed = true;
static constexpr int digits = LDBL_MANT_DIG;
static constexpr int digits10 = LDBL_DIG;
static constexpr int max_digits10 = 2 + (digits * 30103l) / 100000l;
_CCCL_API static constexpr type min() noexcept
{
return LDBL_MIN;
}
_CCCL_API static constexpr type max() noexcept
{
return LDBL_MAX;
}
_CCCL_API static constexpr type lowest() noexcept
{
return -max();
}
static constexpr bool is_integer = false;
static constexpr bool is_exact = false;
static constexpr int radix = FLT_RADIX;
_CCCL_API static constexpr type epsilon() noexcept
{
return LDBL_EPSILON;
}
_CCCL_API static constexpr type round_error() noexcept
{
return 0.5L;
}
static constexpr int min_exponent = LDBL_MIN_EXP;
static constexpr int min_exponent10 = LDBL_MIN_10_EXP;
static constexpr int max_exponent = LDBL_MAX_EXP;
static constexpr int max_exponent10 = LDBL_MAX_10_EXP;
static constexpr bool has_infinity = true;
static constexpr bool has_quiet_NaN = true;
static constexpr bool has_signaling_NaN = true;
_LIBCUDACXX_DEPRECATED_IN_CXX23 static constexpr float_denorm_style has_denorm = denorm_present;
_LIBCUDACXX_DEPRECATED_IN_CXX23 static constexpr bool has_denorm_loss = false;
_CCCL_API static constexpr type infinity() noexcept
{
return _CCCL_BUILTIN_HUGE_VALL();
}
_CCCL_API static constexpr type quiet_NaN() noexcept
{
return _CCCL_BUILTIN_NANL("");
}
_CCCL_API static constexpr type signaling_NaN() noexcept
{
return _CCCL_BUILTIN_NANSL("");
}
_CCCL_API static constexpr type denorm_min() noexcept
{
# if defined(LDBL_TRUE_MIN)
return LDBL_TRUE_MIN;
# else // ^^^ LDBL_TRUE_MIN ^^^ // vvv !LDBL_TRUE_MIN vvv
return __LDBL_DENORM_MIN__;
# endif // ^^^ !LDBL_TRUE_MIN ^^^
}
static constexpr bool is_iec559 = true;
static constexpr bool is_bounded = true;
static constexpr bool is_modulo = false;
static constexpr bool traps = false;
static constexpr bool tinyness_before = false;
static constexpr float_round_style round_style = round_to_nearest;
#endif // _CCCL_HAS_LONG_DOUBLE()
};
template <class _Tp>
class numeric_limits : public __numeric_limits_impl<_Tp>
{};
template <class _Tp>
class numeric_limits<const _Tp> : public numeric_limits<_Tp>
{};
template <class _Tp>
class numeric_limits<volatile _Tp> : public numeric_limits<_Tp>
{};
template <class _Tp>
class numeric_limits<const volatile _Tp> : public numeric_limits<_Tp>
{};
_LIBCUDACXX_END_NAMESPACE_STD
#include <cuda/std/__cccl/epilogue.h>
#endif // _LIBCUDACXX___LIMITS_NUMERIC_LIMITS_H
|