Fixed some namespace pollution issues

Fortune for rngxx's current commit: Blessing − 吉
capi
Avril 3 years ago
parent 0ecf0be7a7
commit 7733ada38b
Signed by: flanchan
GPG Key ID: 284488987C31F630

@ -18,6 +18,7 @@ INCLUDE=include
INCLUDE_INTERNAL=src/internal
COMMON_FLAGS= -W -Wall -Wextra -Wstrict-aliasing -fno-strict-aliasing "-D_VERSION=$(VERSION)" $(addprefix -I,$(INCLUDE)) $(addprefix -I,$(INCLUDE_INTERNAL))
COMMON_FLAGS+=-D_RNGXX_IMPL
TARGET_CPU?=native
OPT_FLAGS?= $(addprefix -march=,$(TARGET_CPU)) -fgraphite -fopenmp -floop-parallelize-all -ftree-parallelize-loops=4 \

@ -6,7 +6,13 @@
#include <climits>
#ifndef _RNGXX_IMPL
#define _RNGXX_COMMON_MINIMAL
#endif
#include "rngxx/common.h"
#ifndef _RNGXX_IMPL
#undef _RNGXX_COMMON_MINIMAL
#endif
#define CTOR_COPY(name) name(const name& copy)
#define CTOR_MOVE(name) name(name&& move)
@ -178,13 +184,9 @@ protected:
// It is recommended to override `next_bytes()` too however.
virtual f64 _sample() = 0;
inline f64 sample()
{
auto s = _sample();
if (UNLIKELY(s < 0 || s > 1)) throw InvalidRandomSample{ s };
return s;
}
private:
f64 sample();
private:
template<usize N>
inline void _next_bytes(u8* a)
{

@ -7,6 +7,8 @@ extern "C" {
#include <stdint.h>
#include <stddef.h>
#ifndef _RNGXX_COMMON_MINIMAL
#include <stdlib.h>
#define IFUNC_NAME(name, ver) _impl__ ## name ## __ ## ver
@ -32,6 +34,8 @@ extern "C" {
#define _rng_internal v_internal
#endif
#define DEF(s, n) typedef s ## int ## n ## _t s ## n
#define DEFINT(n) typedef uint ## n ## _t u ## n; \
typedef int ## n ## _t i ## n
@ -41,6 +45,7 @@ DEFINT(16);
DEFINT(32);
DEFINT(64);
#ifdef __cplusplus
#else
#include <stdbool.h>
@ -65,7 +70,9 @@ typedef uintptr_t ptr_t;
#undef DEF
#ifdef __cplusplus
#ifndef _RNGXX_COMMON_MINIMAL
#define restrict __restrict__
#endif
}
#endif

@ -30,6 +30,15 @@ N_INTS
#undef NEXTT
#undef NEXT
f64 Random::sample()
{
auto s = _sample();
if (UNLIKELY(s < 0 || s > 1)) throw InvalidRandomSample{ s };
return s;
}
// Inefficient sample() based impl of `bytes()`
void Random::next_bytes(u8* ptr, usize n)
{

Loading…
Cancel
Save