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));
116 __host__ __device__
double intpowlog(
const T x,
unsigned const e)
118 if (e == 0)
return 1.0;
121 double h = intpowlog(x, e / 2);
126 double h = intpowlog(x, e / 2);
142 __host__ __device__
static inline
143 long int positive_modulo(
long int i,
long int n)
145 return (i % n + n) % n;
164 __host__ __device__
static inline
165 T periodic(
const T & pos,
const T & p2,
const T & p1)
169 pos_tmp = pos - (p2 - p1) * (
long int)( (pos -p1) / (p2 - p1));
170 pos_tmp += (pos < p1)?(p2 - p1):0;
193 __device__ __host__
static inline
194 T periodic_l(
const T & pos,
const T & p2,
const T & p1)
200 pos_tmp = p1 + (pos - p2);
204 pos_tmp = p2 - (p1 - pos);
219 __host__ __device__
inline long int size_t_floor(
double x)
221 size_t i = (
long int)x;
222 return i - ( i > x );
229 __host__ __device__
inline long int size_t_floor(
float x)
231 size_t i = (
long int)x;
232 return i - ( i > x );
239 __device__ __host__
inline int uint_floor(
double x)
241 unsigned int i = (
int)x;
242 return i - ( i > x );
249 __device__ __host__
inline int uint_floor(
float x)
251 unsigned int i = (
int)x;
252 return i - ( i > x );
255 const int tab64[64] = {
256 63, 0, 58, 1, 59, 47, 53, 2,
257 60, 39, 48, 27, 54, 33, 42, 3,
258 61, 51, 37, 40, 49, 18, 28, 20,
259 55, 30, 34, 11, 43, 14, 22, 4,
260 62, 57, 46, 52, 38, 26, 32, 41,
261 50, 36, 17, 19, 29, 10, 13, 21,
262 56, 45, 25, 31, 35, 16, 9, 12,
263 44, 24, 15, 8, 23, 7, 6, 5};
270 __host__ __device__
inline int log2_64 (uint64_t value)
276 value |= value >> 16;
277 value |= value >> 32;
278 return tab64[((uint64_t)((value - (value >> 1))*0x07EDD5E59A4E28C2)) >> 58];
282#ifdef HAVE_LIBQUADMATH
288 __host__ __device__
inline long int size_t_floor(boost::multiprecision::float128 x)
290 size_t i = (
long int)x;
291 return i - ( i > x );
KeyT const ValueT ValueT OffsetIteratorT OffsetIteratorT int
[in] The number of segments that comprise the sorting data
convert a type into constant type