From 7cda97c127076acbbaa7b472cf5a89357c1d9a84 Mon Sep 17 00:00:00 2001 From: Tyge Løvset Date: Fri, 17 Jul 2020 10:55:16 +0200 Subject: Added macro overload allowing zero args (not utilized). Renamed ..._floatRandom() to ..._randomFloat() --- examples/rngtest.c | 76 +++++++++++++++++++++++++++--------------------------- stc/cdefs.h | 18 +++++++------ stc/chash.h | 12 ++++----- stc/crandom.h | 6 ++--- 4 files changed, 57 insertions(+), 55 deletions(-) diff --git a/examples/rngtest.c b/examples/rngtest.c index d88d1fab..ed3bed08 100644 --- a/examples/rngtest.c +++ b/examples/rngtest.c @@ -1,39 +1,39 @@ -#include -#include -#include "../stc/crandom.h" -#ifdef __cplusplus -#include -#endif - - -#define NN 1000000000 - -int main(void) -{ - clock_t difference, before; - uint64_t v; - printf("start\n"); - - pcg32_random_t pcg = pcg32_seed(time(NULL), 1); - before = clock(); \ - v = 0; - for (size_t i=0; i +#include +#include "../stc/crandom.h" +#ifdef __cplusplus +#include +#endif + + +#define NN 1000000000 + +int main(void) +{ + clock_t difference, before; + uint64_t v; + printf("start\n"); + + pcg32_random_t pcg = pcg32_seed(time(NULL), 1); + before = clock(); \ + v = 0; + for (size_t i=0; i -#include +#include declare_CSet(sx, int); // Set of int declare_CMap(mx, int, char); // Map of int -> char @@ -101,16 +101,16 @@ enum {chash_HASH = 0x7f, chash_USED = 0x80}; #define declare_CSet_5(tag, Key, keyDestroy, keyHash, keyEquals) \ declare_CSet_8(tag, Key, keyDestroy, keyHash, keyEquals, \ - Key, c_defaultGetRaw, c_defaultInitRaw) + Key, c_defaultGetRaw, c_defaultInitRaw) #define declare_CSet_8(tag, Key, keyDestroy, keyHashRaw, keyEqualsRaw, \ RawKey, keyGetRaw, keyInitRaw) \ - declare_CHASH(tag, CSet, cset, Key, void, void, keyHashRaw, keyEqualsRaw, \ + declare_CHASH(tag, CSet, cset, Key, void, void, keyHashRaw, keyEqualsRaw, \ keyDestroy, RawKey, keyGetRaw, keyInitRaw) /* CSet_str, CMap_str: */ -#define declare_CSet_str(tag) \ - declare_CMAPSTR(tag, CSet, cset, void, void) +#define declare_CSet_str() \ + declare_CMAPSTR(str, CSet, cset, void, void) #define declare_CMap_str(...) \ c_MACRO_OVERLOAD(declare_CMap_str, __VA_ARGS__) @@ -123,7 +123,7 @@ enum {chash_HASH = 0x7f, chash_USED = 0x80}; #define declare_CMAPSTR(tag, CType, ctype, Value, valueDestroy) \ declare_CHASH(tag, CType, ctype, CStr, Value, valueDestroy, cstr_hashRaw, \ - cstr_equalsRaw, cstr_destroy, const char*, cstr_getRaw, cstr_make) + cstr_equalsRaw, cstr_destroy, const char*, cstr_getRaw, cstr_make) #define OPT_1_cset(x) #define OPT_2_cset(x, y) x diff --git a/stc/crandom.h b/stc/crandom.h index 06f1c26a..ff2e03d3 100644 --- a/stc/crandom.h +++ b/stc/crandom.h @@ -17,13 +17,13 @@ STC_INLINE uint32_t pcg32_random(pcg32_random_t* rng) } /* float random int number in range [0, 1). NB: 23 bit resolution. */ -STC_INLINE float pcg32_floatRandom(pcg32_random_t* rng) { +STC_INLINE float pcg32_randomFloat(pcg32_random_t* rng) { union {uint32_t i; float f;} u = {0x3F800000u | (pcg32_random(rng) >> 9)}; return u.f - 1.0f; } /* Uniform random number in range [0, bound) */ -STC_INLINE uint32_t pcg32_boundedRandom(pcg32_random_t* rng, uint32_t bound) { +STC_INLINE uint32_t pcg32_randomBounded(pcg32_random_t* rng, uint32_t bound) { return (uint32_t) (((uint64_t) pcg32_random(rng) * bound) >> 32); } @@ -59,7 +59,7 @@ STC_API uint64_t sfc64_random(sfc64_random_t* rng) { } /* double random int number in range [0, 1). */ -STC_INLINE double sfc64_fRandom(sfc64_random_t* rng) { +STC_INLINE double sfc64_randomFloat(sfc64_random_t* rng) { union {uint64_t i; double f;} u = {0x3FF0000000000000ull | (sfc64_random(rng) >> 12)}; return u.f - 1.0; } -- cgit v1.2.3