-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlimits.cuh
53 lines (47 loc) · 1.37 KB
/
limits.cuh
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
// With reference to the numeric_limits header
// Macro with reference in following
// https://en.cppreference.com/w/cpp/types/climits
#include <cstdint>
#include <cfloat>
namespace cuda_custom {
template <typename T>
struct limits
{
__host__ __device__ static constexpr T
min() noexcept {return T();}
__host__ __device__ static constexpr T
max() noexcept {return T();}
__host__ __device__ static constexpr T
lowest() noexcept {return T();}
};
template <>
struct limits<int>
{
__host__ __device__ static constexpr int
min() noexcept {return INT_MIN;}
__host__ __device__ static constexpr int
max() noexcept {return INT_MAX;}
__host__ __device__ static constexpr int
lowest() noexcept {return INT_MIN;}
};
template <>
struct limits<unsigned int>
{
__host__ __device__ static constexpr unsigned int
min() noexcept {return 0;}
__host__ __device__ static constexpr unsigned int
max() noexcept {return UINT_MAX;}
__host__ __device__ static constexpr unsigned int
lowest() noexcept {return 0;}
};
template <>
struct limits<float>
{
__host__ __device__ static constexpr float
min() noexcept {return FLT_MIN;}
__host__ __device__ static constexpr float
max() noexcept {return FLT_MAX;}
__host__ __device__ static constexpr float
lowest() noexcept {return -FLT_MAX;}
};
}