diff options
| author | Tyge Løvset <[email protected]> | 2020-08-11 23:08:45 +0200 |
|---|---|---|
| committer | Tyge Løvset <[email protected]> | 2020-08-11 23:08:45 +0200 |
| commit | 631ed32c6ba9a7966d52b1de1c3e59283e1f8312 (patch) | |
| tree | bc4a1a726d7feed5e1d89487f5f74d27ed29a4ae | |
| parent | 28574b3bd60c5ef07f3c245095b56c8278a98459 (diff) | |
| download | STC-modified-631ed32c6ba9a7966d52b1de1c3e59283e1f8312.tar.gz STC-modified-631ed32c6ba9a7966d52b1de1c3e59283e1f8312.zip | |
Added visual studio _umul128() declaration in crandom.h
| -rw-r--r-- | stc/crandom.h | 17 |
1 files changed, 9 insertions, 8 deletions
diff --git a/stc/crandom.h b/stc/crandom.h index 1e3b2107..a3d0b77c 100644 --- a/stc/crandom.h +++ b/stc/crandom.h @@ -94,15 +94,16 @@ STC_INLINE double crandom_f64(crandom_eng64_t* rng) { STC_INLINE crandom_distrib_i64_t crandom_uniform_i64_init(int64_t low, int64_t high) {
crandom_distrib_i64_t dist = {low, high - low + 1}; return dist;
}
-STC_INLINE int64_t crandom_uniform_i64(crandom_eng64_t* rng, crandom_distrib_i64_t dist) {
-#if defined(__SIZEOF_INT128__)
- return dist.offset + (int64_t) (((__uint128_t) crandom_i64(rng) * dist.range) >> 64);
-#elif defined(_MSC_VER) && defined(_WIN64)
- int64_t hi; _umul128(crandom_i64(rng), dist.range, &hi); return dist.offset + hi;
-#else
- return dist.offset + crandom_i64(rng) % dist.range; // slower
-#endif
+STC_INLINE int64_t crandom_uniform_i64(crandom_eng64_t* rng, crandom_distrib_i64_t dist) {
+ #if defined(__SIZEOF_INT128__)
+ return dist.offset + (int64_t) (((__uint128_t) crandom_i64(rng) * dist.range) >> 64);
+ #elif defined(_MSC_VER) && defined(_WIN64)
+ uint64_t _umul128(uint64_t x, uint64_t y, uint64_t *hi);
+ uint64_t hi; _umul128(crandom_i64(rng), dist.range, &hi); return dist.offset + hi;
+ #else
+ return dist.offset + crandom_i64(rng) % dist.range; // slower
+ #endif
}
STC_INLINE crandom_distrib_f64_t crandom_uniform_f64_init(double low, double high) {
|
