-
Notifications
You must be signed in to change notification settings - Fork 4
/
p3a_constants.hpp
148 lines (126 loc) · 3.77 KB
/
p3a_constants.hpp
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
#pragma once
#include <cfloat>
#include <limits>
#include "p3a_macros.hpp"
#ifdef __CUDA_ARCH__
#include <math_constants.h>
#endif
namespace p3a {
namespace constants {
template <class T>
struct maximum {
P3A_HOST_DEVICE P3A_ALWAYS_INLINE inline static constexpr
T value() { return T::maximum(); }
};
template <>
struct maximum<double> {
P3A_HOST_DEVICE P3A_ALWAYS_INLINE inline static constexpr
double value() { return DBL_MAX; }
};
template <class T>
struct minimum {
P3A_HOST_DEVICE P3A_ALWAYS_INLINE inline static constexpr
T value() { return T::minimum(); }
};
template <>
struct minimum<double> {
P3A_HOST_DEVICE P3A_ALWAYS_INLINE inline static constexpr
double value() { return -DBL_MAX; }
};
template <class T>
struct epsilon {
P3A_HOST_DEVICE P3A_ALWAYS_INLINE inline static constexpr
T value() { return T::epsilon(); }
};
template <>
struct epsilon<float> {
P3A_HOST_DEVICE P3A_ALWAYS_INLINE inline static constexpr
float value() { return FLT_EPSILON; }
};
template <>
struct epsilon<double> {
P3A_HOST_DEVICE P3A_ALWAYS_INLINE inline static constexpr
double value() { return DBL_EPSILON; }
};
template <class T>
struct quiet_NaN;
template <>
struct quiet_NaN<float> {
P3A_HOST_DEVICE P3A_ALWAYS_INLINE inline static constexpr
float value() {
#ifdef __CUDA_ARCH__
return CUDART_NAN_F;
#else
return std::numeric_limits<float>::quiet_NaN();
#endif
}
};
template <>
struct quiet_NaN<double> {
P3A_HOST_DEVICE P3A_ALWAYS_INLINE inline static constexpr
float value() {
#ifdef __CUDA_ARCH__
return CUDART_NAN;
#else
return std::numeric_limits<double>::quiet_NaN();
#endif
}
};
template <class T>
struct zero {
P3A_HOST_DEVICE P3A_ALWAYS_INLINE inline static constexpr
T value() { return T::zero(); }
};
template <>
struct zero<int> {
P3A_HOST_DEVICE P3A_ALWAYS_INLINE inline static constexpr
int value() { return 0; }
};
template <>
struct zero<float> {
P3A_HOST_DEVICE P3A_ALWAYS_INLINE inline static constexpr
float value() { return 0.0f; }
};
template <>
struct zero<double> {
P3A_HOST_DEVICE P3A_ALWAYS_INLINE inline static constexpr
double value() { return 0.0; }
};
}
template <class T>
[[nodiscard]] P3A_HOST_DEVICE P3A_ALWAYS_INLINE inline constexpr
T pi_value() { return T(3.14159265358979323846264338327950288419716939937510l); }
template <class T>
[[nodiscard]] P3A_HOST_DEVICE P3A_ALWAYS_INLINE inline constexpr
T maximum_value() { return constants::maximum<T>::value(); }
template <class T>
[[nodiscard]] P3A_HOST_DEVICE P3A_ALWAYS_INLINE inline constexpr
T minimum_value() { return constants::minimum<T>::value(); }
template <class T>
[[nodiscard]] P3A_HOST_DEVICE P3A_ALWAYS_INLINE inline constexpr
T epsilon_value() { return constants::epsilon<T>::value(); }
template <class T>
[[nodiscard]] P3A_HOST_DEVICE P3A_ALWAYS_INLINE inline constexpr
T quiet_NaN_value() { return constants::quiet_NaN<T>::value(); }
template <class T>
[[nodiscard]] P3A_HOST_DEVICE P3A_ALWAYS_INLINE inline constexpr
T zero_value() { return constants::zero<T>::value(); }
template <class T>
[[nodiscard]] P3A_HOST_DEVICE P3A_ALWAYS_INLINE inline constexpr
T one_value() { return T(1); }
template <class T>
[[nodiscard]] P3A_HOST_DEVICE P3A_ALWAYS_INLINE inline constexpr
T speed_of_light_value() { return T(299792458); }
template <class T>
[[nodiscard]] P3A_HOST_DEVICE P3A_ALWAYS_INLINE inline constexpr
T electron_volt_value() { return T(1.602176634e-19); }
template <class T>
[[nodiscard]] P3A_HOST_DEVICE P3A_ALWAYS_INLINE inline constexpr
T boltzmann_value() { return T(1.380649e-23); }
template <class T>
[[nodiscard]] P3A_HOST_DEVICE P3A_ALWAYS_INLINE inline constexpr
T inch_value() { return T(25.4e-3); }
template <class T>
[[nodiscard]] P3A_HOST_DEVICE P3A_ALWAYS_INLINE inline constexpr
T square_root_of_two_value() { return T(1.41421356237309504880); }
}