4 #ifdef HAVE_LIBQUADMATH
5 #include <boost/multiprecision/float128.hpp>
8 #include "util/cuda_util.hpp"
22 __host__ __device__
int sgn(T val)
24 return (T(0) < val) - (val < T(0));
38 __host__ __device__
static inline
39 size_t factorial(
size_t f)
43 for (
size_t s = 2 ; s <= f ; s++)
64 __host__ __device__
static inline
65 size_t C(
size_t n,
size_t k)
67 return factorial(n)/(factorial(k)*factorial(n-k));
80 __host__ __device__
static inline
81 size_t round_big_2(
size_t n)
108 __host__ __device__
inline constexpr
109 size_t pow(
const T base,
unsigned const exponent)
112 return (exponent == 0) ? 1 : (base * pow(base, exponent-1));
127 __host__ __device__
double intpowlog(
const T base,
unsigned const exponent)
129 T out = 1, curpwr = base;
130 for(
unsigned _e = exponent ; _e > 0; _e = _e >> 1)
150 __host__ __device__
static inline
151 long int positive_modulo(
long int i,
long int n)
153 return (i % n + n) % n;
172 __host__ __device__
static inline
173 T periodic(
const T & pos,
const T & p2,
const T & p1)
177 pos_tmp = pos - (p2 - p1) * (
long int)( (pos -p1) / (p2 - p1));
178 pos_tmp += (pos < p1)?(p2 - p1):0;
201 __device__ __host__
static inline
202 T periodic_l(
const T & pos,
const T & p2,
const T & p1)
208 pos_tmp = p1 + (pos - p2);
212 pos_tmp = p2 - (p1 - pos);
227 __host__ __device__
inline long int size_t_floor(
double x)
229 size_t i = (
long int)x;
230 return i - ( i > x );
237 __host__ __device__
inline long int size_t_floor(
float x)
239 size_t i = (
long int)x;
240 return i - ( i > x );
247 __device__ __host__
inline int uint_floor(
double x)
249 unsigned int i = (
int)x;
250 return i - ( i > x );
257 __device__ __host__
inline int uint_floor(
float x)
259 unsigned int i = (
int)x;
260 return i - ( i > x );
263 const int tab64[64] = {
264 63, 0, 58, 1, 59, 47, 53, 2,
265 60, 39, 48, 27, 54, 33, 42, 3,
266 61, 51, 37, 40, 49, 18, 28, 20,
267 55, 30, 34, 11, 43, 14, 22, 4,
268 62, 57, 46, 52, 38, 26, 32, 41,
269 50, 36, 17, 19, 29, 10, 13, 21,
270 56, 45, 25, 31, 35, 16, 9, 12,
271 44, 24, 15, 8, 23, 7, 6, 5};
278 __host__ __device__
inline int log2_64 (uint64_t value)
284 value |= value >> 16;
285 value |= value >> 32;
286 return tab64[((uint64_t)((value - (value >> 1))*0x07EDD5E59A4E28C2)) >> 58];
290 #ifdef HAVE_LIBQUADMATH
296 __host__ __device__
inline long int size_t_floor(boost::multiprecision::float128 x)
298 size_t i = (
long int)x;
299 return i - ( i > x );
int sgn(T val)
Gets the sign of a variable.
KeyT const ValueT ValueT OffsetIteratorT OffsetIteratorT int
[in] The number of segments that comprise the sorting data
convert a type into constant type