33#ifndef __r123_uniform_dot_hpp
34#define __r123_uniform_dot_hpp
88#include <Random123/features/compilerfeatures.h>
90#if R123_USE_CXX11_TYPE_TRAITS
93#if __cplusplus >= 201103L
103#if R123_USE_CXX11_TYPE_TRAITS
104using std::make_signed;
105using std::make_unsigned;
111struct make_signed { };
113struct make_unsigned { };
114#define R123_MK_SIGNED_UNSIGNED(ST, UT) \
116 struct make_signed<ST> { \
120 struct make_signed<UT> { \
124 struct make_unsigned<ST> { \
128 struct make_unsigned<UT> { \
132R123_MK_SIGNED_UNSIGNED(int8_t,
uint8_t);
133R123_MK_SIGNED_UNSIGNED(int16_t, uint16_t);
134R123_MK_SIGNED_UNSIGNED(int32_t,
uint32_t);
135R123_MK_SIGNED_UNSIGNED(int64_t,
uint64_t);
136#if R123_USE_GNU_UINT128
137R123_MK_SIGNED_UNSIGNED(__int128_t, __uint128_t);
139#undef R123_MK_SIGNED_UNSIGNED
142#if defined(__CUDACC__) || defined(_LIBCPP_HAS_NO_CONSTEXPR)
156 typedef typename make_unsigned<T>::type uT;
157 return (~uT(0)) >> std::numeric_limits<T>::is_signed;
162 return std::numeric_limits<T>::max();
188template<
typename Ftype,
typename Itype>
190 typedef typename make_unsigned<Itype>::type Utype;
191 R123_CONSTEXPR Ftype factor = Ftype(1.) / (Ftype(maxTvalue<Utype>()) + Ftype(1.));
192 R123_CONSTEXPR Ftype halffactor = Ftype(0.5) * factor;
193#if R123_UNIFORM_FLOAT_STORE
194 volatile Ftype x = Utype(in) * factor;
195 return x + halffactor;
197 return Utype(in) * factor + halffactor;
220template<
typename Ftype,
typename Itype>
222 typedef typename make_signed<Itype>::type Stype;
223 R123_CONSTEXPR Ftype factor = Ftype(1.) / (Ftype(maxTvalue<Stype>()) + Ftype(1.));
224 R123_CONSTEXPR Ftype halffactor = Ftype(0.5) * factor;
225#if R123_UNIFORM_FLOAT_STORE
226 volatile Ftype x = Stype(in) * factor;
227 return x + halffactor;
229 return Stype(in) * factor + halffactor;
254template<
typename Ftype,
typename Itype>
256 typedef typename make_unsigned<Itype>::type Utype;
257 R123_CONSTEXPR
int excess = std::numeric_limits<Utype>::digits - std::numeric_limits<Ftype>::digits;
259 R123_CONSTEXPR
int ex_nowarn = (excess >= 0) ? excess : 0;
260 R123_CONSTEXPR Ftype factor = Ftype(1.) / (Ftype(1.) + Ftype((maxTvalue<Utype>() >> ex_nowarn)));
261 return (1 | (Utype(in) >> ex_nowarn)) * factor;
263 return u01<Ftype>(in);
266#if R123_USE_CXX11_STD_ARRAY
274template<
typename Ftype,
typename CollType>
275static inline std::array<Ftype, CollType::static_size> u01all(CollType in) {
276 std::array<Ftype, CollType::static_size> ret;
277 auto p = ret.begin();
279 *p++ = u01<Ftype>(e);
290template<
typename Ftype,
typename CollType>
291static inline std::array<Ftype, CollType::static_size> uneg11all(CollType in) {
292 std::array<Ftype, CollType::static_size> ret;
293 auto p = ret.begin();
295 *p++ = uneg11<Ftype>(e);
306template<
typename Ftype,
typename CollType>
307static inline std::array<Ftype, CollType::static_size> u01fixedptall(CollType in) {
308 std::array<Ftype, CollType::static_size> ret;
309 auto p = ret.begin();
311 *p++ = u01fixedpt<Ftype>(e);
#define R123_STATIC_INLINE
R123_CUDA_DEVICE R123_STATIC_INLINE Ftype uneg11(Itype in)
Return a signed value in [-1,1].
R123_CUDA_DEVICE R123_STATIC_INLINE Ftype u01(Itype in)
Return a uniform real value in (0, 1].